ashscott
(Ash)
1
I’m trying to set up a notification based on rising temperature, but keep getting this error:
Error during template condition: UndefinedError: ‘mappingproxy object’ has no attribute ‘temperature’
My automation looks like this:
- alias: 'Notify when sauna is up to temperature'
trigger:
platform: template
value_template: "{% if states.sensor.sauna_temperature.attributes.Temperature > 24 %}true{% endif %}"
action:
service: notify.prowl
data_template:
title: "Spa Sauna"
message: "Up to temperature"
The console output from my Sonoff gives this:
21:28:37 MQT: tele/sauna/SENSOR = {“Time”:“2018-10-05T21:28:37”,“DS18B20”:{“Temperature”:25.6},“TempUnit”:“C”}
Any help would be much appreciated.
tom_l
2
Try using a lower-case ‘t’ in temperature. HA is case sensitive and all entity ids and attributes are lower case.
Also the attribute is a string. Cast it as a floating point number or integer.
- alias: 'Notify when sauna is up to temperature'
trigger:
platform: template
value_template: "{% if states.sensor.sauna_temperature.attributes.temperature | float > 24 %}true{% endif %}"
action:
service: notify.prowl
data_template:
title: "Spa Sauna"
message: "Up to temperature"
tom_l
3
Or you might just be able to use this:
- alias: 'Notify when sauna is up to temperature'
trigger:
platform: numeric_state
entity_id: sensor.sauna_temperature
above: 24
action:
service: notify.prowl
data_template:
title: "Spa Sauna"
message: "Up to temperature"
It depends how your sensor is set up.
1 Like
ashscott
(Ash)
4
Thank you so much for taking the time to reply.
My sensor is set up thus:
#### Sauna temperature ###
- platform: mqtt
name: "Sauna Temperature"
state_topic: "tele/sauna/SENSOR"
value_template: "{{ value_json['DS18B20'].Temperature }}"
unit_of_measurement: "°C"
You said “It depends how your sensor is set up.”
Does this make a difference in the examples you gave?
How is a sensor defined as float, integer or string?
35 years ago I used to dabble with C and am just getting back to coding now, so help is invaluable!
tom_l
5
In that case the second option (without the template) that I posted should work.
State values are always strings. To cast them as another type use the pipe symbol.
e.g.
{{ states.sensor.sauna_temperature.state | float }}
{{ states.sensor.sauna_temperature.state | int }}
ashscott
(Ash)
6
Brilliant. That worked.
Thank you so much for your help.
I appreciate it.