anarro
(Anarro)
December 28, 2019, 9:08pm
1
Hi,
I am new to the world of automation, so be patient with me.
I am trying to send a notification if any temperature sensor has a value less than the default or preset value of my input_number.tempint entity, but I have this error in the LOGS view:
Error while executing automation automation.notificar_temperatura_interior. Error rendering template for call_service at pos 1: UndefinedError: 'trigger' is undefined
id: '1548707669979'
alias: Send Temperature Int
trigger:
- platform: template
value_template: '{{ (states.sensor.netatmo_salon_temperature.state|float ) <= (states.input_number.valor_tempint.state|float ) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_papas_temperature.state|float ) <= (states.input_number.valor_tempint.state|float ) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_dani_temperature.state|float ) <= (states.input_number.valor_tempint.state|float ) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_aina_temperature.state|float ) <= (states.input_number.valor_tempint.state|float ) }}'
condition: []
action:
- data:
message: "The temperature of sensor {{ trigger.to_state.name }} is {{ state_attr(trigger.entity_id, 'state' }}
service: notify.telegantoni
and I like add the value of the sensor too…
What am I doing wrong?
Thks!
Harry13
(George Georgas)
December 28, 2019, 9:45pm
2
Sorry I’m not great at yaml automations
Prefer node red.
From what I can see
You message statement is where your errors are
trigger.to_state.name ? does that even exist ?
Also you missing ) at the end of state_attrib()
You can’t use trigger.to_state with a template, because if the template triggers it will not give you the entity id, because there is no entity that triggered the automation.
anarro
(Anarro)
December 28, 2019, 11:33pm
4
ok, thanks @Burningstone , do you know how I can do it?
anarro
(Anarro)
December 29, 2019, 12:27am
5
I can’t believe it !!, in the end it worked for me with this automation:
- id: '1548707669979'
alias: Notify Temperature Int
trigger:
- platform: template
value_template: '{{ (states.sensor.netatmo_salon_temperature.state|float) <= (states.input_number.valor_tempint.state|float) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_papas_temperature.state|float) <= (states.input_number.valor_tempint.state|float) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_dani_temperature.state|float) <= (states.input_number.valor_tempint.state|float) }}'
- platform: template
value_template: '{{ (states.sensor.netatmo_aina_temperature.state|float) <= (states.input_number.valor_tempint.state|float) }}'
condition: []
action:
service: notify.telegantoni
data_template:
message: "Notify of sensor {{ trigger.to_state.name }} is: {{ trigger.to_state.state }}"
Thank you very much everyone!
1 Like
tom_l
December 29, 2019, 1:56am
6
What you have are valid templates, but there are better ones.
If you use this form:
value_template: "{{ states('sensor.netatmo_salon_temperature')|float <= states('input_number.valor_tempint')|float }}"
Instead of this:
value_template: '{{ states.sensor.netatmo_salon_temperature.state|float <= states.input_number.valor_tempint.state|float }}'
Your template will not generate errors when the entity is unknown or unavailable. See the warning in baby vomit yellow here: https://www.home-assistant.io/docs/configuration/templating/#states
anarro
(Anarro)
December 29, 2019, 9:03am
7
Great change! Thank you very much! @tom_l
1 Like