My overall goal is to use a derivative sensor to tell me my current rate of natural gas usage. The challenge I run into is when my furnace or hot water heater shuts off, I don’t get any updates from my gas meter until something else starts to use gas. Since the derivative helper only updates its value when the underlying data changes, my rate of use calculation stays high for longer then the use is actually happening.
Based on this similar answer, I need to set up a time triggered template sensor and calculate the derivative of a sensor that regularly “updates” even though the value doesn’t really change.
I have tried setting up such a time triggered template sensor, but the sensor doesn’t show that it updates at the scheduled interval. With this template, I can see the template sensor it creates, but it only updates when the underlying value changes, not every 5 seconds. (Once I get this working I will update less frequently, but 5 seconds is short enough that I can see (or don’t see in this case) the results.)
Am I taking the correct approach, and if so what am I doing wrong?
Here is what I am trying:
- trigger:
- platform: time_pattern
seconds: /5
sensor:
- name: "NW Natural Gas Consumption Trigger"
unique_id: "{{device_id('sensor.nw_natural_gas_consumption')}}_trigger"
state: "{{ states('sensor.nw_natural_gas_consumption') }}"
unit_of_measurement: "CCF"
device_class: "gas"
Time shown in the below screenshot is more than 5 seconds ago. I would expect that the Last Changed timestamp would be the last time the value changed, and the Last Updated timestamp would be within 5 seconds: