Mappingproxy object has no attribute 'mean'

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'
    - sensor.hall_temperature
    - sensor.toilet_temperature
    - sensor.ensuite_temperature
    - sensor.kitchen_temperature

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:

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:

It looks correct to me. Have you tried the state_attr() method?

I tried:

  friendly_name: 'House temperature'
  value_template: '"{{state_attr('sensor.average_indoor_temperature','temperature')}}"
  unit_of_measurement: °C

But this didn’t return a value.

you have an extra quote in there, also that device doesn’t appear to have a temperature attribute

  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?

Yeah, just add the round

  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.

:man_shrugging: didn’t even notice that… probably just wants to round it. Makes this easier

  friendly_name: 'House temperature'
  value_template: "{{ states('sensor.average_indoor_temperature') | float | round(0) }}"
  unit_of_measurement: °C
1 Like

lol. exactly :wink:

1 Like

Thanks for that - did exactly what I was after!