Trigger.entity_id sample

Haven’t tried trigger data yet, but with templating…maybe adding .attributes.friendly_name to the template?
Something like :

message: "Alarm tripped at {{ trigger.entity_id.attributes.friendly_name }}"

thanks. but it is not working.

It seems attributes are not passed over to data_template. A temporary workaround for me is to manipulate the string. Example…

- alias: 'Alarm tripped'
  trigger:
    - platform: state
      entity_id: sensor.front_door
      state: 'Open'
    - platform: state
      entity_id: sensor.entrance_motion
      state: 'Active'
  condition:
    - condition: state
      entity_id: alarm_control_panel.zone_a
      state: armed_away
  action:
    service: notify.notify
    data_template:
      message: "Alarm tripped at {{ trigger.entity_id|replace('sensor.', '')|replace('_', ' ') }}"
      title: ""
2 Likes

This is a pretty cool method - I see how you got your nym.

Hey,
I know it’s a bit late but I just had the exact same issue and I did it with a quick loop over all states of the domain sensor.

action:
  - service: notify.xxx
    data_template:
      title: "[Alert][Server] - "
      message: >-
        {%- for state in states.sensor if state.entity_id == trigger.entity_id -%}
          {{ state.attributes.friendly_name }} is down.
        {%- endfor -%} 
8 Likes

Nice! This might be an answer for an Alexa intent I was working on - thanks!

1 Like

Do you care to elaborate on this? I am currently working on alexa integration myself. Althogh I have to do the “Alexa” device myself as well, as it’s not available in Germany right now. But it’s always good to hear what others are doing to get some ideas :smiley:

I have an intent set up to activate scenes and another to check on the status of the front door lock.

What I’d like to do is set the manual alarm in HA, but have Alexa tell me if one or more of my sensors are currently on and if so, which ones. If all sensors are reported off, then Alexa should set the alarm in away mode and tell me I have XX amount of seconds before it’s armed.

I’m kind of hoping some of the answers I got from @aimc as well as your new piece of info will let me do this. Even just querying the state of all the sensors and returning the names of the ones that are on would be good enough for me.

Is the Alexa Voice Service available in Germany? I’ve seen a lot of DIY RasPi Echo setup tutorials. Perhaps you could roll your own?

What you trying to do should be perfectly doable. If you need any help with your setup I’d be glad to help you out. What maybe does help you is making a template sensor called something like “alexa_response”

alexa_response:
  value_template: >-
    {{ states("sensor.alexa_response") }}

You can just call a script in your intent set the state of the “sensor.alexa_response” to what you want alexa to say after the script and add that to your alexa like this

speech:
  type: plaintext
  text: >
    {{ states("sensor.alexa_response") }}

That’s how I implemented my custom kodi commands which rely on an external python script. (For playing latest episode of x or playing season y episode z of x)

The Alexa voice service is available here, at least the developer console is.
And I already have a RaspberryPi set up using the AlexaPi github repo and even added voice activation over in my fork/branch https://github.com/PhyberApex/AlexaPi/tree/voice-activated for anyone wondering.

1 Like

Thanks much! I may take you up on that.

I’m doing like 4 things at once so I think I need to re-read this post when I am in dev mode. :smiley:

I’m trying to clean house and get things sorted for a new couch being delivered and at the same time struggling with an Aeotec Multisensor 6 and trying to get it set up proper for HA. I probably should take a break…

But I’m going to come back to this - and I wanted to take the time to thank you for your guidance and your offer of help. Cheers!

1 Like

No problem! Cheers!

Dredging up an old topic! But could you clarify how you’re setting the state of a sensor? I was under the impression that they were read-only. Or are you using a command-line sensor and manipulating things that way? I’d love to find a way to store small bits of text.

wow…geezus I just now have seen that I did not answer that. Really sorry! I set the state of this sensor over the REST API from a python script. I think there really should be a way to write sensor data within HA tho.

~Cheers

This is exactly what I was looking for! I wanted my google home to welcome home whoever just came home, instead of a generic welcome home message.

alias: Home Routine
trigger:
  - platform: state
    entity_id: group.jordan
    from: not_home
    to: home
  - platform: state
    entity_id: group.lee
    from: not_home
    to: home
  - platform: state
    entity_id: group.alexia
    from: not_home
    to: home

action:
  - service: media_player.turn_off
    entity_id: media_player.living_room_home
  - service: media_player.turn_on
    entity_id: media_player.living_room_home
  - service: switch.turn_on
    entity_id: switch.thecave
  - service: cover.open_cover
    entity_id: cover.garage_door
  - delay: '00:02:00'
  - service: tts.google_say
    entity_id: media_player.living_room_home
    # data:
    #   message: "Welcome home!"
    data_template:
      message: Welcome home, {{ trigger.entity_id|replace('group.', '') }}!

I’ll test this out when I get home.

You can simplify it to this…

alias: Home Routine
trigger:
  - platform: state
    entity_id: group.jordan, group.lee, group.alexia
    from: not_home
    to: home

action:
  - service: media_player.turn_off
    entity_id: media_player.living_room_home
  - service: media_player.turn_on
    entity_id: media_player.living_room_home
  - service: switch.turn_on
    entity_id: switch.thecave
  - service: cover.open_cover
    entity_id: cover.garage_door
  - delay: '00:02:00'
  - service: tts.google_say
    entity_id: media_player.living_room_home
    # data:
    #   message: "Welcome home!"
    data_template:
      message: Welcome home, {{ trigger.to_state.attributes.friendly_name }}!
5 Likes

What was your trigger on this automation?

Sorry for taking so long to get back at you. I don’t seem to have that particular automation set up anymore so I can’t really help with that. Anything in particular you want to ask?

~Cheers

To get the friendly name of the trigger:
state_attr(trigger.entity_id, ‘friendly_name’)

2 Likes

Vey helpful. A note for future readers - this is using the data_template: rather than just data:, and for binary_sensors you need to specify that rather than sensors. I modified this to notify me (on my TV) when doors open or close, with their actual state.

alias: .notify door opened close on TV
description: ""
trigger:
  - platform: state
    entity_id:
      - binary_sensor.sensor_front_door
      - binary_sensor.garage_side_door_contact_sensor
      - binary_sensor.sensor_family_room_doors
      - binary_sensor.sensor_deck_south_doors
      - binary_sensor.sensor_deck_north_doors
      - binary_sensor.sensor_parlor_sliding_doors
      - binary_sensor.garage_door_myq_contact_sensor
      - binary_sensor.workout_room_window
      - binary_sensor.lumi_lumi_sensor_magnet_aq2_on_off
      - binary_sensor.hot_tub_cover_access_control_window_door_is_open
condition:
  - condition: not
    conditions:
      - condition: state
        entity_id: media_player.tv_family_room
        state: "off"
action:
  - service: notify.family_room_tv
    data_template:
      message: >-
        {%- for state in states.binary_sensor if state.entity_id ==
        trigger.entity_id -%}
          {{ state.attributes.friendly_name | replace(" Contact Sensor","") }} is {{state.state | replace("on","open") | replace("off", "closed")}} 
        {%- endfor -%}
mode: queued
max: 10
1 Like