Broadlink RM-PRO and A1 sensor

No, you can just add another sensor 2: below

Ok, thanks

I just tested it more with the new code, seems like the code break the on/off button icon, the switch function still work but the icon doesn’t change state, i revert back to the old broadlink.py fixed the problem.

I just figured it out. New version out :slight_smile:

@anon35356645

Mine works with this:

sensor:
  - platform: broadlink
    name: "Sala"
    update_interval: 60
    host: 192.168.1.153
    mac: 'b4:43:0d:38:46:c2'
    monitored_conditions:
      - temperature
  - platform: broadlink
    name: "Suite"
    update_interval: 60
    host: 192.168.1.225
    mac: 'b4:43:0d:70:0e:b5'
    monitored_conditions:
      - temperature
      - humidity
      - air_quality
      - light
      - noise

two times broadlink, and no problem? Ok

gee, you are quick, tested with new version, problem solved, cheers.:beer:

1 Like

where do you put the new broadlink.py file?

It depends on your setup, mine one is here /srv/homeassistant/lib/python3.4/site-packages/homeassistant/components/switch

If you go to this link, it tells you where the path of that file is.
https://github.com/home-assistant/home-assistant/compare/broadlink?expand=1

mine is on:

/srv/hass/hass_venv/lib/python3.4/site-packages/homeassistant/components/switch

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.