Broadlink binding for RMx, A1, SPx and MP. Any interest?

Continuing the discussion from Broadlink binding for RMx, A1, SPx and MP. Any interest?:

Continuing the discussion from Broadlink binding for RMx, A1, SPx and MP. Any interest?:

Finally the Broadlink is arrived but i have some questions

How You guys learn the IR Codes which the broadlink is using got here an RM3 mini running with v44057 firmware.
with the new Broadlink App i could learn the Codes to Mobil but i have at moment no glue how to get that codes since the Windows Software above is not working with that frimware.

and no idea how to set uo docker properly :slight_smile:

Hi Jan,

i had the same Problem. I fixed it by resetting the device and closing the app directly after connecting the remote to the network.

David

I’ve had some time to pick up the dev work on the British General sockets, which look to extend the SP4b sockets.

I think I’ve got the payload sorted, but my java skills are weak and byte operations in java are weaker.

The Python here has the following code:

        checksum = sum(packet[0x08:], 0xC0AD) & 0xFFFF
        packet[0x06] = checksum & 0xFF
        packet[0x07] = checksum >> 8

I’ve seen in the existing binding code there’s some for loops for checksums, but I’m struggling to work out what the python is doing. It’s taking the byte array from the flag onwards and adding 0xc0ad but I don’t understand anything else.

My rudimentary, untested code for the encode function at the moment is as follows. I’m thinking I should move to using a ByteBuffer instead.

private void encodeMessage(int flag, String json) {
        int length = 12 + json.length();
        Byte[] packet = new Byte[14 + json.length()];
        packet[0x00] = (byte) (length & 0xFF);
        packet[0x01] = (byte) ((length >> 8) & 0xFF);
        packet[0x02] = (byte) (0xa5a5 & 0xFF);
        packet[0x03] = (byte) ((0xa5a5 >> 8) & 0xFF);
        packet[0x04] = 0x5a5a & 0xFF;
        packet[0x05] = ((0x5a5a >> 8) & 0xFF);
        packet[0x06] = 0x00;
        packet[0x07] = 0x00;
        packet[0x08] = (byte) flag;
        packet[0x09] = 0x0B;
        packet[0x0a] = (byte) (json.length() & 0xFF);
        packet[0x0b] = (byte) ((json.length() >> 8) & 0xFF);
        packet[0x0c] = (byte) ((json.length() >> 16) & 0xFF);
        packet[0x0d] = (byte) ((json.length() >> 24) & 0xFF);
        for (int i = 0; i < json.length(); i++) {            
            packet[i + 15] = (byte) json.charAt(i);
        }
}

Any help would be appreciated

Some progress. The json response is quite long so the slice function cuts the output a bit short. Looking at the python code it reads to the end of the array, but that’s not working for me. I think the best course of action is to refactor the slice code to read to the end or take a parameter to read to the end.

Output of the status response decoded below:

EDIT: I can now control the BG1 twin wall socket. I’ve had to modify some of the core code slightly so I don’t feel comfortable doing a merge request with the main repo, however I’ve uploaded it here: GitHub - RobPope/BroadlinkOH3: OpenHAB3 implementation of Broadlink Binding including support for BG1

Hello Fellow Broadlink’ers.
First of all - Thank you to everyone for this great and very long thread :slight_smile: .
So this is my first post in the community (be nice). I was able to setup OH3 without any issues, put in all my lighting, blinds, UPS, Printer status, gmail, Pushover and link it all with Alexa.
For the RM4 Pro, it was more complicated: was connected and then it went into a communication error (couldn’t authenticate). I then deleted it, and reinstalled it using the Android App, but stopped short of adding it to my Android environment Broadlink APP, all seems to be good now. The RM4 Pro has the latest firmware v52079.

I have read and re-read this thread so many time and am very confused as to what my next steps are. It talks about broadlink.map, creating a remote control, etc… Am really not sure anymore where to start. If anyone could point me to a “plan” of action, that would be awesome. I am not familiar with OH 2 so everything I do is via the GUI. If I need to start doing things the “old” way (am an old guy…I can say that, right?), I am game for it, but will probably will have lots of question.

maybe something like this:

  1. Find your IR code (how, etc…) and put it somewhere.
  2. test those using xyz.
  3. create your remote, as such…using this…
  4. Test in OH 3
  5. Assign this to Alexa using the following meta data.

I am trying to create a simple remote that will turn on/off my Kitchen Fan It has 4 speeds and that’s all for now.

Thanks you so much for everything I have read in this forum so far - it’s awesome. :pray::pray::pray::pray:

2 Likes

I followed the link below. I used the Method 1 that he listed for Configuration and the the python-broadlink method for learning the IR codes. I also set it up with the MQTT method as a backup but I do not currently use it because I would have had to create a directory structure to match the MQTT messages. For my specific setup that would have created 2 or so hours of folder creation and a single text file for every IR code I needed to use. Using this method to capture the IR codes is the easiest way IMO. I was able to quickly and efficiently learn and toss all my IR codes into a broadlink.map file by repeating the same three quick commands.

https://community.openhab.org/t/broadlink-bestcon-rm4c-mini-via-mqtt/98268

From that point I ended up creating my own personal widget for the remote based off of the weather widget tutorial and several posts in the page below to help with understanding oh-links and badges.

https://community.openhab.org/t/building-pages-in-the-oh3-ui-documentation-draft-2-3/104392/263

1 Like

