I’d do it this way:
template:
- trigger:
- platform: time_pattern
minutes: "/15"
sensor:
- name: "tempcan002 history"
state: "{{ states('sensor.tempcan002_temperature') }}"
attributes:
qtr0: "{{ states('sensor.tempcan002_temperature')|float(0) }}"
qtr1: "{{ this.attributes['qtr0'] }}"
qtr2: "{{ this.attributes['qtr1'] }}"
qtr3: "{{ this.attributes['qtr2'] }}"
qtr4: "{{ this.attributes['qtr3'] }}"
- sensor:
- name: "tempcan002 moins 1 heure"
state: "{{ state_attr('sensor.tempcan002_history', 'qtr4') }}"
unit_of_measurement: "°C"
device_class: temperature
availability: "{{ state_attr('sensor.tempcan002_history', 'qtr4') is number }}"
Set the time_pattern
interval to give you the temporal resolution you care about (I’ve used 15 minutes), and adjust the attributes accordingly. You could trigger every minute and have 60 attributes (like the ten in the link) but that’s probably overkill.
This will only start working at a quarter-hour (x:00, x:15, x:30, x:45): the history
sensor will be unknown
until that time.
It will then take an hour to fully populate. The moins 1 heure
sensor will be unavailable
until then.
EDIT: My test sensor (I always like to validate my responses) now it’s fully populated:
15-minute resolution vs ~2 minute on the master: