I have a switch that triggers an automation. I don’t care if it i s on or off, but I want to trigger every time someone pushes the switch. Therefore, I thought to not have any state defined (e.g. from on to off). However, if I change something at the zwave interface (disable entities) all devices get “an update” and the switch triggers.
If you do not define a to: or from: for a state trigger then the automation will trigger on any change of state or attribute change of the entity. If you only want to trigger on any change of state and ignore attribute changes then use a null to: like this:
trigger:
- platform: state
entity_id: switch.your_switch_here
to:
It could also be because your switch state is changing from unknown to some state. In which case you could use this trigger:
Yes indeed, and yes that is one solution. The other is to trigger on all states and to use conditions to check that the from or to state is not unknown.
Also you don’t need to use lists of states if you only have one state:
trigger:
- platform: state
entity_id: switch.your_switch_here
from: 'on'
to: 'off'
- platform: state
entity_id: switch.your_switch_here
from: 'off'
to: 'on'
Input buttons don’t have the state on/off they only store the date they were last pressed. For this you would have to do the other method I mentioned:
trigger:
- platform: state
entity_id: input_button.your_button_here
to:
condition:
- "{{ trigger.from_state.state not in ['unknown', 'unavailable'] }}"
- "{{ trigger.to_state.state not in ['unknown', 'unavailable'] }}"
- "{{ trigger.from_state.state != trigger.to_state.state}}"