I’m using this solution widely where I trigger on an event (or in my case often many) and then in a choose look at the event_type.
On a restart (or, for example, restarting the zwave integration), I get events fired. I assume that is so that listeners could update the state at startup. The result is things get turned on that should not have been – the scene controller button wasn’t pushed.
The trigger data has this from_state that includes restored: true. I couldn’t find docs on that, but I assume that I can check that in a condition to test if the event is from a restart and not an actual button pushed on a scene controller.
Is there a question here? Why did you post this as a separate thread rather than a reply in whatever thread you’re referring to?
It is not a trigger, it is a trigger variable which he has copied from traces. Or at least that is what I would expect, considering what it looks like…
Post the trigger you’re using, exactly the way it appears in your automation. Also, what is producing event.bar_ceiling_light_scene_001? I assume it is z-wave?
I posted it there because it was a follow up to a response to how to avoid device ids where an entity doesn’t have a state change to use - like a scene controller.
At that time I received a response showing how to use event ids. But that response didn’t handle the situation of restarts generated events, which is important (preventing unexpected running of devices, for example).
I was surprised too. Seems odd an event would fire on restart as (in this usage) could run automations when a button wasn’t actually pushed. Could it be related to the z-wave integration?
(I also looked at the zwave-js logs and didn’t see the event starting there. I’ll poke at it more today.)
It’s just triggering on the event entity ids (like in the post @TheFes I linked to). The trigger output I posted was for entity_id: event.bar_ceiling_light_scene_001, and in that specific automation the trigger is this:
And from that trigger data you can see that there’s that restored: true attribute. I wasn’t able to find documentation on that, so just assumed it’s there for cases like this.
Here’s a similar example, but of a less involved automation.
Thanks. I’ll have time to test in a few hours. Looks like it would work from the trigger data I posted above.
I was hesitant to use the state since the events can fire without any state change. I need to learn more about initial states at startup, or when restarting an integration.
Do you, by chance, happen to know any details on the restored attribute and/or why these events apparently fire at startup?
My initial post (the one linked to) was based on my experience with ESPHome events, where events entities are not restored after a restart.
I know that for Zigbee2MQTT events, the events do restore, and thus will cause a trigger if you use something like the linked post. This is because the state will change from unavailable to the valid previous state.
I don’t have any Zwave devices, so I can’t tell anything about that.
Adding a not_from: unavailable will prevent that. The part from the trace you shared clearly shows the from state was unavailable.
My automation’s State Trigger employs not_from: unavailable and prevents it from firing on startup because, on startup, the event entity’s state value undergoes a state-change from unavailable to whatever value it had prior to the restart.