Handle with an Array in Automations

Hello, when I have an array with light1 and light2 and when I have a state change in my automation, I want to send a message to my mobile phone which light changed the state. I dont know how to handle with the array at “target” and “data” area (see entity_id: switch. and message: “<LIGHT 1 OR LIGHT2> blub”)

trigger:
  - platform: state
    entity_id: [switch.light1, switch.light2]
    from: "off"
    to: "on"
action:
  - service: [ .... ]
    target:
      entity_id: switch.<WHICH LIGHT GOES ON OR OFF>
  - service: notify.mobile
    data:
      message: "<LIGHT 1 OR LIGHT2> blub"

I am new at yaml topic sorry for my question :-/

Use trigger variables:


  - service: …
    target:
      entity_id: "{{ trigger.entity_id }}"
  - service: notify.…
    data:
      message: "{{ trigger.to_state.name }}"

{{ trigger.entity_id }} = the entity which triggered your automation
{{ trigger.to_state.name }} = the frontend name of the entity that triggered your automation, entity’s state changed to on = to_state

Thanks and sorry I really dont understand what you mean :-S

I dont want that every switch in my HA trigers the automation only some special switches…

How will my automation then look like with switch.light1 & switch.light2?

What makes you think that every switch triggers this automation?

The automation gets triggered by the switches you defined as trigger.

Sorry my mistake :slight_smile: I misunderstand there something. Thanks the initial post resolv my problem :slight_smile:

No worries :slight_smile: