How can I convert reed sensor impulses to cubic meters and kWh for my gasmeter?

I have a vzlogger instance running that posts my gas meters impulses to HA. I am somehow lost now how to convert these impulses to m3 and kwh and how to use the values also as utility meter for the energy dashboard.

pi@rpi-vzlogger:~ $ cat /var/log/vzlogger.log | grep chn2
[Apr 28 07:29:56][chn2] New channel initialized (uuid=...f68014 api=volkszaehler id=Impulse)
[Apr 28 07:30:07][chn2] Adding reading to queue (value=1.00 ts=1651123807015)
[Apr 28 07:31:51][chn2] Adding reading to queue (value=1.00 ts=1651123911626)
[Apr 28 07:32:51][chn2] New channel initialized (uuid=...f68014 api=volkszaehler id=Impulse)
[Apr 28 07:33:01][chn2] Adding reading to queue (value=1.00 ts=1651123981001)
[Apr 28 07:34:12][chn2] Adding reading to queue (value=1.00 ts=1651124052494)
[Apr 28 07:35:24][chn2] Adding reading to queue (value=1.00 ts=1651124123924)

mqtt.yaml:

- platform: mqtt
  name: "Gas Meter"
  state_topic: "vzlogger/data/chn2/raw"

Thanks for helping :slight_smile:

You have to know what the pulses are measuring, ie how many m3 does a pulse represent?

I think it is 1000 per m3

I now managed with force_update to store the new value, even if it always sends a 1.
I am still struggling how to make sense from this:

  • how can I now derive gas consumption from this, e.g. convert to kWh
  • how can I add the counts to a variable that holds my initial gas meter reading in m3

Thanks.

I answer myself with the solution:

You need a counter:

counter:
  gas:
    initial: 794509
    step: 1

If your HA value and the actual counter value are different, just increment/decrement the value using the UI or the services menu until it is fine.

You also need an automation:

- id: '1651387933493'
  alias: Increment Gas Counter
  description: ''
  trigger:
  - platform: mqtt
    topic: vzlogger/data/chn2/raw
  condition: []
  action:
  - service: counter.increment
    data: {}
    target:
      entity_id: counter.gas
  mode: single

Note: if you want to have an entity in your HA that shows the last update of the MQTT sensor, add this, including the force_update:

- platform: mqtt # not needed, just for displaying in the ui
  name: "gas_impulse"
  state_topic: "vzlogger/data/chn2/raw"
  value_template: "{{ value_json.value | round(0) }}"
  force_update: true

Now you can derive the needed values from the counter. The conversion factor from m3 to kWh can be found on your gas bill.

  - sensor:
      - name: "Gaszähler"
        unique_id: gaszaehler_m3
        state: "{{ states ('counter.gas') | float * 0.01 }}"
        unit_of_measurement: "m³"
        icon: "mdi:gas-station"
        device_class: gas
        state_class: total_increasing
  - sensor:
      - name: "Gaszähler kWh"
        unique_id: gaszaehler_kwh
        state: "{{ (states ('sensor.gaszahler') | float(0) * 0.9355 * 11.272) | round(3) }}"
        unit_of_measurement: "kWh"
        icon: "mdi:gas-station"
        device_class: gas
        state_class: total_increasing

The m3 entity can also be added to the Energy Dashboard.

From a documentation perspective, this could be improved in the official docs. I have no idea how, if I have an idea, I’ll file a PR :wink:

And if you want to have daily / monthly energy counts as well, a utility meter sensor can come in handy: