Broadlink RM-PRO and TC2 switch

Anyway guys. I have tested and it is still NOT working for me. This is what I did.

  1. 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.py1 after edit the line 183 to become self._device.send_data(binascii.unhexlify(packet))
  2. I downloaded the getBroadlinkSharedData.py file and add these lines; import base64 to the top and then code = base64.b64encode(code+code) below code = ''.join('%02x' % (i & 0xff) for i in jsonIrCodeData[i]['code'])
  3. I use the generated code into my configuration…

example:

- platform: broadlink
  host: 192.168.1.999
  mac: 'XX:XX:XX:XX:XX:XX'
  type: rm
  switches:
    entrance_light:
      command_on: 'ZTkxNDQ2MDBkZjA5MTYwOTE2MDkwOTE2MDkx....'
      command_off: 'ZTkxNDQ2MDBkZjA5MDkxNjA5MTYwOTE2MDkxN....'

It is still not working. Did I do anything wrong?

base64encode.py

import base64
encoded = base64.b64encode(‘e90a34000b21220b0b21210c0b22210c0b22210c0c21210c0b21210c0c220b210c210c210c210b22210c210c0b000150220b220b0c21220b00000000’)
print encoded

ZTkwYTM0MDAwYjIxMjIwYjBiMjEyMTBjMGIyMjIxMGMwYjIyMjEwYzBjMjEyMTBjMGIyMTIxMGMwYzIyMGIyMTBjMjEwYzIxMGMyMTBiMjIyMTBjMjEwYzBiMDAwMTUwMjIwYjIyMGIwYzIxMjIwYjAwMDAwMDAw

switch:

  • platform: broadlink
    host: 192.168.1.33
    mac: ‘b4:43:0d:38:4c:48’
    switches:
    reciever:
    friendly_name: “livingroom lights”
    command_on: 'ZTkwYTM0MDAwYjIxMjIwYjBiMjEyMTBjMGIyMjIxMGMwYjIyMjEwYzBjMjEyMTBjMGIyMTIxMGMwYzIyMGIyMTBjMjEwYzIxMGMyMTBiMjIyMTBjMjEwYzBiMDAwMTUwMjIwYjIyMGIwYzIxMjIwYjAwMDAwMDAw

    command_off: ‘’

It is still not working. Did I do anything wrong?

I am sorry. I don’t understand what you are trying to tell me.

@masterkenobi I am using version 0.35.3 on a raspberry pi, I didn’t replace any file I used the original one and changed only:

self.device.senddata(packet)

to

self.device.senddata(binascii.unhexlify(packet))

Maybe that’s why mine was at line 148 and yours was at line 183

And this is how my config file looks like:

switch:
platform: broadlink
host: 10.0.0.5
mac: ‘b4:43:00:00:00:00’
switches:
entrance_light:
friendly_name: “Entrance Light”
command_on: ‘ZTkwYTQyMDBkZjA5MDkxNjE2MDkxNjA5MDkxNjE2MDkxNjA5MDkxNjE2MDkwOTE2MTYwOTE2MDkwOTE2MDkxNjE2MDkxNjA5MDkxNjA5MTYxNjA5MTYwOTE2MDkxNjA5MDkxNjA5MTYxNjA5MDkxNjE2MDkwOTE2MTYwOTE2MDkxNjA5MDkxNjE2MDllOTBhNDIwMGRmMDkwOTE2MTYwOTE2MDkwOTE2MTYwOTE2MDkwOTE2MTYwOTA5MTYxNjA5MTYwOTA5MTYwOTE2MTYwOTE2MDkwOTE2MDkxNjE2MDkxNjA5MTYwOTE2MDkwOTE2MDkxNjE2MDkwOTE2MTYwOTA5MTYxNjA5MTYwOTE2MDkwOTE2MTYwOQ==’
command_off: ‘ZTkwYTQyMDBkZjA5MDkxNjE2MDkwOTE2MTYwOTA5MTYwOTE2MTYwOTA5MTYwOTE2MTYwOTE2MDkwOTE2MDkxNjE2MDkwOTE2MTYwOTA5MTYxNjA5MTYwOTE2MDkxNjA5MTYwOTE2MDkwOTE2MDkxNjE2MDkxNjA5MTYwOTA5MTYxNjA5MTYwOTA5MTZlOTBhNDIwMGRmMDkwOTE2MTYwOTA5MTYxNjA5MDkxNjA5MTYxNjA5MDkxNjA5MTYxNjA5MTYwOTA5MTYwOTE2MTYwOTA5MTYxNjA5MDkxNjE2MDkxNjA5MTYwOTE2MDkxNjA5MTYwOTA5MTYwOTE2MTYwOTE2MDkxNjA5MDkxNjE2MDkxNjA5MDkxNg==’

