I have a new cheap Tuya Zigbee button connected through a Tuya hub and SmartLife. It has imported into HA and I am seeing events in Developer Tools / Events as shown here
I have not been able to access new_state and old_state in a Condition in an automation, and eventually discovered through the trace that this seems to be the entirety of the event that’s being seen in the automation. I’m only allowed one screen shot so here’s a copy/paste:
You are confusing Event triggers with event entities.
trigger: event
event_type: state_changed
Most of the times new users think they need to use an Event trigger with state_changed as the event type, they’re mistaken… and that goes double when it’s for an event entity. The whole point of event entities is to make it so people don’t have to use Event triggers for these kind of things (i.e. button presses).
This kind of “open” state_changed Event trigger is basically a poor re-creation of a states machine. But HA already has a states machine and triggers designed to monitor it for changes. So, just use a State trigger, that is what it was designed to do.
The “new state” and “old state” you see in the Event can be included as part of the trigger by using the to and from configuration variable of the State trigger. However, in most cases with event entities, it’s best to not use them. Just use a general trigger, then add conditions to check the values you are interested in.
Here’s an example of what you would do to have an automation execute actions based on a specific event_type:
triggers:
- alias: When the button press updates the state
trigger: state
entity_id: event.wireless_scene_switch_button_1
not_to:
- unavailable
not_from:
- unavailable
conditions:
- alias: Check that the new event type is "click"
condition: state
attribute: event_type
entity_id: event.wireless_scene_switch_button_1
state: click
...
Can you post an example of what you’re suggesting?
I have tried various configurations of event_data to detect a specific button event but all have failed.
Detecting any and all button events works because only one constraint, entity_id, is needed. However, when I add more constraints, to narrow it down to a specific button event, the Event Trigger no longer triggers.