I have a sensor set up that gets the ‘mean’ temperature of several Hue sensors around the house.
It’s working fine, but I get the following nagging error:
2019-02-22 09:45:21 ERROR (MainThread) [homeassistant.components.sensor.template] Could not render template House temperature: UndefinedError: 'mappingproxy object' has no attribute 'mean'
Anyone have any ideas how to stop the error?
This is my code:
- platform: min_max
name: "Average Indoor Temperature"
type: "mean"
# unit_of_measurement: '°C'
entity_ids:
- sensor.hall_temperature
- sensor.toilet_temperature
- sensor.ensuite_temperature
- sensor.kitchen_temperature
petro
(Petro)
February 22, 2019, 3:50pm
2
I think you are looking at the wrong min_max sensor. Do you have another one in you configuration named “House temperature”, not “Average Indoor Temperature”?
ah - I also have this which gets the mean temp:
house_temperature:
friendly_name: ‘House temperature’
value_template: ‘{{states.sensor.average_indoor_temperature.attributes.mean | round(0) }}’
unit_of_measurement: °C
I guess this code is wrong then?
I think I used the code above as this is shown in the states:
petro
(Petro)
February 22, 2019, 5:37pm
4
Martin_Granger:
mean
It looks correct to me. Have you tried the state_attr() method?
I tried:
house_temperature:
friendly_name: 'House temperature'
value_template: '"{{state_attr('sensor.average_indoor_temperature','temperature')}}"
unit_of_measurement: °C
But this didn’t return a value.
petro
(Petro)
February 22, 2019, 8:22pm
6
you have an extra quote in there, also that device doesn’t appear to have a temperature attribute
house_temperature:
friendly_name: 'House temperature'
value_template: "{{ state_attr('sensor.average_indoor_temperature','mean') }}"
unit_of_measurement: °C
My bad re extra quote - quickly typing / pasting. I’d not put mean in there though - your code is now working.
Any idea how I’d get that to round though?
petro
(Petro)
February 22, 2019, 10:02pm
8
Yeah, just add the round
house_temperature:
friendly_name: 'House temperature'
value_template: "{{ state_attr('sensor.average_indoor_temperature','mean') | float | round(0) }}"
unit_of_measurement: °C
I added the float in there to make sure we have a number.
might be a silly question, but why use an added template sensor for getting the attribute ‘mean’ , when the state of that sensor amounts to the same value?
unless of course you want it rounded.
petro
(Petro)
February 22, 2019, 10:13pm
10
didn’t even notice that… probably just wants to round it. Makes this easier
house_temperature:
friendly_name: 'House temperature'
value_template: "{{ states('sensor.average_indoor_temperature') | float | round(0) }}"
unit_of_measurement: °C
1 Like
Thanks for that - did exactly what I was after!