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?
Thanks
Paul
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?
Thanks
Paul
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?
Cheers
Paul
alias: garage internal toggle
description: ""
trigger:
- platform: device
type: changed_states
device_id: ed9dc42bb511ed237b8f4105a2b6bb67
entity_id: c2976b6b0a7353cd9b1708d66aa5a403
domain: switch
condition: []
action:
- service: light.toggle
metadata: {}
data: {}
target:
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
conditions:
- 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
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).
So I never solved this. This is my code, what am I doing wrong?
alias: garage internal toggle
description: ""
mode: single
triggers:
- type: changed_states
device_id: ed9dc42bb511ed237b8f4105a2b6bb67
entity_id: switch.garage_rear_internal
domain: switch
trigger: device
conditions:
- condition: not
conditions:
- condition: state
entity_id: light.garage_internal
state: unavailable
- condition: state
entity_id: light.garage_internal
state: unknown
actions:
- metadata: {}
data: {}
target:
entity_id: light.garage_internal
action: light.toggle
You’re triggering on Every state change. That’s your first error. You need to trigger only when the switch goes from off to on and vice versa.
Your second error is that you’re checking the unwanted states in the conditions. This means that nothing will trigger when your switch goes from on/off to unavailable/unknown.
This is fine but it doesn’t cater for the opposite scenario. If your switch goes from unavailable/unknown to on/off, your automation will still trigger.
Your third error is that you’re calling a light toggle in your actions. This assumes your garage switch and your light states are in sync. It’s not a problem if your garage switch is momentary, but if not, you might run into situations where they’re out of sync.
Ok thanks, I get the first one, but that wasn’t what I selected.
I created in the GUI and the first option was as you can see below.
I can change to an off to on state.
For the second error I don’t understand, can you please explain more?
For the third, i think it needs to be this way. There is a switch at the front that connected to the light. The rear switch is unconnected, so each time its pressed, whatever state its in it needs to toggle the light precisely because you don’t know the state. It works functionally in the garage fine, the issue is just the power on behavior.
Blockquote
You’re VERY lucky I saw your post. You replied to yourself instead of replying to me, so I wasn’t notified.
Let’s start with the basics. Go to your Automation > Hit the 3 dots in the top right corner > Edit as Yaml > Copy everything, then paste your automation here, correctly formatted please.
I can already tell by your screenshot that you’re using device triggers instead of entity triggers, which isn’t ideal. So, send me also the name of the entity of the switch taken from the Developer tools.
For the second issue, we can tackle it later. We probably won’t have to if you post your automation, so we’ll cross that bridge when we get to it.
Thank you. I decided to start again, no conditions yet but this is where I started.
It functions correctly when I push the button, its just every time HA starts up it turns the light on.
description: ""
triggers:
- trigger: state
entity_id:
- switch.garage_rear_internal
to: "on"
- trigger: state
entity_id:
- switch.garage_rear_internal
to: "off"
conditions: []
actions:
- action: light.toggle
metadata: {}
data: {}
target:
entity_id: light.garage_internal
mode: single
`type or paste code here`
Replace your triggers with this. I freehanded this on mobile while eating, but indentation should be good
triggers:
- trigger: state
entity_id:
- switch.garage_rear_internal
to: "on"
from: "off"
- trigger: state
entity_id:
- switch.garage_rear_internal
to: "off"
from: "on"
Oh thats great, many thanks. I can see how that solves the issue.
cheers
Paul