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'