Broadlink RM-PRO and A1 sensor

If you are getting an error message with “ValueError: AES key must be either 16, 24, or 32 bytes long”
it would be great if you could try this version:

https://github.com/home-assistant/home-assistant/blob/issue-%234997/homeassistant/components/switch/broadlink.py

Download the file and put it in HA_CONFIG_FOLDER/custom_components/switch/broadlink.py

Report back how it goes.

You can also put it in custom_components/switch/broadlink.py

keeping the file in
srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch
?

or changing in bth directories?

well I put both files (I think 2 different versions…)

It shows the choice to learn from 1 or other broadlink, but the learning command does not work, giving the usual error

16-12-20 15:45:51 homeassistant.components.http: Serving /api/services/broadlink/learn_command_192.168.1.89 to 192.168.1.52 (auth: True)
16-12-20 15:45:51 homeassistant.core: Bus:Handling <Event call_service[L]: service_data=, service_call_id=1978023984-25, domain=broadlink, service=learn_command_192.168.1.89>
16-12-20 15:45:51 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 "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 70, in _learn_command
    broadlink_device.enter_learning)
  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 "/home/hass/.homeassistant/deps/broadlink/__init__.py", line 381, in enter_learning
    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

Is it possible to add the assumed_state attribute so can change the switch icon?

1 Like

I just tried it here as well…:slight_smile:

Sorry, please ignore my question. It is working already.

I was adding the attribute under the broadlink platform, it should be added under customize like this.
customize:
switch.broadlink_switch:
assumed_state: false

similar error

16-12-20 16:21:51 homeassistant.components.http: Serving /api/services/homeassistant/turn_on to 192.168.1.3 (auth: True)
16-12-20 16:21:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=homeassistant, service=turn_on, service_data=entity_id=switch.asus_router, service_call_id=1977274416-7>
16-12-20 16:21:51 homeassistant.core: Bus:Handling <Event call_service[L]: domain=switch, service=turn_on, service_data=entity_id=['switch.asus_router'], service_call_id=1977274416-8>
16-12-20 16:21:52 homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 164, 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 235, in send_packet
    response = self.cs.recvfrom(1024)
socket.timeout: timed out

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 164, 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

During handling of the above exception, another exception occurred:

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 "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 150, in turn_on
    if self._sendpacket(self._command_on):
  File "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 173, in _sendpacket
    return self._sendpacket(packet, max(0, retry-1))
  File "/home/hass/.homeassistant/custom_components/switch/broadlink.py", line 170, in _sendpacket
    self._device.auth()
  File "/home/hass/.homeassistant/deps/broadlink/__init__.py", line 169, in auth
    response = self.send_packet(0x65, payload)
  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

hi, which file is now covering what?
i have a broadlink.py under sensor - for an e-air (A1) – which i understand i have to remove after i upgrade.
but for my switch i have to keep the broadlink.py under custom_components/switch

corect?

after giving it a go the point seems moot: turns out I have an SP3 (SPCC-EU-ENG officially),
any chance of supporting the SP3cc… any time soon?

thanks for the good work btw.

It seems that sp3 is supported: https://github.com/mjg59/python-broadlink/blob/master/broadlink/init.py#L18

Great!
Is there already a way to use SP1, SP2 or SP3, once they report their status…

I think Sp2 and sp3 will report the current state back to HA, but sp1 will not.

@undef : could you try to add your sp3 switch as:
type: sp2

I have a SP Mini.
Would be
type: SPMini
?

Should also be sp2: https://github.com/mjg59/python-broadlink/blob/master/broadlink/init.py#L16

Notice, that you will need the newest version: https://github.com/home-assistant/home-assistant/pull/5022

I will will add support for all the types later

The log not show any problem…

for you problem try to copy cp -r /usr/local/lib/python2.7/dist-packages/Crypto /usr/local/lib/python3.5/dist-packages/

How do I config complete A/C remote with all the buttons needed?

Thanks.

That will be a really challenge…
First of all, I think is time we ask for a Button Instance instead of using switches.
I think the best option would be creating a floating remote filled with buttons, just like the history floating window when click on a component on frontend.

It did not work.
Got a persistent notification saying Invalid Config

switch 3:
  platform: broadlink
  host: 192.168.1.207
  mac: 'B4:43:0D:XX:XX:XX'
  type: sp2
  switches:
    sp_switch:

Remove the two last lines