The value will be reset (to the current value) every time some trigger happens. One trigger will happen when a value is higher than the last max or at midnight (regardless the value).
So, this sensor won’t work until the midnight happens for the first time. You probably can set an initial value manually on Developer Tools > States, otherwise just wait for next midnight and it will work.
Sure! But then you probably will prefer using a template trigger instead of a time trigger. Something like this:
- platform: template
value_template: '{{ now().day == 1 and now().hour == 0 and now().minute == 0 and now().second == 0 }}'
Try this:
- platform: template
value_template: '{{ now().month == 1 and now().day == 1 and now().hour == 0 and now().minute == 0 and now().second == 0 }}'
So the full code will look like this:
template:
- trigger:
- platform: template
value_template: '{{ now().month == 1 and now().day == 1 and now().hour == 0 and now().minute == 0 and now().second == 0 }}'
- platform: template
value_template: "{{ states('sensor.home_average_temperature') > states('sensor.home_yearly_max_average_temperature') }}"
sensor:
- name: Home - Yearly max average temperature
unique_id: home_yearly_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: template
value_template: '{{ now().month == 1 and now().day == 1 and now().hour == 0 and now().minute == 0 and now().second == 0 }}'
- platform: template
value_template: "{{ states('sensor.home_average_temperature') < states('sensor.home_yearly_min_average_temperature') }}"
sensor:
- name: Home - Yearly min average temperature
unique_id: home_yearly_min_average_temperature
unit_of_measurement: "°C"
device_class: temperature
icon: mdi:thermometer-chevron-down
state: "{{ states('sensor.home_average_temperature')}}"
attributes:
datetime: "{{ now() }}"
In both cases you probably should set the initial value manually (Developer Tools > States) otherwise you will have to wait for a new month/year to start getting this working.