How to make an Average Sensor from other Sensor Attributes?

I’m trying to make an average sensor of three other Sensors using their attributes, I cant get this to work.

Any assistance would be great:

These are the sensors and the attributes:

{{ state_attr('climate.downstairs_heating_local' , 'current_temperature')|float(0) }}

{{ state_attr('climate.upstairs_heating_local' , 'current_temperature')|float(0) }}

{{ state_attr('climate.kitchen_ufh_local' , 'current_temperature')|float(0) }}

I tried this but not working:

{{ state_attr('climate.downstairs_heating_local' , 'current_temperature') + state_attr('climate.upstairs_heating_local' , 'current_temperature') + state_attr('climate.kitchen_ufh_local' , 'current_temperature')
        | rejectattr('current_temperature', 'in', ['unavailable', 'unknown', '0.0'])
        | map(attribute='current_temperature') | map('float') | average | round(2, 0) }} 

I have other Average Sensors working but they are without any attributes:

template:
  sensor:
    - name: "House Avg Temperature"
      unit_of_measurement: "°C"
      device_class: temperature
      state_class: measurement
      unique_id: house_avg_temperature
      state: >
        {{ expand('sensor.luminance_sensor_1_temperature','sensor.luminance_sensor_2_temperature','sensor.luminance_sensor_3_temperature','sensor.luminance_sensor_4_temperature','sensor.luminance_sensor_5_temperature','sensor.luminance_sensor_6_temperature','sensor.t_h_sensor_2_temperature','sensor.luminance_sensor_8_temperature')
        | rejectattr('state', 'in', ['unavailable', 'unknown', '0.0'])
        | map(attribute='state') | map('float') | average | round(2, 0) }}

Try this:

{{ ['climate.downstairs_heating_local', 'climate.upstairs_heating_local', 'climate.kitchen_ufh_local'] | map('state_attr', 'current_temperature') | select('is_number') | average | round(2) }}
1 Like