side_lights:
  friendly_name: "Side Lights"
  command_on: 'ZTkwYTQyMDBkZjA5MDkxNjE2MDkxNjA5MDkxNjE2MDkwOTE2MDkxNjE2MDkxNjA5MDkxNjE2MDkwOTE2MDkxNjE2MDkxNjA5MTYwOTE2MDkxNjA5MTYwOTA5MTYxNjA5MDkxNjA5MTYwOTE2MDkxNjE2MDkwOTE2MDkxNjE2MDkwOTE2MDkxNjE2MDllOTBhNDIwMGRmMDkwOTE2MTYwOTE2MDkwOTE2MTYwOTA5MTYwOTE2MTYwOTE2MDkwOTE2MTYwOTA5MTYwOTE2MTYwOTE2MDkxNjA5MTYwOTE2MDkxNjA5MDkxNjE2MDkwOTE2MDkxNjA5MTYwOTE2MTYwOTA5MTYwOTE2MTYwOTA5MTYwOTE2MTYwOQ=='
  command_off: 'ZTkwYTQyMDBkZjA5MDkxNjA5MTYxNjA5MDkxNjA5MTYxNjA5MDkxNjE2MDkwOTE2MDkxNjE2MDkxNjA5MDkxNjE2MDkwOTE2MTYwOTE2MDkxNjA5MTYwOTE2MDkxNjA5MTYwOTA5MTYwOTE2MTYwOTE2MDkxNjA5MTYwOTA5MTYwOTE2MDkxNjE2MDllOTBhNDIwMGRmMDkwOTE2MDkxNjE2MDkwOTE2MDkxNjE2MDkwOTE2MTYwOTA5MTYwOTE2MTYwOTE2MDkwOTE2MTYwOTA5MTYxNjA5MTYwOTE2MDkxNjA5MTYwOTE2MDkxNjA5MDkxNjA5MTYxNjA5MTYwOTE2MDkxNjA5MDkxNjA5MTYwOTE2MTYwOQ=='

It’s not working, even if i use only SP2

switch:
platform: broadlink
host: 10.0.0.4
mac: ‘b4:43:00:00:00:00’
type: sp2
friendly_name: ‘Router’

You need to use the dev version. A new release will probably come during the weekend.

Oh I see…I’ll wait for the release than.

Btw: does HA have an option to use on/off http commands ?

I have URL for an accessory that accepts http get requests with different values for on and off, is that possible?

Thanks!

1 Like

Check out the switches components:

Here you will find the RESTfull switch:

2 Likes

The RESTfull switch is probably the best choice.

Thanks, but it looks like it support only post requests and get requests are just for getting the status, the command line with curl is good enough:)

1 Like

@NightRanger

OK. I have revert it back to the original version but with modified line 148

But what I am confuse on is how to get the base64 code you are getting. Based on your original getBroadlinkSharedData.py, let say from there the hex code I got is…

hexcode = '123456abcdef'

is this how to get the correct base64 code?

base64code = base64.b64encode(hexcode)

or…

base64code = base64.b64encode(hexcode+hexcode)

here is an example of what I type into my Raspberry Pi:

pi@raspberrypi:~ $ python
Python 2.7.9 (default, Sep 17 2016, 20:26:04)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from base64 import b64encode, b64decode
>>> hex_data  = "b24632001c0a1c1b0c1b0c1b0c0a1c1b0c0a1c0a1c0a1c0a1c0a1c0a1c1b0c0a1c1b0c0a1c1b0c1b0c1b0c0a1c0a1c1b0c1b0c1b0cc5000000000000"
>>> packet = hex_data.decode('hex')
>>> b64encode(packet).decode('utf8')
u'skYyABwKHBsMGwwbDAocGwwKHAocChwKHAocChwbDAocGwwKHBsMGwwbDAocChwbDBsMGwzFAAAAAAAA'
>>>

AFAIK this is still all applicable. Also note this code is a different code I am suing for a standard RF device so it’s not been entered twice.

It’s this code that I then use:

@masterkenobi For TC2 use duplicated code:

base64code = base64.b64encode(hexcode+hexcode)

Example:

import base64

myhex = "e90a4200df0909160916091616091609091616091609091616091609160916091609091616090916091616090916091616090916091609161609091616091609160909161609"

encoded = base64.b64encode(myhex + myhex)

print encoded

thanks but it is still not working. actually I am unsure of one thing in the documentation. The device MAC address I need to put in is the MAC address of my RM Pro which can be obtained from the router, right?

Yes, or from the e-control app device list in the following format: xx:xx:xx:xx:xx:xx

okay… then i really have no idea why it is not working for me :cry:

Do you have any errors in your HA logs ?

yes. this is the error i can find.

homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.4/asyncio/tasks.py", line 233, in _step
    result = coro.throw(exc)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/core.py", line 1049, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/__init__.py", line 87, in async_handle_switch_service
    yield from switch.async_turn_on()
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/helpers/entity.py", line 353, in async_turn_on
    None, ft.partial(self.turn_on, **kwargs))
  File "/usr/lib/python3.4/asyncio/futures.py", line 388, in __iter__
    yield self  # This tells Task to wait for completion.
  File "/usr/lib/python3.4/asyncio/tasks.py", line 286, in _wakeup
    value = future.result()
  File "/usr/lib/python3.4/asyncio/futures.py", line 277, in result
    raise self._exception
  File "/usr/lib/python3.4/concurrent/futures/thread.py", line 54, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/broadlink.py", line 134, in turn_on
    if self._sendpacket(self._command_on):
  File "/usr/local/lib/python3.4/dist-packages/homeassistant/components/switch/broadlink.py", line 148, in _sendpacket
    self._device.send_data(binascii.unhexlify(packet))
  File "/home/pi/.homeassistant/deps/broadlink/__init__.py", line 450, in send_data
    self.send_packet(0x6a, packet)
  File "/home/pi/.homeassistant/deps/broadlink/__init__.py", line 229, in send_packet
    payload = aes.encrypt(bytes(payload))
  File "/home/pi/.homeassistant/deps/Crypto/Cipher/blockalgo.py", line 244, in encrypt
    return self._cipher.encrypt(plaintext)
ValueError: Input strings must be a multiple of 16 in length