Serialize sensor's data for easier consumption by statistic sensor

I was trying to get the statistic sensor to work for using an irregular updated cell phone data sensor. (fido) I found the statistic sensor gave false or unexpected readings so i created a template sensor that changed the cell phone data into a regular 1 minute updated template sensor which can easily be consumed by a statistic sensor. I can set the count in the statistic sensor to number of minute I need to watch as I found the max time variable often didn’t work as expected.

The two keys in doing this is changing the value of the cell phone data slightly to register a state change. I added a small decimal amount based on seconds in time. The other key is set the entity in the template sensor to time so its updated every minute and not when cell phone data is updated. If no change in the cell phone data sensor, the template sensor will use it previous state.

  - platform: template
    sensors:
      celldata:
        entity_id: sensor.time
        value_template: "{% if states('sensor.fido_1111_data_used')  == 'unknown' %}{{ states('sensor.celldata') + now().second / 100  }}{% else %}{{ (states('sensor.fido_11111_data_used')| int / 1000 )  | int + now().second / 100  }}{% endif %}"
        unit_of_measurement: 'Mb'

Are you still using this?

I’m trying to accomplish the same with a power consumption sensor but I find that if I reboot HA the data can be reset for the count attribute which is the key metric for me calculating history changes for last month, last week etc.

Do you find the same?

I just use this to record a data point every minute, even if there was no change in data or it become unknown. Restarts had little affect on the look of the graph. I don’t use this anymore since moving to lovelace.