BroadlinkIRTools icon indicating copy to clipboard operation
BroadlinkIRTools copied to clipboard

Summary - Broken and Attempted fixes

Open ninadpchaudhari opened this issue 2 years ago • 3 comments

As this tool was broken for new versions of HA, Tried to change the WebSocket API and the commands to work with the new versions :


  sendBroadlinkLearnCmd(targetKey) {
    store.state.socket.send(JSON.stringify({
      id: store.state.socketId++,
      type: "call_service",
      service: "learn_command",
      domain: "remote",
      service_data: {
        command: targetKey,
        command_type: "ir",
        device: "remote.corridor_pro_controller_remote",
        timeout: 10
      },
      target: {
        entity_id: "remote.corridor_pro_controller_remote"
      }
    }));
  },

Sadly, the new learn_command does not give back, it only stores the same into the file. I confirmed this via the source code in HA Core's Broadlink integration: Function async_learn_command, Line

Screenshot after the change! Command is sent successfully, but the response is just the notification! Screen Shot 2022-06-06 at 1 03 10 PM

Even earlier the HA's remote.py's learn command function did not return anything, but based on this project, I think, we are expecting an event type of state changed with the irCode let irCode = message.replace("Received packet is: ", ""); Perma Link to the function As of now, only thing that HA send back is

{
  "id": 70,
  "type": "event",
  "event": {
    "event_type": "state_changed",
    "data": {
      "entity_id": "persistent_notification.learn_command",
      "old_state": null,
      "new_state": {
        "entity_id": "persistent_notification.learn_command",
        "state": "notifying",
        "attributes": {
          "message": "Press the 'cool_auto_19' button.",
          "title": "Learn command",
          "friendly_name": "Learn command"
        },
        "last_changed": "2022-06-06T16:55:16.622753+00:00",
        "last_updated": "2022-06-06T16:55:16.622753+00:00",
        "context": {
          "id": "01G4WZ2BWEB9TXFT4CMG6R21M2",
          "parent_id": null,
          "user_id": null
        }
      }
    },
    "origin": "LOCAL",
    "time_fired": "2022-06-06T16:55:16.622753+00:00",
    "context": {
      "id": "01G4WZ2BWEB9TXFT4CMG6R21M2",
      "parent_id": null,
      "user_id": null
    }
  }
}

I wonder

  • How did HA return back the code earier
  • How can we get the same code now! Last option is always to parse the storage file located under .storage directory

ninadpchaudhari avatar Jun 06 '22 16:06 ninadpchaudhari

After spending the entire afternoon after this, I came to the same conclusions and ended up getting the commands from the .storage file.

I listened to all the events HA is firing when sending an IR command and the base64 is not present in any of them. So I guess there is no way with the current integration to get them as in the past.

It would be nice to create a fork of this project and at least push these findings.

I managed to get it running locally so it could be run as a docker container or an add-on.

victorigualada avatar Oct 25 '22 16:10 victorigualada

Building on your work @ninadpchaudhari and @victorigualada I've forked and updated the project. I've made a PR to merge those changes back but in the mean time you can use it at https://callumgare.github.io/BroadlinkIRTools/

callumgare avatar Mar 03 '23 13:03 callumgare

@victorigualada thing is, it was using a ≠ service, from the broadlink direct integration, that did return the command. Now, these new services do not return it. That's why we'll prolly always need to parse from the .storage file.

suvl avatar May 02 '24 10:05 suvl