BroadLink Switch Component

Hi,

I have been attempting to get HA to switch a TC2 on/off from following some information I have found here:

As you can see from the bottom of the issue someone has used the tasker app to get hold of the codes but the format is like this:

e9144600df090916160916090916091616090916160916090916160916090916160909161609091616091609160916091609160916091609091609160916160909161609091609000148

I have used an online too to convert this to base 64:

ZTkxNDQ2MDBkZjA5MDkxNjE2MDkxNjA5MDkxNjA5MTYxNjA5MDkxNjE2MDkxNjA5MDkxNjE2MDkxNjA5MDkxNjE2MDkwOTE2MTYwOTA5MTYxNjA5MTYwOTE2MDkxNjA5MTYwOTE2MDkxNjA5MTYwOTA5MTYwOTE2MDkxNjE2MDkwOTE2MTYwOTA5MTYwOTAwMDE0OA==

But when I attempt to send the command I get the following error:

ValueError: Input strings must be a multiple of 16 in length

Anybody able to help with this issue so we can see home assistant control the TC2 switches and make the component even more useful?

1 Like

Mike,

I am at your same stage - did you manage to get it working?

thanks,

D

Try something like:

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

Then @mikehole code becomes: 6QpCAN8JCRYWCRYJCRYWCRYJCRYWCQkWFgkWCQkWCRYWCRYJCRYJFhYJFgkWCRYJCRYJFhYJCRYWCQkWFgkWCRYJCRYWCQ==

Thanks for the suggestion but unfortunately I still get the same error:

17-01-09 12:08:10 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 “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/core.py”, line 1049, in _event_to_service_call
yield from service_handler.func(service_call)
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch/init.py”, line 87, in async_handle_switch_service
yield from switch.async_turn_on()
File “/srv/homeassistant/lib/python3.4/site-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 “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch/broadlink.py”, line 134, in turn_on
if self._sendpacket(self._command_on):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch/broadlink.py”, line 148, in _sendpacket
self._device.send_data(packet)
File “/home/homeassistant/.homeassistant/deps/broadlink/init.py”, line 376, in send_data
self.send_packet(0x6a, packet)
File “/home/homeassistant/.homeassistant/deps/broadlink/init.py”, line 215, in send_packet
payload = aes.encrypt(bytes(payload))
File “/srv/homeassistant/lib/python3.4/site-packages/Crypto/Cipher/blockalgo.py”, line 244, in encrypt
return self._cipher.encrypt(plaintext)
ValueError: Input strings must be a multiple of 16 in length

I have also tried doubling the codes as suggested in the GitHub topics that relate to this.

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

1 Like

Fingers crossed :slight_smile:

@mikehole Try to duplicate the code like this:

e9144600df090916160916090916091616090916160916090916160916090916160909161609091616091609160916091609160916091609091609160916160909161609091609000148e9144600df090916160916090916091616090916160916090916160916090916160909161609091616091609160916091609160916091609091609160916160909161609091609000148

and then encode it to base64.

Let me know if ti works.

It doesn’t work unfortunately :frowning:

@mikehole Unfortunately I don’t have home assistant installed (yet…), I do plan to install it this week and i will be able to test it, If i’ll manage to get everything working i’ll let you know.

Great stuff, I see form GitHub you are a contributor to the libraries on there. Good to have you on board :slight_smile:

@mikehole I am just a user who tries to get things working…lol

I finally got everything working well which includes all my broadlink accessories, RM PRO, TC2, SP2 along with amazon echo.

I published a detailed document about the process here:

I just found about Home Assistant and it looks very cool, So here we go again to another journey to get broadlink integration… :slight_smile:

1 Like

I went for HASS because it’s got the HueBridge out of the box so I was able to get an Orvibo S20 working with Alexa by only playing with config and no code.

And it has a good web user interface.

@mikehole Got it working, look at this post.

Great stuff. Must admit trying to follow that thread is a little confusing will wait for the next HASS release to drop to see if I can get it going. But af far as I can tell it’s the self.device.senddata(binascii.unhexlify(packet)) line that makes the difference?

Yes, this is the only change i made.

Great stuff, looking forwards to finally getting my dining room light sorted :slight_smile: