I want to configure an automation that when a light turns on or turns off it will send a notification. I can easily do this with two automations by setting the trigger “from” and “to”. However is it possible to do this in one automation?
When I trigger on just the light the automation also triggers if the dimming level of the light changes and I don’t want that.
Also ‘unavailable’, None and anything in between. I recommend enumerating all the wanted transitions as triggers
trigger:
- platform: state
entity_id: light.my_light_to_observe
from: 'on'
to: 'off'
- platform: state
entity_id: light.my_light_to_observe
from: 'off'
to: 'on'
And then use templates in the action section to send the right message. For example:
action:
- service: > # May not need this... it may be the same service...
{% if trigger.to_state.state == 'on' %} call_this_service
{% elif trigger.to_state.state == 'off' %} call_this_service_instead
{% endif %}
data:
message: > # Specify the message based on the `to_state` value
{% if trigger.to_state.state == 'on' %} The light turned ON!
{% elif trigger.to_state.state == 'off' %} The light turned OFF
{% endif %}