Templating help please

Hi All,

I an trying to get my head around templates and have read a bunch of threads (and the docs) on it but have not figured out exactly how to achieve what I am planning.
I was hoping to expand on the below code to include more lights going ‘unavailable’ as triggers and then have the notification tell me which one or more lights have gone ‘unavailable’. I have 5 other lights I would like to include as triggers.

notify_light_unavailable.yaml

alias: Notify if light unavailable
initial_state: 'on'
trigger:
  - platform: state
    entity_id: light.front_door_light
    to: 'unavailable'
    for:
      seconds: 5
action:
  - service: notify.Pushbullet
    data:
      message: 'The front door light has gone unavailable'

Can someone please help me out here?

Something like this should work for you

alias: Notify if light unavailable
initial_state: 'on'
trigger:
  - platform: state
    entity_id: light.front_door_light
    to: 'unavailable'
    for:
      seconds: 5
  - platform: state
    entity_id: light.back_door_light
    to: 'unavailable'
    for:
      seconds: 5
  - platform: state
    entity_id: light.kitchen_light
    to: 'unavailable'
    for:
      seconds: 5
action:
- service: notify.Pushbullet
  data_template:
    message: >-
      {% if states.light.front_door_light.state =='unavailable' %}
        "Front light is unavailable"
      {% elif states.light.back_door_light.state =='unavailable' %}
        "Back light is unavailable"
      {% elif states.light.kitchen_light.state =='unavailable' %}
        "Kitchen light is unavailable"
      {% else %}
        ":|"
      {% endif %}

You just need to substitute your entity_ids in the trigger and message template

thanks. I’ll give it a try. Since you have if / elif statements, would that still allow for the action to send multiple notifications if more than one light becomes unavailable? It seems that a few of my lights randomly do this throughout the day. Initially I created the automation so I could then provide a bit of an alarm if someone was to steal my front light globe (its a Yeelight screw globe so easy to take) but since I seem to be having a few random ‘unavailable’s’ throughout the day I figure I’ll use the notification to try and nut out the root cause first…

Take a look at this thread. It does a similar thing. In automations, you can get info regarding the trigger condition, then use that in a template:

No it wouldn’t.
You’d be much better off using the info from the link provided by @ih8gates above.

I’ve already used it to cut 100 or so lines from my auto and script files !!