Shelly modules turn off after HomeAssistant restart; can we influence it?

Hello,

I am observing weird behavior for some months that I tracked down to shellies that are turning on/off after Home Assistant restart or apparently after some “clean up” process. One might not be worried by having shelly switch being turned off after the HA restart, however, in some configurations I have shelly in the wall behind the physical switch and zigbee lights I am turning on using an automation that is triggered by the toggle of the shellies in the wall. Especially I connected a shelly module to my six physical rockers/switches in the hall that were connected to a relay. I connected shelly to the relay and turn on zigbee lights in the hall by an automation.

First, the behavior after HA restarts switches all groups on/off for example. Based on what rule is beyond me. This is by default?

Second, I tracked down that almost every shelly (funny, not every but almost every, what is the rule which one is beyond me) goes through this what looks like some clean up process. However, it ends by turning on/off the switch. That apparently makes a party lighting in our home.

Any ideas how to force shelly modules to NOT turn on/off when it checks all the other sensors? Shelly modules are configured to remain in the previous state after restart. However, if the state is OFF, it also switches to OFF and triggers the automation.

These will be changing from unknown to off (or on, depending on the last state) at start up. So all you have to do is include from: 'on' in your state trigger to ignore this.

Ok, so then I must have two automations

alias: LIGHTS - Office - Central off > on
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.shellyswitch25_8caab55fec50_channel_2
    from: "off"
    to: "on"
condition: []
action:
  - type: turn_on
    device_id: 5a08c3f570ad10919f259986a4c78376
    entity_id: light.office_central_zigbee
    domain: light
mode: single

And the way around (on>off, off>on). Yah, tiny idea but it looks like an Occam razor .)

No, wrong, one automation. The above two understandably do not turn the light on when the state of the switch is on. So then:

alias: LIGHTS - Office - Central toggle
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.shellyswitch25_8caab55fec50_channel_2
    from: "on"
    to: "off"
  - platform: state
    entity_id:
      - switch.shellyswitch25_8caab55fec50_channel_2
    from: "off"
    to: "on"
condition: []
action:
  - type: toggle
    device_id: 5a08c3f570ad10919f259986a4c78376
    entity_id: light.office_central_zigbee
    domain: light
mode: single

@tom_l I migrated from Deconz to zigbee2mqtt and found similar behavior. Right now, after every restart of Home Assitant my light in the food store lights up when the doors are open. The automation is focused on the “device” of the Aqara door sensor and it is “opened” after restart. It did not behave the same way on Deconz. The solution was to follow the state of an entity from off to on. I don’t think this is intended behavior and it seems to be similar to the one with shellies above.

Look the sensor changes after restart from open to open. Unnecessarily.