Need to reload automations way too often

Hello,
I am facing a problem since this weekend… Tried many things but nothing seems to work.
My problem is (quite) simple : I have to regularly (basically every morning) reload automations to make some Xiaomi switches (dual switch - this ones) being detected by HA.
The clicks on these switches are supposed to trigger automations to toggle a light.
BUT the problem that occurs is that, in the morning, automations do not work anymore, meaning the clicks on the switch don’t trigger anything.
In HA logbook/history, I can see that the click itself is not detected.
I solve this problem by reloading automations from the confi/system panel.
I could schedule an automations reloading every morning, but this would not be a proper way to solve the problem…
I first thought there was a connection problem between my switch and my ZHA network, but I eliminated this possibility, as reloading automations seems to be solving the problem…
What do you think ? :slight_smile:

EDIT: or maybe not after reading you said this:

So ignore all this:

Sounds like your binary sensors are getting the ‘unknown’ state overnight for some reason.

If your automations are using triggers like this:

trigger:
  - platform: state
    entity_id: binary_sensor.your_switch
    from: 'off'
    to: 'on'

then change the triggers to this:

trigger:
  - platform: state
    entity_id: binary_sensor.your_switch
    from: 
      - 'off'
      - 'unknown'
    to: 'on'

This is due to this breaking change introduced in 2022.2:

Screenshot 2022-02-08 at 09-55-17 2022 2 Let's start streamlining

https://www.home-assistant.io/blog/2022/02/02/release-20222/#breaking-changes

Alternately you could simplify:

trigger:
  - platform: state
    entity_id: binary_sensor.your_switch
    to: 'on'

The from: state is optional and in the case of a binary state trigger it’s often irrelevant to your automation unless your automation is specifically to handle recovering from an unexpected state.

1 Like

I did consider adding that but the trouble with that trigger is it may trigger after a restart (unavailable → on). This is unlikely as the binary sensors should be off, but it is best to define the states.

Also after re-reading the original post I don’t think this is the issue.

Though why reloading automations fixes it… :man_shrugging:

1 Like

Hello guys,
Thanks a lot for your answers !
The switch does not work exactly this way…
The with works as a remote, not as an on/off button.
Here is my automation :

alias: Switch name
description: ''
trigger:
  - device_id: 15543ab534e35b3a45e439e0
    domain: zha
    platform: device
    type: remote_button_short_press
    subtype: button_2
condition: []
action:
  - service: light.toggle
    target:
      entity_id: light.somelight
mode: single

I tried again this morning, and, again, I had to reload my automations, because SOME automations working with ZHA were not working.
I explain :

  • tried to click on my Xiaomi buttons (whichever they are) : nothing happens, the clicks have no effect on anything.
  • clicked on a Zigbee button (wired switch), supposed to launch an automation (turn on the radio on one of my Alexa devices) => worked perfectly.
    It looks like SOME of my Zigbee devices (the ones working on battery) are getting disconnected… BUT, as soon as I reload the automations from the system panel : works again :cold_sweat: :cold_sweat:

In the meantime, and to bypass the misfunctionning, I added the following automation to reload automations every hour, but I would really like to address my problem the proper way…

alias: Reload automations every hour
description: ''
trigger:
  - platform: time_pattern
    hours: /01
condition: []
action:
  - service: automation.reload
mode: single

1 Like

Hi,
I have a ConBee II and I have the same problem : I have to relad automations to have my switches work.
Theses are Rf355 (Rfxtrx) switches that commands a Zigbee light variator.
And sometimes, these switches doesn’t work, about every 3 or 5 days, and always after a reboot.

I think it’s a bug with Conbee II and automationss, as all other rfxtrx based automations sill work, as rfxtrx and zigbee entities.

So I’ll use your bypass method, thank you.

I have posted a bug in april with the deconz integration: each time a reboot takes place, the automations get loaded when deconz is not ready yet to link the listeners to the right entities. Deconz produces errors every reboot for all listeners.

This is the type of error I get a lot on each reboot:
2022-04-29 20:47:41 ERROR (MainThread) [homeassistant.components.automation.knop_koken] Got error ‘No deconz_event tied to device “Kooksceneknop” found’ when setting up triggers for Sfeerkeuken

@tom_l : This is not about state listeners but button events from remotes. They are device actions “a button is pressed” for momentary switches. Deconz event listeners may still work, I havent tested those. Because these events come in, the actions are just not listening.

The developer has not taken any action on this for some time now. If you too have Deconz, please add a comment with the bug:

If you use another integration, please post an issue with the integration at hand, linking the Deconz bug too so they know more integrations may face similar problems. Maybe this even needs to be taken a step higher to see if there’s something similar going on with more integrations.

In the meantime I created an automation to reload the automations a minute or so after a reboot to work around this. I do not have to reaload every hour now, it has been stable like this for almost two months.

alias: System restart workarounds
description: Reload automations to fix Deconz triggers
trigger:
  - platform: homeassistant
    event: start
condition: []
action:
  - delay:
      hours: 0
      minutes: 1
      seconds: 0
      milliseconds: 0
  - service: automation.reload
    data: {}
mode: single
2 Likes

Thanks for raising this. I saw the github issue has been closed already. Have you managed to find a working proper fix for this?
I always thought something in my hardware was broken for a few months, but due to this post I saw that restarting the automations did the trick.

I have an automation to reload the automations a few minutes after every reboot, as you can see in my earlier post. That works around it for me. The issue gets closed automatically every so often, and I got tired of reopening it again, and again and again, …

Maybe I’ll do a feature request to automate that too :wink:

Thanks for getting back so fast and providing your solution. I copied your automation for now. Hope that will fix my issues till a proper fix will come.