Utility Meter Correct Configuration

I want to track how much m3 of gas I consume on heating. I have my heating system connected to a switch, and I have set up a generic thermostat. When heating it consumes 1 m3 per hour.

I set up a utility meter to track consumption but I don’t think is behaving the way I intended. It just adds 1 m3 every time it goes from idle to heating, instead of tracking minutes heating. I made a sensor that returns 1 when the switch is on, and 0 when off, and a utility meter to read that sensor.

Did I get something wrong?

This is my configuration:

    source: sensor.calefaccion_central_calentando
    cycle: daily
    source: sensor.calefaccion_central_calentando
    cycle: monthly
  - platform: template
        friendly_name: Calentando
        unit_of_measurement: 'm3'
        value_template: "{% if states('switch.0x00158d000427fce2_switch_l1') =='on' %}1{% else %}0{% endif %}"

You need the integration sensor, the utility meter doesn’t do any integration by itself.

Thanks a lot,

I was able to do it and came across the derivative sensor as well.
Even thougth with the default configuration it works ok, when I change the value of ‘unit_time’ it gives numbers that I don’t understand, for instance, for this sensor (the derivative of temperature):

  - platform: derivative
    source: sensor.0x00158d00046575ed_temperature
    name: variacion_temperatura_segundo
    round: 2
    unit_time: 'min'

I was expecting to have values in the range of 0.1 C/m, but instead I get a reading of 300. Luckily, it’s a mistake.

I’m pretty sure I’m not getting how this works.

Thanks for your help

I think you should add a time window like in the documentation example.