I don’t like this combination of an automation setting a helper, so rather than this I would try a trigger based template sensor.
Something like this (not tested):
template:
- trigger:
- platform: time
at: "00:00:00"
- platform: template
value_template: "{{ states('sensor.home_average_temperature') > states('sensor.home_todays_max_average_temperature') }}"
sensor:
- name: Home - Todays max average temperature
unique_id: home_todays_max_average_temperature
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer-chevron-up
state: "{{ states('sensor.home_average_temperature')}}"
attributes:
datetime: "{{ now() }}"
- trigger:
- platform: time
at: "00:00:00"
- platform: template
value_template: "{{ states('sensor.home_average_temperature') < states('sensor.home_todays_min_average_temperature') }}"
sensor:
- name: Home - Todays min average temperature
unique_id: home_todays_min_average_temperature
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer-chevron-down
state: "{{ states('sensor.home_average_temperature')}}"
attributes:
datetime: "{{ now() }}"
I think it looks more elegant and it’s much easier to maintain. And it will be easy to replicate for annually/monthly/weekly/hourly sensors as you might want.
You can use the same triggers used on the automations suggested in this thread, if you wanna improve the one from my example.
Edit on 2023-01-12 18:41UTC: Replaced the template trigger used to detect a new day by a time patter to trigger at midnight. My intention is to reduce chance of errors and probably reduce CPU consumption a bit.