Record sensor value every 5 minutes

Hello everyone,
Newbie here, the rabbit hole beckons :slight_smile:

Please help, I am stumped:

Short 'n sweet: Water Heater (WH) temperature changes infrequently. Values are only stored / recorded when the temperature does change - this plays havoc on filtering, statistics etc.
I’ve now setup a time pattern triggered template, with a new sensor which records the value every minute (will increase this time interval after testing):

template:
    trigger:
      - platform: time_pattern
        minutes: "*"
    sensor:
      - name: "Geyser Temperature Template"
        state: "{{ states('sensor.geyser_temperature') }}"
        unit_of_measurement: "°C"

Problem: it does indeed trigger every minute, I can confirm that from the data.
BUT, when the temperature stays constant for a few minutes then the template (or recorder?) only stores the state on state change - in other words it doesn’t store the value every minute (the whole reason for creating the template in the first place)…

How do I configure this template (or is it the recorder?) to record the template sensor data every minute, even if the data does not change?

This has been a frustration of mine. I.m.o. sensors like derivative are not doing what they promise because they have no means to sample entity data based on time triggers. This was worsened by optimizations to the recorder, which I understand was changed to avoid storing duplicates.

I put in a bug report/change request for sensors like derivative, but although others seem to agree that current behavior is not correct, it has not been picked up yet. On the forum, most I get is: it is documented to work this way, so it is not a bug. Regardless it does not fulfill the intended purpose.

For now, all I can think of is to introduce slight variations in the data. Maybe it can be accomplished by changing an attribute of the entity, e.g. with the sample time? It is driving me nuts that this is needed.

1 Like

@Edwin_D, check out @attixray’s post down the bottom of:

In a nutshell, each time the template is triggered the sensor value changes by a fraction, fooling HA into thinking it’s a new value which it then records…

Thanks to that post, I’ve amended my template as follows:

template:
    trigger:
      - platform: time_pattern
        minutes: "*"
    sensor:
      - name: "Geyser Temperature Template"
        state: "{{ states('sensor.sonoff_geyser_temperature')|float + (((now().second / 15) -1.5 | float) -1.5) / 1000 }}"
        unit_of_measurement: "°C"
        attributes:
         attribute: "{{ now().minute }}"