How to get entity name in notifications title?
I tried different things like {{ entitiy_id }}
but it gets ignored.
Configuration in yaml view:
Greetings
How to get entity name in notifications title?
I tried different things like {{ entitiy_id }}
but it gets ignored.
Configuration in yaml view:
Greetings
Another try:
alias: Hohe Co2 Belastung
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_buro_co2
above: '1000'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_co2
above: '1000'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_schlafzimmer_co2
above: '1000'
condition: []
action:
- device_id: xxx
domain: mobile_app
type: notify
message: >
'Hohe CO2 Belastung {{ trigger.to_state.state }}
in {{ trigger.to_state.entity_id }}'
title: Hohe CO2 Belastung
mode: single
max: 10
when clicking testing nothings happens and in the server logs following error occurs:
Hohe Co2 Belastung: Error executing script. Unexpected error for device at pos 1: Error rendering message: UndefinedError: 'trigger' is undefined
Edit1: aaah i needed to change trigger.to_state to trigger.numeric_state because i’m using another platform.
Ok now i only need the nice entity_id name.
I would expect {{ state_attr(trigger.to_state.entity_id, "friendly_name") }}
to work.
alias: Hohe Co2 Belastung
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_buro_co2
above: '1000'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_co2
above: '1000'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_schlafzimmer_co2
above: '1000'
condition: []
action:
- device_id: xxx
domain: mobile_app
type: notify
title: Hohe CO2 Belastung
message: >
{{ state_attr(trigger.to_state.entity_id, "friendly_name") }}
mode: single
max: 10
Hohe Co2 Belastung: Error executing script. Unexpected error for device at pos 1: Error rendering message: UndefinedError: 'trigger' is undefined
Are you executing the automation manually? In that case there is no trigger.
It works! many thanks @robertklep
I didn’t think about it that testing wouldn’t work and assumed that i need to change the code
The working code is now
alias: Hohe Luftfeuchtigkeit
description: ''
trigger:
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_buro_humidity
above: '59'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_humidity
above: '59'
- platform: numeric_state
entity_id: sensor.netatmo_zuhause_wohnzimmer_schlafzimmer_humidity
above: '59'
condition: []
action:
- device_id: 8f5fe97d9f8f2017727b5af1f45e990b
domain: mobile_app
type: notify
title: Hohe Luftfeuchtigkeit
message: >-
{{ trigger.to_state.state }} % in Raum {{
state_attr(trigger.to_state.entity_id, "friendly_name") }}
mode: single
max: 10
I ran into the exact same problem earlier this week and it took me some time to realise that manually executing automations skips the “trigger” part, and hence, no trigger
variable will be defined
you already have the name, no need to access the state machine to get it.
trigger.to_state.attributes.friendly_name
or trigger.to_state.name