Broadlink RM-PRO and TC2 switch

@masterkenobi

Ok, Test 1, Dumped the codes using my “getBroadlinkSharedData.py” script, sending it using the following code and it’s working, as you can see you need to duplicate the code, I am installing HA and now and hopefully I will be able to see if there’s any problem:

import broadlink
import time
import sys

device = broadlink.rm(host=(“10.0.0.2”,80), mac=bytearray.fromhex(“b4430fffffff”))

print “Connecting to Broadlink device…”
device.auth()
time.sleep(1)
print “Connected…”
time.sleep(1)
device.host

hex1 = “e90a4200df0909160916091616091609091616091609091616091609160916091609091616090916091616090916091616090916091609161609091616091609160909161609”
hex2 = “e90a4200df0909160916091616091609091616091609091616091609160916091609091616090916091616090916091616090916091609161609091616091609160909161609”
myhex = hex1 + hex2

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

1 Like

There have been a lot of bug fixes in the Broadlink component since the last release. So I suggest that you wait for the next release or use the dev version: https://home-assistant.io/developers/development_environment

@masterkenobi Ok, all is working fine when using the library directly, i have tested with HA and having the same issue with length, It can be the version of the library or the way it was implemented int HA.

I guess we will have to wait for the updates and try again.

1 Like

How to convert hexcode to b64encode

or

Great to hear that. I guess we just need to wait for @Danielhiversen to make it works on the next release. By the way, I can help you to test it. I just need to know how. Thanks guys!

No issues have been reported for the dev version, so I am not going to fix anything more before the next release.
So the release version will probably be the same as the dev.

Always great if someone will test the dev version: https://home-assistant.io/developers/development_environment

1 Like

5 TC2 switches are coming, so I can’t test. Will do as soon as they come

how do i test out the dev version? The link you sent earlier is too deep for me…

1 Like

@masterkenobi @Danielhiversen OK Guys, It’s working

Line 148: /homeassistant/components/switch/broadlink.py

Change:

self._device.send_data(packet)

To:

self._device.send_data(binascii.unhexlify(packet))

Works with TC2 duplicated hex code (converted to b64) and IR (no need to duplicate it like the tc2) works great as well.

So it looks like this fix is doing the trick, but i am not sure if it will break something else like SP1/SP2

2 Likes

great to hear. Can’t wait to test it out. @Danielhiversen, where can I get the latest copy of broadlink.py? I would like to try it out by replacing the existing one; /usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/broadlink.py?

Anyone know how do i add an sp2 power plug to my configuration in addition to the ir and rf codes going to my RM pro ?

@NightRanger

I went to https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/broadlink.py and I cannot find self.device.senddata(packet) on line 148. I can only find self._device.send_data(packet) on line 183.

Sorry…

self._device.send_data(packet) is at line 183
It was 148 when i opened it in nano from my RPI

OK. So I have replaced the original /usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/broadlink.py with the one I got from https://github.com/home-assistant/home-assistant/blob/dev/homeassistant/components/switch/broadlink.py after edit the line 183 to become self._device.send_data(binascii.unhexlify(packet))

When you said…

Does that mean, I need to use the hex code generated by Broadlink-e-control-db-dump/getBroadlinkSharedData.py at master · NightRang3r/Broadlink-e-control-db-dump · GitHub, duplicate it (a+a) and then convert it to b64 using

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

??

import base64
print base64.b64encode('e9144600df09...')

do you know how do I add a sp2 power plug to my configuration in addition to the ir and rf codes going to my RM pro?

I am sorry. I don’t understand. Try…

- platform: broadlink
  host: 192.168.1.999
  mac: 'XX:XX:XX:XX:XX:XX'
  type: sp2
  switches:
    entrance_light:
      command_on: '6RRGAN8JFgkWCQkWCRYWCQkWCR....'
      command_off: '6RRGAN8JCRYJFgkWCRYJFhYJFgkW...'

It’s a wifi based controller it doesn’t have IR or RF codes

I can’t add more than one broadlink platform or type i get yaml error it says i have duplicate values because my rm is already configured.

It is explained in the documentation for the next release https://github.com/home-assistant/home-assistant.github.io/blob/next/source/_components/switch.broadlink.markdown

For the second platform you have to use

switch 2:
  platform: broadlink

Thanks you so much, I missed it!