Historic value in value template

Hi All,
I have a question on historic values.
Based on a gas meter sensor which reads the meter continuously, I’m trying to create a sensor that calculates the gas usage today until now. So in the value template I would like to use the sensor value from yesterday 00:00. Any ideas how I can get this value from history?

- platform: template
  sensors:
   
    gas_today:
      value_template: "{{ states('sensor.dsmr_gas_delivered') | float    - states('sensor.dsmr_gas_delivered............') | float
      }}"

Thx,
PPee

Use a daily cycle with this, much easier:

That would give you two days btw. Today starts at 0:00.

Utility meter doesn’t work for me I have the solar power and i have the daily solar power with the sma inverter. When i use utility meter with sensor solar power i have a bigger value than with the original sensor daily solar power. I try it because i want to know the consumption of power with HEM zw095 who give me power and cumulative power but if i try to use utility meter with instant power it gibe me very very big number
But if i can keep the value of the cumultative sensor at midnight - cumultative sensor now i resolve my problem :slight_smile:

Just create an input_number to use in an automation to save the previous value at midnight (or whenever your desired time is). then you can compare the “now” value with that saved input_number value.

That’s because you can’t use a power (W) sensor with a utility meter. You need to use an energy sensor (Wh).

The utility meter will work with any accumulating quantity. Like gas consumption, water consumption, energy use etc… but not gas flow rate, water flow rate or power.

As PPee’s question was about “gas delivered” (gas consumption) the utility meter will work.

Thx all,
Yes Finity, thought about the input_number too, and also about the dsmr-integration, but I want to be more flexible. I’m now using MQTT and the midnight values of the meters are copied to a variable that is stored daily in my Synology MariaDB via recorder (to reduce storage space). I would like to use the entity values of any historic moment. My question is, is it possible to get this flexible historic/recorded value to use in a calculation with the value_template.
PPee

Found a solution in reading historic values using the SQL platform
Cheers
PPee

Could you please share the solution?

4 Likes