Broadlink RM-PRO getting error

Hi Experts,

Im new to this Home assistant. I im configuring my Raspberry Pi to integrate with my Broadlink RM Pro. When i add the below command i get error please help what i did wrong.

switch:
   platform: broadlink
   host: 192.168.1.24
   mac: B4:43:0D:DA:2C:1E
   timeout: 15
   switches:
    TV:
    friendly_name: "Philips TV"
    -command_on: 'JgAcAB0dHB44HhweGx4cHR06HB0cHhwdHB8bHhwADQUAAAAAAAAAAAAAAAA='
    -command_off: 'JgAaABweOR4bHhwdHB4dHRw6HhsdHR0dOTocAA0FAAAAAAAAAAAAAAAAAAA='

Error I get:

16-12-19 00:58:30 homeassistant.loader: Unable to find component switch.broadlink
16-12-19 00:58:30 homeassistant.bootstrap: Unable to find platform switch.broadlink

Appreciate your help…

Cheers…

You need to upgrade to 0.35

Hi Daniel,

Many thanks for the reply. Do u mean upgrade my Broadlink RM Pro device?

Thanks.

Cheers…

No, home-assistant

Hi Daniel,

Many thanks for the prompt reply. Well noted, will do the upgrade.

Thanks…

Cheers.

Hi Experts,

After i have upgraded this is what i encounter:

16-12-19 20:48:14 homeassistant.components.switch: Error while setting up platform broadlink
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 150, in _async_setup_platform
entity_platform.add_entities, discovery_info
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 48, in setup_platform
import broadlink
File “/home/homeassistant/.homeassistant/deps/broadlink/init.py”, line 4, in
from Crypto.Cipher import AES
ImportError: No module named ‘Crypto’

Anything i missed out?

Thanks in advance.

Cheers…

There is a bug in the Broadlink library we are using. I am waiting for the fix to be approved: https://github.com/mjg59/python-broadlink/pull/30

Until then you have to install crypto manually
If you use a virtual environment enable it.
Run pip install pycrypto

Wow thanks very much for swift reply. Very much appreciated, Sir!

Cheers…

I Just ran the pip install pycrypto and this is the error i received:

warning: GMP or MPIR library not found; Not building Crypto.PublicKey._fastmath.

Successfully installed pycrypto
Cleaning up…

Then i restarted the raspberry pi then the error from homeassistant.log:

16-12-19 21:29:51 homeassistant.components.switch: Error while setting up platform broadlink
Traceback (most recent call last):
File “/srv/homeassistant/lib/python3.4/site-packages/homeassistant/helpers/entity_component.py”, line 150, in _async_setup_platform
entity_platform.add_entities, discovery_info
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 48, in setup_platform
import broadlink
File “/home/homeassistant/.homeassistant/deps/broadlink/init.py”, line 4, in
from Crypto.Cipher import AES
ImportError: No module named ‘Crypto’

Thanks in advance…

Cheers…

check the indent of TV (I think should be 2 spaces not 1)
Also before the command_on and off, I did not use the -
the mac address between ’
also in friendly_name a ’ and not "

I don’t know if all above is critical or not, worth to try though

You should activate the virtual environment before you install crypto.

smart@sitha:~#source /srv/hass/bin/activate
(hass) smart@sitha:~# pip install pycrypto

I did the above, and have no error from installation. But still in error log I get this

16-12-20 08:44:18 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.3 (auth: True)
16-12-20 08:44:18 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_data=entity_id=switch.asus_router, domain=homeassistant, service_call_id=1977892912-117>
16-12-20 08:44:18 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_data=entity_id=['switch.asus_router'], domain=switch, service_call_id=1977892912-118>
16-12-20 08:44:18 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/hass/hass_venv/lib/python3.4/site-packages/homeassistant/core.py", line 1049, in _event_to_service_call
    yield from service_handler.func(service_call)
  File "/srv/hass/hass_venv/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/hass/hass_venv/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/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/broadlink.py", line 134, in turn_on
    if self._sendpacket(self._command_on):
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch/broadlink.py", line 148, in _sendpacket
    self._device.send_data(packet)
  File "/home/hass/.homeassistant/deps/broadlink/__init__.py", line 376, in send_data
    self.send_packet(0x6a, packet)
  File "/home/hass/.homeassistant/deps/broadlink/__init__.py", line 214, in send_packet
    aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/Crypto/Cipher/AES.py", line 95, in new
    return AESCipher(key, *args, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/Crypto/Cipher/AES.py", line 59, in __init__
    blockalgo.BlockAlgo.__init__(self, _AES, key, *args, **kwargs)
  File "/srv/hass/hass_venv/lib/python3.4/site-packages/Crypto/Cipher/blockalgo.py", line 141, in __init__
    self._cipher = factory.new(key, *args, **kwargs)
ValueError: AES key must be either 16, 24, or 32 bytes long

That seems to be bug in the library we are using.
You should report to https://github.com/mjg59/python-broadlink and https://github.com/home-assistant/home-assistant

how you do that. In issues?

Hi Daniel,

Many thanks for the effort. Will report the bug.

Thanks. Hope to get u a beer one day. :slight_smile:

Cheers.