Broadlink RM-PRO and TC2 switch

Daniel is a great guy and great programmer … but not in clarity :smiley:

Hehe. :wink:
I am sorry for the confusion.
I am a bit confused my self by all the different Broadlink devices :slight_smile:

that’s alright Daniel. You’ve been great help for all of us. Keep up the good work we do appreciate every time you reply to us. Happy new year everyone!!!

You may be interested on this talk:

https://github.com/mjg59/python-broadlink/issues/54#issuecomment-271367580

1 Like

Thanks. Since my phone is not rooted, I am following the getBroadlinkSharedData.py method. Unfortunately, I cannot find jsonSubIr, jsonButton or jsonIrCode files. This is what I see…

Nvm about this. I can view the files via my phone explorer. Don’t know why it is not showing in my PC.

@oliverdog

I tried to run the script but it returns this error…

$ python3 getBroadlinkSharedData.py
  File "getBroadlinkSharedData.py", line 32
    print "ID:", jsonSubIrData[i]['id'], "| Name:", jsonSubIrData[i]['name']
              ^
SyntaxError: Missing parentheses in call to 'print'

Please help.

Use python2

Thanks. But now I am receiving this error…

$ python2 getBroadlinkSharedData.py
Traceback (most recent call last):
  File "getBroadlinkSharedData.py", line 20, in <module>
    import simplejson as json
ImportError: No module named simplejson

FYI, I installed simplejson using pip3 install simplejson. When I tried to reinstall it using pip, it says…

$ pip install simplejson
Requirement already satisfied: simplejson in /usr/local/lib/python3.4dist-packages

I manage to install Python2 in my Windows PC and manage to generate the text file filed with the TC2 codes. Will try to use the codes in my configuration soon.

@Danielhiversen

I put the codes into my configuration…

switch:
  platform: broadlink
  host: 192.168.1.000
  mac: 'AA:AA:AA:AA:AA:AA'
  switches:
    carporch_light:
      command_on: 'e9144600df090916091616090916091616091609160916091609160916090916160916091609160909161609091609161609160916090916091609161609160916090916160909000148'
      command_off: 'e9144600df090916091609160916160909161609160909160916091609161609160916091609091616091609160916090916091609160916160916091609160909161609160909000148'

It is not working. Any idea why?

That looks like hex format,
You have to convert it to the correct format,
You can try:

I am sorry. How do I use this…?

from base64 import b64encode, b64decode
hex_data  = "e9144600df090916160916090916091616090916160916090916160916090916160909161609091616091609160916091609160916091609091609160916160909161609091609000148"
packet = hex_data.decode('hex')
b64encode(packet).decode('utf8')

OK. If I understand correctly, that is code is in python. So, I modified getBroadlinkSharedData.py by adding from base64 import b64encode, b64decode on line 21 and then…

below…

code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code'])

add this…

        packet = code.decode('hex')
        code = b64encode(packet).decode('utf8')

The generated codes will become something like this…

6RRGAN8JCRYJFgkWCRYWCQkWFgkWCQkWCRYJFgkWFgkWCRYJFgkJFhYJFgkWCRYJCRYJFgkWCRYWCRYJFgkWCQkWFgkWCQkAAUg=

However, it is still not working :sweat:

I notice this in the log ValueError: Input strings must be a multiple of 16 in length.

I can feel we are getting closer…

@masterkenobi That’s exactly the issue other users are experiencing as well, the code format you get from " getBroadlinkSharedData.py" should work directly with “python-broadlink” (for the TC2 rf codes I found that you need to duplicate the code so it will be in the expected length and if you send it should work), but…I don’t know how python-broadlink was integrated into home assistant, the issue is still with the AES encryption, I believe it because of missing padding.

So you say that the code can be used directly as data in the send_data function?

https://github.com/mjg59/python-broadlink/blob/master/broadlink/init.py#L452

Edit:
Solving this issue will help: https://github.com/NightRang3r/Broadlink-e-control-db-dump/issues/1

I do not have the RM-PRO device, so it is hard for me to test this

Btw, here is how we encode the code in hass: https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/broadlink.py#L93

Exactly,

My script just dumps the codes from the e-Control app.

The first method for the rooted devices the codes stored in the rmt.db in binary, when you copy them in hex they work fine with the send_data function, you will still have the length issue (at least for TC2 switches) but if you duplicate the code and send it using the function it works great.

So for example if your code is: abcd you need to send abcdabcd

For the second script getBroadlinkSharedData.py the codes are stored in decimal format array so my script converts them to hex which should be the format to use with python-broadlink but you still need to send duplicate code.

#!/usr/bin/python

import broadlink
import time
import sys

device = broadlink.rm(host=(“IP ADDRESS”,80), mac=bytearray.fromhex(“MAC ADDRESS”))

device.auth()
time.sleep(1)
time.sleep(1)
device.host

myhex =“abcdabcd”

device.send_data(myhex.decode(‘hex’))
print “Code Sent…”

I will do some more tests later today

Btw: I don’t have home assistant installed yet, tried yesterday on a rpi with the one click install script but it failed, I’ll try to install the hassbian so I could see what’s going on

Hmm, then this should work:

hexcode = hexcode + hexcode
packet = hexcode.decode('hex')
code = b64encode(packet).decode('utf8')

Theoretically It should, but someone on another post mentioned he tried duplicating the code and it didn’t worked with HA, after I’ll install it I can do proper testing.

1 Like