Does anyone know why this part of the UI will not trigger an automation with a button press. I have not seen a use case where it has a function. Triggering an automation with a button press is basic therefore i would think it should be streamlined.
It will only trigger when the attribute value changes. So, if you press the button once when the value of event_type isn’t “Pressed”, it will trigger. Then when you press it again the attribute value hasn’t changed, so it doesn’t trigger.
Use the State trigger without the attribute or to defined, this will cause the trigger to fire every time the button is pressed. Then use a condition to check that it’s the desired attribute value before proceeding to execute the action sequence.
That makes perfect sense now.
Regarding:
“Then use a State condition to check that it’s the desired attribute value before proceding to execute the action sequence.”
I assume you do this in the “and if” part of the automation? How would i start that? I have had issues with these physical button triggering at night with the HA restarts haha
Yes, “And If” is formally known as the Conditions block of the automation.
You actually have two options. The best option is to use a Template condition so that you know you are checking the same value that triggered the automation in the first place:
condition: template
value_template: "{{ trigger.to_state.attributes.event_type == 'Pressed' }}"
The second option would be to use a State condition:
condition: state
entity_id: event.YOUR_ENTITY
attribute: event_type
state: Pressed
The State condition will check the attributes current value, which (at least in theory) could have changed in the couple of microseconds between when the trigger fired and the condition is checked.
I don’t have any experience with those particular devices, but if you can find an example in an automation debug trace where it triggered after restart we can probably diagnose the cause.
One option that works in many cases is to assign a value for not_from in the trigger. You will need to use the trigger’s breadcrumb menu to switch over to edit it in YAML. It should look something like:
trigger: state
entity_id: event.YOUR_ENTITY
not_from:
- unknown
- unavailable
This is awesome and i apreciate the help.
Would this one work to keep them from triggering on a restart and in your opinion the best solution?:
condition: template
value_template: "{{ trigger.to_state.attributes.event_type == 'Pressed' }}"
If this is the fix, is there a way to make a helper on this so I can add for future uses?
Or should I both that one and this one in the same automation:
trigger: state
entity_id: event.YOUR_ENTITY
not_from:
- unknown
- unavailable
Below is an automation that triggered in the middle of the night during the restart. Is this what you were looking for?
{
"trace": {
"last_step": "action/0/choose/0/sequence/0",
"run_id": "b6c8ff169427611c1f1726e63f892158",
"state": "stopped",
"script_execution": "finished",
"timestamp": {
"start": "2026-01-18T07:50:43.144617+00:00",
"finish": "2026-01-18T07:50:49.512145+00:00"
},
"domain": "automation",
"item_id": "1764358678322",
"trigger": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"trace": {
"trigger/0": [
{
"path": "trigger/0",
"timestamp": "2026-01-18T07:50:43.144662+00:00",
"changed_variables": {
"this": {
"entity_id": "automation.coffer_light_switch_automation",
"state": "on",
"attributes": {
"id": "1764358678322",
"last_triggered": "2026-01-18T07:50:06.950073+00:00",
"mode": "single",
"current": 0,
"friendly_name": "Coffer Light Switch Automation"
},
"last_changed": "2026-01-17T08:03:30.905078+00:00",
"last_reported": "2026-01-18T07:50:12.797596+00:00",
"last_updated": "2026-01-18T07:50:12.797596+00:00",
"context": {
"id": "01KF81AGHX9118AAN2A2MHQH69",
"parent_id": null,
"user_id": null
}
},
"trigger": {
"id": "On Button Pressed",
"idx": "0",
"alias": null,
"platform": "state",
"entity_id": "event.coffer_light_switch_living_rm_aqara_h2_1",
"from_state": {
"entity_id": "event.coffer_light_switch_living_rm_aqara_h2_1",
"state": "unavailable",
"attributes": {
"restored": true,
"event_types": [
"initial_press"
],
"device_class": "button",
"friendly_name": "Coffer Light Switch Living Rm Aqara H2 1",
"supported_features": 0
},
"last_changed": "2026-01-18T07:50:06.938446+00:00",
"last_reported": "2026-01-18T07:50:06.938446+00:00",
"last_updated": "2026-01-18T07:50:06.938446+00:00",
"context": {
"id": "01KF81AATTYTEFCY9JAW7SEB76",
"parent_id": null,
"user_id": null
}
},
"to_state": {
"entity_id": "event.coffer_light_switch_living_rm_aqara_h2_1",
"state": "2025-12-14T15:13:13.518+00:00",
"attributes": {
"event_types": [
"initial_press"
],
"event_type": "initial_press",
"newPosition": 1,
"device_class": "button",
"friendly_name": "Coffer Light Switch Living Rm Aqara H2 1"
},
"last_changed": "2026-01-18T07:50:43.023887+00:00",
"last_reported": "2026-01-18T07:50:43.023887+00:00",
"last_updated": "2026-01-18T07:50:43.023887+00:00",
"context": {
"id": "01KF81BE2FJPVPADH8MJV3H4MN",
"parent_id": null,
"user_id": null
}
},
"for": null,
"attribute": null,
"description": "state of event.coffer_light_switch_living_rm_aqara_h2_1"
}
}
}
],
"action/0": [
{
"path": "action/0",
"timestamp": "2026-01-18T07:50:43.144846+00:00",
"changed_variables": {
"context": {
"id": "01KF81BE685CZKYDF5FEWNFF95",
"parent_id": "01KF81BE2FJPVPADH8MJV3H4MN",
"user_id": null
}
},
"result": {
"choice": 0
}
}
],
"action/0/choose/0": [
{
"path": "action/0/choose/0",
"timestamp": "2026-01-18T07:50:43.144936+00:00",
"result": {
"result": true
}
}
],
"action/0/choose/0/conditions/0": [
{
"path": "action/0/choose/0/conditions/0",
"timestamp": "2026-01-18T07:50:43.144984+00:00",
"result": {
"result": true
}
}
],
"action/0/choose/0/sequence/0": [
{
"path": "action/0/choose/0/sequence/0",
"timestamp": "2026-01-18T07:50:43.145118+00:00",
"child_id": {
"domain": "script",
"item_id": "new_script",
"run_id": "1f9750787bf4b81f57cefadc77d8903c"
},
"result": {
"params": {
"domain": "script",
"service": "new_script",
"service_data": {},
"target": {}
},
"running_script": true
}
}
]
},
"config": {
"id": "1764358678322",
"alias": "Coffer Light Switch Automation",
"description": "",
"triggers": [
{
"trigger": "state",
"entity_id": [
"event.coffer_light_switch_living_rm_aqara_h2_1"
],
"id": "On Button Pressed"
},
{
"trigger": "state",
"entity_id": [
"event.coffer_light_switch_living_rm_aqara_h2_2"
],
"id": "Raise Button Pressed"
},
{
"trigger": "state",
"entity_id": [
"event.coffer_light_switch_living_rm_aqara_h2_3"
],
"id": "Lower Button Pressed"
},
{
"trigger": "state",
"entity_id": [
"event.coffer_light_switch_living_rm_aqara_h2_4"
],
"id": "Off Button Pressed"
}
],
"conditions": [],
"actions": [
{
"choose": [
{
"conditions": [
{
"condition": "trigger",
"id": [
"On Button Pressed"
]
}
],
"sequence": [
{
"action": "script.new_script",
"metadata": {},
"data": {}
}
]
},
{
"conditions": [
{
"condition": "trigger",
"id": [
"Raise Button Pressed"
]
}
],
"sequence": [
{
"action": "script.coffer_raise",
"metadata": {},
"data": {}
}
]
},
{
"conditions": [
{
"condition": "trigger",
"id": [
"Lower Button Pressed"
]
}
],
"sequence": [
{
"action": "script.lower_coffer_lights_script",
"metadata": {},
"data": {}
}
]
},
{
"conditions": [
{
"condition": "trigger",
"id": [
"Off Button Pressed"
]
}
],
"sequence": [
{
"action": "script.turn_off_coffer_lights",
"metadata": {},
"data": {}
}
]
}
]
}
],
"mode": "single"
},
"blueprint_inputs": null,
"context": {
"id": "01KF81BE685CZKYDF5FEWNFF95",
"parent_id": "01KF81BE2FJPVPADH8MJV3H4MN",
"user_id": null
}
},
"logbookEntries": [
{
"name": "Coffer Light Switch Automation",
"message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"entity_id": "automation.coffer_light_switch_automation",
"context_id": "01KF81BE685CZKYDF5FEWNFF95",
"domain": "automation",
"when": 1768722643.1447346
},
{
"name": "On Coffer Lights Script",
"message": "started",
"entity_id": "script.on_coffer_lights_script",
"context_id": "01KF81BE685CZKYDF5FEWNFF95",
"domain": "script",
"when": 1768722643.1459045,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "script.on_coffer_lights_script",
"when": 1768722643.1460228,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_16_aqara_led_strip_t1",
"when": 1768722644.1738875,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_ceiling_light_helper",
"icon": "mdi:lightbulb-group",
"when": 1768722644.1770384,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.living_rm_light_group_helper",
"icon": "mdi:lightbulb-group",
"when": 1768722644.1803973,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_17_aqara_led_strip_t1",
"when": 1768722644.1813085,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.all_inside_light_group_helper",
"icon": "mdi:lightbulb-group",
"when": 1768722644.184362,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_20_aqara_led_strip_t1",
"when": 1768722645.2861683,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_14_aqara_led_strip_t1",
"when": 1768722645.2961571,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_13_aqara_led_strip_t1_2",
"when": 1768722645.2983403,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_15_aqara_led_strip_t1",
"when": 1768722646.3007216,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
},
{
"state": "on",
"entity_id": "light.coffer_light_9_aqara_led_strip_t1",
"when": 1768722646.3045163,
"context_event_type": "automation_triggered",
"context_domain": "automation",
"context_name": "Coffer Light Switch Automation",
"context_message": "triggered by state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_source": "state of event.coffer_light_switch_living_rm_aqara_h2_1",
"context_entity_id": "automation.coffer_light_switch_automation"
}
]
}
Your automation triggered after the restart because the state of the event is unavailable immediately upon restart, and then shortly thereafter it restores to its previous state, which for an event is the timestamp of the last occurrence. So, shortly after restarting, the state changed from unavailable to 2025-12-14T15:13:13.518+00:00. That caused your automation to trigger.
The change that will guard against that is modifying your trigger to include the not_from as Drew mentioned:
trigger: state
entity_id: event.YOUR_ENTITY
not_from:
- unknown
- unavailable
The condition is what you need to ensure your automation only continues if the event type was Pressed. You can use the template condition or the state condition for that. As Drew said, the template condition is the preferred one because it looks at the event that triggered the automation. The state condition instead looks at the event at that moment, and it’s possible (although unlikely) that the event has changed since the automation was triggered a fraction of a second ago.
Thanks.
When I use the template Condition and click on the “test” I don’t get the usual Condition Passes or condition did not pass. It does nothing. Is this expected?
The trigger variable isn’t defined until the automation is triggered. So when you test the condition manually, it’s going to error out.
If you want to test an automation that references a trigger variable, you’ll need to actually trigger it. Since you have a state trigger, you can trigger it by changing the state of that event entity in developer tools → state.
