Automation on light on or off but not dim in one automation?

Hi.

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.

Thanks

Hi there, Just keep the from and to settings vacant. Then the automation will be triggered with any change of state…i,e on to off or off to on

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'
2 Likes

With that I also get a notification when the brightness turns from 25% to 50% which is what I’d like to eliminate.

DOH of course!

1 Like

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 %}
action:
  service: light.turn_{{ trigger.to_state.state }}
1 Like

I always forget to use this nifty little approach! Much better than if/elif/endif statements!!

Thanks, @m0wlheld!