Zigbee light switch initial state

I have some annoying behavior. I have a light in my garage that’s controlled by a Zigbee switch that for some reason seems to default to on after a HA restart.

Is there some setting I’m missing?

The first thing would be to check if the device has a config option for initial state, although this is so obvious when you look at the device I would assume you already looked for this.

Second is the whole “after HA restart”, which implies the possibility that you have something turning it on (i.e., automation). You may have to look for all related items to see if there is anything tied to that and if you don’t find it then search all your YAML files for that entity ID and see where the references are (you can use Visual Code Server for that nicely).

I would strongly suspect the latter for this problem, it’s very suspect that hit happens when HA restarts. If you can’t find it no matter what you do, just try changing the entity ID of that light and restart, if it is fixed then it’s likely some automation - now if you referenced it via Device ID then it’ll be harder to find.

Thanks, I suspect also that you are correct. The Garage has a second ‘unconnected’ switch at the back door, that has an automation to toggle the Zigee light switch when pressed.

How would I stop this triggering on power up?


alias: garage internal toggle
description: ""
  - platform: device
    type: changed_states
    device_id: ed9dc42bb511ed237b8f4105a2b6bb67
    entity_id: c2976b6b0a7353cd9b1708d66aa5a403
    domain: switch
condition: []
  - service: light.toggle
    metadata: {}
    data: {}
      entity_id: light.garage_internal
mode: single

First I wouldn’t use device_id, it’s problematic in the long run. Find the actual entity and attribute you want to trigger on and use that instead.

One thing a lot of people miss is how to not control something when HA is starting up or when a device goes offline, it’s a simple condition on the automation that you say “don’t do this if the other device is unavailable or unknown” which is what happens when HA restarts, your devices are unavailable while initializing.

Something like:

condition: not
  - condition: state
    entity_id: switch.your_triggering_switch
    state: unavailable
  - condition: state
    entity_id: switch.your_triggering_switch
    state: unknown

Thanks, i’ll take a look at doing that. I have tended to use the UI to create the functions rather than code, maybe i need to bite the bullet for full functionality!

What CO_4X4 said can be done in the UI

1 Like

Exactly, it’s easier to show you the code and let you translate that into the AI than it is to post several screenshots, but for being complete, here’s the building block:


If you want to paste example code just click the three dots to the right of any section in your automation and “Edit in YAML” and paste, then “Edit in Visual Editor” to return. This allows you to take examples from here and get it into the UI easily (since the vast majority of help here is provided in YAML for clarity).