Average temperature of a TRV

I would like to get an average temperature of a TRV that has the following state attributes:

  - 'off'
  - heat
min_temp: 5
max_temp: 30
target_temp_step: 0.5
preset_modes:
  - none
  - auto
  - manual
  - holiday
current_temperature: 15.8
temperature: 17
preset_mode: manual
battery_low: false
boost_timeset_countdown: 0
child_lock: UNLOCK
comfort_temperature: 19
current_heating_setpoint: 17
eco_temperature: 17
error_status: 0
fault_alarm: 0
frost_protection: 'OFF'
heating_stop: 'OFF'
holiday_start_stop: 2021/01/01 01:01 | 2021/01/01 01:01
holiday_temperature: 17
last_seen: '2022-12-03T14:14:17+01:00'
linkquality: 25
local_temperature: 15.8
local_temperature_calibration: 0
online: 'ON'
open_window: 'OFF'
open_window_temperature: 19
preset: manual
schedule_friday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_monday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_saturday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_sunday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_thursday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_tuesday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
schedule_wednesday: 06:00/17 12:00/21 14:00/17 17:00/21 24:00/17
system_mode: heat
update:
  installed_version: unknown
  state: idle
update_available: false
working_day: mon_sun
friendly_name: Radiator
supported_features: 17

I’m trying to get an average temperature from that sensor, but can’t get it to work with either the statistics or the history_stat platform. Since it’s state is heat I’m getting an unknow in the statistics platform and can’t figure out how the single out the state attribute in that platform. The history_stat platform isn’t suitable for this since it’s used for counting the time of a certain state.

What I’m trying to achieve is to get a weekly or monthly average of my TRV temperature and of my Aquara sensor, the difference between the two will my “local_temperature_calibration”-value in the TRV.

Feed the sensor created by this to the statistics sensor (not the history stats sensor).

template:
  - sensor:
      - name: TRV Current Temperature
        unit_of_measurement: "°C"
        device_class: temperature
        state_class: measurement # only include this line if you want long term statistics
        state: "{{ state_attr('climate.your_trv_entity_here', 'current_temperature') }}"
        availability: "{{ state_attr('climate.your_trv_entity_here', 'current_temperature')|is_number }}"
1 Like

Thanks for the help, I’ve used a different approach. I’ve used the GitHub - Limych/ha-average: Average Sensor for Home Assistant to calculate an average over 30 days:

- platform: average
  name: 'Average TRV temp'
  end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  duration:
    days: 30
  entities:
    - climate.trv

- platform: average
  name: 'Average Aquara temp'
  end: '{{ now().replace(hour=0).replace(minute=0).replace(second=0) }}'
  duration:
    days: 30
  entities:
    - sensor.aquara

Then a sensor to calculate the difference between the two.

- sensor: 
    - name: "Difference TRV and Aquara"
      unique_id: differnce_trv_aquara
      unit_of_measurement: "°C"
      state: >
        {% set trv = states('sensor.average_trv_temp') | float(0) %}
        {% set aquara = states('sensor.average_aquara_temp') | float(0) %}
        {{ (trv - aquara) | float(0) | round(1) }}

If someone is using this as an example, please be aware that I’ve split my config (the average sensors belong to the sensor-domain and the difference sensor belongs to the template-domain).