to learn codes - the best way is to use this utility Broadlink Manager download | SourceForge.net
But what is the best way connect this codes in OH3 i don’t know. Year ago on OH2.5 i do this manual but that was complicated , you must wright many text files. I really interested how can we do this from OH3 interface, with his new abilities

Best way for OH3 is via the Broadlink binding. Install the binding Broadlink 3.1 which is a few posts above. The ActionCommand that I have called CABLE_SELECT(or CABLE_POWER depending on what photo you look at) is the command that correlates to what is in the broadlink.map file.

1 Like

Thx for the help, I instal broadlink bunding, it work, but can you pls do a more open tutorial. Something like how to add custom RF/IR code and shoot it from oh3, in a step by step way:

  • where you put map file
  • what you write in map file
  • how you create the property links like in your picture
  • how you shoot this property from “Model” (for example I do relay control from this menu can I add here “custom code” and shot it from here?)

Hello.Tell me please. I have broadlink rm4c mini.I can’t read the codes from the remote for the file broadlink.map.I tried the bridge broadlink but it is only suitable for RM1/2.Tell me please how to read codse. perhaps there are other ways.

Have a look here.
I also got a RM4C Mini in production controlling my TV and Mibox.
The guide should enable you to record your IR commands.
You can then use them in openHAB/MQTT as you need to.

The broadlink.map file goes into /etc/openhab/transform and you write in the .map file the commands like:

start=IRCODE

You can then use the “start” command to execute the IR code via openHAB via the broadlink command channel.
There should be enough information in this thread to configure openHAB by now.
Have a read through it and let us know if you need further information.

I tried this manual but I could not get the codes for broadlink.map.tell me please in detail how did you get the codes?

I used the method outlined in linked thread via Teach Remote Codes leveraging broadlink-mqtt, whereas also used python-broadlink. Both worked, just follow the instructions of said thread or their respective github repos.

I have a Broadlink RM 4 mini on Openhab 2.5. I got a few IR codes that I learned with the Python library and it worked a couple of times. However now nothing happens when setting something in PaperUI and in addition the following shows up in the logs:

2021-03-13 21:38:04.592 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4:cfbc4452[v]: Authentication failed: 
2021-03-13 21:38:04.595 [ERROR] [handler.BroadlinkRemoteModel4Handler] - Broadlink Exception: 
java.net.ProtocolException: Response from device is not valid. (0x22=0xFF,0x23=0xFF,0x24=0xFF)
        at org.openhab.binding.broadlink.internal.BroadlinkProtocol.decodePacket(BroadlinkProtocol.java:195) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.decodeDevicePacket(BroadlinkBaseThingHandler.java:180) ~[bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.authenticate(BroadlinkBaseThingHandler.java:140) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.transitionToOnline(BroadlinkBaseThingHandler.java:263) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler.updateItemStatus(BroadlinkBaseThingHandler.java:216) [bundleFile:?]
        at org.openhab.binding.broadlink.handler.BroadlinkBaseThingHandler$1.run(BroadlinkBaseThingHandler.java:104) [bundleFile:?]
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_152]
        at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [?:1.8.0_152]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [?:1.8.0_152]
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [?:1.8.0_152]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_152]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_152]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152]
2021-03-13 21:38:04.603 [ERROR] [handler.BroadlinkRemoteModel4Handler] - rm4:cfbc4452[v]: Attempting to authenticate prior to getting device status FAILED. Will mark as offline
2021-03-13 21:38:04.607 [WARN ] [handler.BroadlinkRemoteModel4Handler] - rm4:cfbc4452[v]: Online -> Offline due to: Couldn't authenticate

It does show as online in PaperUI.
Any suggestions, what I could do?

Currently controlling a BG socket via Alexa so keen to test this out. Is there a ready compiled .jar for this anywhere please?

I think this is this the one that you need.

I had some issues with it so have stopped using it for now. It would work to start with and then stop getting updates. I need to add some more logging but it seems like the auth starts to fial

My knowledge of Python is limited but I think what is happening is:

checksum = sum(packet[0x08:], 0xC0AD) & 0xFFFF

As you say, sum up all of the bytes from 0x08 onwards and add 0xC0AD.
Bitwise AND with 0xFFFF to leave just the 16 least significant bits (throw away the large part of the sum)

packet[0x06] = checksum & 0xFF

Bitwise AND the checksum with 0xFF to leave just the 8 least significant bits (that fit into the least significant byte of the two byte checksum at position 0x06 of the packet array)

packet[0x07] = checksum >> 8

The >>8 shifts the 16 bit checksum 8 bits to the right, leaving the most significant byte of the original checksum as a single byte, which is then put into the most significant byte of the checksum at position 0x07 in the packet array.

So overall, it’s summing up all of the numbers, finding the least significant 16 bit part of the sum and splitting it into 2x 8 bit bytes to go in the 2 bytes of checksum in the packet.

Can anyone share a .thing updated? In old version It can be like this:

Thing broadlink:sp2:xx-xx-xx-xx-xx-xx                           "socket"    [ authorizationKey="auth_key", staticIp=true, ipAddress="192.168.1.64", port=80, pollingInterval=30, iv="iv_key", mac="mac_address"  ]

For the OH3 version, what changes?

I’ve put that in my addons folder and it isn’t showing up. I’ve tried rebooting but no luck.

Also tried: (BroadlinkOH3/target/org.openhab.binding.broadlink-3.1.0-SNAPSHOT.jar at main · RobPope/BroadlinkOH3 · GitHub)