Use a friendly name of triggering device in automation

Hi,

Is it possible to use a friendly name of a triggering device in a automation, like one of the entitied described in trigger and use this in the action (see xxx)

alias: auto_spraak
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.ac_1b11552_1
      - switch.ac_1b11552_2
      - switch.ac_1b11552_3
      - switch.ac_1b11552_8
      - switch.ac_1b11552_10
      - switch.ac_1b11552_11
    to: "on"
condition: []
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.chromecast_huiskamer_nest
      message: hallo, irrigatie xxx start
      cache: true
      language: nl
mode: single
message: "hallo, irrigatie {{ trigger.to_state.name }} start"
1 Like

Yes! that works great!
Can i also combine this with another condition?
I tried to delete the “to on” in the trigger and add a condition in the choose part, but i cant use the used event-entity id there…

alias: auto_spraak
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.ac_1b11552_1
      - switch.ac_1b11552_2
      - switch.ac_1b11552_3
      - switch.ac_1b11552_8
      - switch.ac_1b11552_10
      - switch.ac_1b11552_11
    to: "on"
condition: []
action:
  - choose:
      - conditions: []
        sequence:
          - service: tts.google_translate_say
            data:
              entity_id: media_player.chromecast_huiskamer_nest
              message: hallo, {{ trigger.to_state.name }} start
              cache: true
              language: nl
mode: single

Yes! that works great!
Can i also combine this with another condition?
I tried to delete the “to on” in the trigger and add a condition in the choose part, but i cant use the used event-entity id there…

alias: auto_spraak
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.ac_1b11552_1
      - switch.ac_1b11552_2
      - switch.ac_1b11552_3
      - switch.ac_1b11552_8
      - switch.ac_1b11552_10
      - switch.ac_1b11552_11
    to: "on"
condition: []
action:
  - choose:
      - conditions: []
        sequence:
          - service: tts.google_translate_say
            data:
              entity_id: media_player.chromecast_huiskamer_nest
              message: hallo, {{ trigger.to_state.name }} start
              cache: true
              language: nl
mode: single

I tried this for the conditions block, but no luck

      - conditions:
          - condition: template
            value_template: state.trigger.entity_id = "on"

What are you trying to do by deleting the trigger state?

If you want a message when they turn both on and off do this:

alias: auto_spraak
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.ac_1b11552_1
      - switch.ac_1b11552_2
      - switch.ac_1b11552_3
      - switch.ac_1b11552_8
      - switch.ac_1b11552_10
      - switch.ac_1b11552_11
    to: 
condition: []
action:
  - service: tts.google_translate_say
    data:
      entity_id: media_player.chromecast_huiskamer_nest
      message: "hallo, irrigatie {{ trigger.to_state.name }} changed to {{ trigger.to_state.state }}"
      cache: true
      language: nl
mode: single

Only thing i wanted is
have one automation for on and off
the message for on for the actual event is
hallo name of the eventid starts
the message for off for the actual event
hallo name of the eventid stops

After your first responce, the on part worked well for all entities…

Now understand your solution, do not have to chekc the state at all!
it is all in the message

Thanks for the solution!
Pure for my interest, is it possible to check for the on or off state of the current event in a choose / condition part?

Sure,

      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state = 'on' }}"

cant get the last part working, checking a trigger state in a choice construct
I know, solution is already there, but this is just to learn :slight_smile:

alias: auto_spraak
description: ""
trigger:
  - platform: state
    entity_id:
      - switch.ac_1b11552_1
      - switch.ac_1b11552_2
      - switch.ac_1b11552_3
      - switch.ac_1b11552_8
      - switch.ac_1b11552_10
      - switch.ac_1b11552_11
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            #trial_1: value_template: trigger.to_state.state = "on"
            #trial_2: value_template: "{{ trigger.to_state.state = 'on' }}"
            #trial_3: value_template: trigger.to_state.state = "on"
            value_template: "{{ trigger.to_state.state = "on" }}"
        sequence:
          - service: tts.google_translate_say
            data:
              entity_id: media_player.chromecast_huiskamer_nest
              message: >-
                hallo, {{ trigger.to_state.name }} is {{ trigger.to_state.state
                }}
              cache: true
              language: nl
mode: single

That one should have worked. How are you testing it?

Manually triggering the automation skips the trigger, so there is no trigger.to_state.

by activating one of the irrigations, other words: one of the trigger entities

Grr, see that i get an error when using the right syntax you send
Message malformed: invalid template (TemplateSyntaxError: expected token ‘end of print statement’, got ‘=’) for dictionary value @ data[‘action’][0][‘choose’][0][‘conditions’][0][‘value_template’]

action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.to_state.state = 'on' }}"
        sequence:
          - service: tts.google_translate_say
            data:
              entity_id: media_player.chromecast_huiskamer_nest
              message: >-
                hallo, {{ trigger.to_state.name }} is {{ trigger.to_state.state
                }}
              cache: true
              language: nl
mode: single

found it !

must use a double == sign !

        value_template: "{{ trigger.to_state.state == 'on' }}"
1 Like

Thanks tom_l you helped and learned me a lot. My irrigation system works great and speaks when each zone goes on or off…

Well that was a rookie mistake on my part. Sorry. Glad you worked it out.