Broadlink switch stop working after day or two

Hey

My HA is mainly controling Broadlink switches and everything works exellent.
But after day or two one of the switches “stops” working and in log file I see following errors.
The problem disappears each time if I restart HA, everything back to work.

17-01-09 19:40:37 homeassistant.components.http: Serving /api/services/switch/turn_on to 3.23.24.143 (auth: True)
17-01-09 19:40:37 homeassistant.core: Bus:Handling <Event call_service[L]: service=turn_on, service_call_id=3052416464-45, service_data=entity_id=switch.ac, domain=switch>
17-01-09 19:40:37 homeassistant.core: Error doing job: Task exception was never retrieved
Traceback (most recent call last):
File “/usr/lib/python3.4/asyncio/tasks.py”, line 234, 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 386, in iter
yield self # This tells Task to wait for completion.
File “/usr/lib/python3.4/asyncio/tasks.py”, line 287, in _wakeup
value = future.result()
File “/usr/lib/python3.4/asyncio/futures.py”, line 275, 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(packet)
File “/root/.homeassistant/deps/broadlink/init.py”, line 376, in send_data
self.send_packet(0x6a, packet)
File “/root/.homeassistant/deps/broadlink/init.py”, line 214, in send_packet
aes = AES.new(bytes(self.key), AES.MODE_CBC, bytes(self.iv))
File “/usr/local/lib/python3.4/dist-packages/Crypto/Cipher/AES.py”, line 95, in new
return AESCipher(key, *args, **kwargs)
File “/usr/local/lib/python3.4/dist-packages/Crypto/Cipher/AES.py”, line 59, in init
blockalgo.BlockAlgo.init(self, _AES, key, *args, **kwargs)
File “/usr/local/lib/python3.4/dist-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

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

confirm, new release works excellent (both 36 and 37)

I have just setup home assistant on my man mini. Running version 0.37.0 and I am still seeing the above behaviour.

Should I be running a dev version or are you saying dev version. 0.37.0 only came out a couple of days ago so not sure if your running this or dev version.

BTW - just setup homebridge. Having siri to control my switches is so cool.

There is no difference between 0.37 and the current dev version for the Broadlink component.

Then it is something wrong with your code. Try to relearn the code.

Its an SP MINI plug connected to a lamp. No IR code. Being a noobie can you suggest how I and where I get the logs for diagnosis of the problem.

Does your config look like this?

switch 1:
  platform: broadlink
  host: IP_ADDRESS
  mac: 'MAC_ADDRESS'
  type:  spminiplus
  friendly_name: 'Humidifier'

switch bedroom_spmini:
platform: broadlink
host: 192.168.1.27
mac: ‘XX:XX:XX:XX:XX:XX’
type: spmini2
friendly_name: ‘Bedroom Light’
switches:
bedroom_light:
command_on: ‘switch_packet on’
command_off: ‘switch_packet off’

Will change to spminiplus and test.

This is the device I have.

Or just remove the two last lines (command_on and command_off should not be there.)

Firstly - let me just say thanks for the help.

Made changes as suggested to all my spmini switches. Bedroom Light has not failed yet but the issue appears to be rather intermittent. Noticed now however that the Lounge Light did fail after about 15-20 minutes.

Again for clarity sake I have the following configs for the spmini devices. Also including the customize section just so we have everything on these devices

customize:
- entity_id: switch.spare_bedroom_dehumidifier
friendly_name: Spare Bedroom Dehumidifier
icon: mdi:image-filter-vintage
- entity_id: switch.laundry_dehumidifier
friendly_name: Laundry Dehumidifier
icon: mdi:image-filter-vintage
- entity_id: switch.lounge_light
friendly_name: Lounge Lamp
icon: mdi:lamp
- entity_id: switch.bedroom_light
friendly_name: Bedroom Lamp
icon: mdi:lamp

switch lounge_spmini:
platform: broadlink
host: 192.168.1.22
mac: ‘XX:XX:XX:XX:XX:XX’
type: spminiplus
friendly_name: ‘Lounge Light’

switch laundry_spmini:
platform: broadlink
host: 192.168.1.5
mac: ‘XX:XX:XX:XX:XX:XX’
type: spminiplus
friendly_name: ‘Laundry Dehumidifier’

switch spare_bedroom_spmini:
platform: broadlink
host: 192.168.1.25
mac: ‘XX:XX:XX:XX:XX:XX’
type: spminiplus
friendly_name: ‘Spare Bedroom Dehumidifier’

switch bedroom_spmini:
platform: broadlink
host: 192.168.1.27
mac: ‘XX:XX:XX:XX:XX:XX’
type: spminiplus
friendly_name: ‘Bedroom Light’

What do you mean by failed? Errors in the log?

On the Home Assistant web portal under states I see the switch but when I click on it, it goes to on mode briefly then flicks back to off. Does nothing to the actual switch itself.

Noticed this in the log file
17-02-01 08:33:05 ERROR (<concurrent.futures.thread.ThreadPoolExecutor object at 0x103f8c898>_5) [homeassistant.components.switch.broadlink] timed out

Not always the same device. Now its the dehumidifier switch.

So it is a network issue. Try to increase the timeout in the config

Will try that - been stable for the last couple of hours … this may be due to the changes you suggested so will let it go for a while.

Hi Daniel

Just letting you know that I am still seeing timeouts or inaccessible switches.
Modified config as directed

switch spare_bedroom_spmini:
platform: broadlink
host: 192.168.1.25
mac: ‘B4:43:0D:CB:8C:35’
timeout: 30
type: spminiplus
friendly_name: ‘Spare Bedroom Dehumidifier’

Entry in log file
17-02-02 12:43:14 ERROR (<concurrent.futures.thread.ThreadPoolExecutor object at 0x103740a90>_1) [homeassistant.components.switch.broadlink] timed out

It happens on multiple switch with no set time till failure.

Thoughts ?

is it happens when you fire commands to multiple switches in script in a raw? if yes, try considering adding some delay between each command…

I dont send multiple commands in a script, It just happens. Can you suggest how I get more information from the log files. How do I turn on more detailed logging.

no debug, not actually helps. can you share your code of switch with the commands you’re firing?

Have shown only the relevant sections for one of the switches below.

This one just failed. I am also experiencing the “OSError: [Errno 24] Too many open files” but this problem happens independently of the “too many open files” error. To get things working for the problem switch I just restart HA and it works.

The “too many open files” - requires a machine reboot. When this problem happens restarting HA also fails.

  customize:
    - entity_id: switch.spare_bedroom_dehumidifier
      friendly_name: Spare Bedroom Dehumidifier
      icon: mdi:image-filter-vintage


switch spare_bedroom_spmini:
  platform: broadlink
  host: 192.168.1.25
  mac: 'B4:43:0D:CB:8C:35'
  timeout: 30
  type:  spminiplus
  friendly_name: 'Spare Bedroom Dehumidifier'

group:
  default_view:
    view: yes
    entities:
      - group.lounge_room
      - group.bedroom
      - group.spare_bedroom
      - group.study
      - group.climate
      - group.laundry
      - sensor.plex
      - sun.sun
      - device_tracker.kwsddzoe_samsiphone
  spare_bedroom:
    name: "Spare Bedroom"
    view: no
    entities:
      - switch.spare_bedroom_dehumidifier

regarding too many open files, google it, there’s few solutions could be found of stackoverflow.
and for broadlink switches, my config looking like this:

switch:
  - platform: broadlink
    host: 172.16.13.231
    mac: 'B4:43:0D:B0:12:2A'
    switches:
      reciever:
        command_on: '6RsyABIFCA4HDhAFCA0HDgDDEIIWUSOAQJKJEFBw4HEROBw4QBREFCA4HDQeOAAAAAAAA'
        command_off: '6RsyAAgOEAURBQgXXYYWWUUSSIIPPSSDQgNCA0RBgcPBg0IjhIFCA0HDhEGBw0HDQgNAAAAAAAA'
        friendly_name: "Salon Lamp"