Gasflow P1-meter with derivative

Just FYI
I was looking for a way to visualize my gasflow.
Energy dashboard is one option, but if you want your data to i.e. InfluxDB and create some graphs with Grafana, this was not an option.

So here my config. It’s a single yaml-file in folder packages, so everything is nicely tied together.
My comments are in Dutch, so use google translate to understand the gibberish :slight_smile:

template:
  - sensor:
      # ----------------------------------------------------------------------
      # P1 meter: meterstand in kWh
      # ----------------------------------------------------------------------
      # Legacy sensor.
      # Rekent de m3 om naar kWh
      # Beter: eerst een virtuele sensor definieren, en daar de omrekening doen. Zie ook hieronder
      - name: "P1 meter Total Gas kWh"
        unique_id: "sensor.p1_meter_total_gas_kwh"
        icon: mdi:gas-cylinder
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {% if ( states('sensor.p1_meter_total_gas') not in ['unknown', 'unavailable', 'None'] ) %}
            {% set gasm3 = states('sensor.p1_meter_total_gas') | float %}
            {{ (gasm3  * 10.2346) | round(3, default=0) }}
          {% else %}
            {{ "0" | float }}
          {% endif %}


      # ----------------------------------------------------------------------
      # gasmeter: meterstand in m3
      # ----------------------------------------------------------------------
      # Virtuele sensor:
      # Om continuiteit te garanderen van de sensor: definieer een eigen virtuele sensor op basis van een fysieke sensor.
      # Als de fysieke sensor ooit vervangen moet worden, kan je de nieuwe sensor koppelen aan dezelfde virtuele sensor,
      # zo blijven de tellingen doorlopen en blijf je long-term statistieken behouden.
      # Verder kan je zo ook garanderen dat er altijd een waarde is ("0"), zelfs als de fysieke sensor niet beschikbaar is.
      - name: "gasmeter Total Gas"
        unique_id: "sensor.gasmeter_total_gas"
        icon: mdi:gas-cylinder
        unit_of_measurement: "m3"
        device_class: energy
        state_class: total_increasing
        state: >
          {% if ( states('sensor.p1_meter_total_gas') not in ['unknown', 'unavailable', 'None'] ) %}
            {{ states('sensor.p1_meter_total_gas') | float  | round(3, default=0) }}
          {% else %}
            {{ "0" | float }}
          {% endif %}
        availability: >
          {% if ( states('sensor.p1_meter_total_gas') not in ['unknown', 'unavailable', 'None'] ) %}
            {{ true }}
          {% else %}
            {{ states('sensor.p1_meter_total_gas')  }}
          {% endif %}



      # ----------------------------------------------------------------------
      # gasmeter: meterstand, omgerekend naar kWh
      # ----------------------------------------------------------------------
      - name: "gasmeter Total Gas kWh"
        unique_id: "sensor.gasmeter_total_gas_kwh"
        icon: mdi:gas-cylinder
        unit_of_measurement: "kWh"
        device_class: energy
        state_class: total_increasing
        state: >
          {{ (states('sensor.gasmeter_total_gas') | float  * 10.2346) | round(3, default=0) }}

      # ----------------------------------------------------------------------
      # gasmeter: meterstand, omgerekend naar Wh
      # ----------------------------------------------------------------------
      - name: "gasmeter Total Gas Wh"
        unique_id: "sensor.gasmeter_total_gas_wh"
        icon: mdi:gas-cylinder
        unit_of_measurement: "Wh"
        device_class: energy
        state_class: total_increasing
        state: >
          {{ (states('sensor.gasmeter_total_gas') | float  * 10.2346 * 1000.0) | round(0, default=0) }}



sensor:
      # ----------------------------------------------------------------------
      # gasmeter: momentaan gasverbruik in m3/h
      # ----------------------------------------------------------------------
      - name: "gasmeter Total Gas Flow"
        platform: derivative
        source: sensor.gasmeter_total_gas
        unit_time: h
        time_window: "00:10:00"  # we look at the change over the last half hour

      # ----------------------------------------------------------------------
      # gasmeter: momentaan gasverbruik in kW
      # ----------------------------------------------------------------------
      - name: "gasmeter Total Gas Flow kW"
        platform: derivative
        source: sensor.gasmeter_total_gas_kwh
        unit_time: h
        time_window: "00:10:00"

      # ----------------------------------------------------------------------
      # gasmeter: momentaan gasverbruik in W
      # ----------------------------------------------------------------------
      - name: "gasmeter Total Gas Flow W"
        platform: derivative
        source: sensor.gasmeter_total_gas_wh
        unit_time: h
        time_window: "00:10:00"

Finally, this results in

  • green line: my gasflow, based on a derivative of my gasmeter (m3) and transformed to W
  • orange: my gasboiler modulation

As you can see: around 10:15, I turned on my heating. Gasboiler started a 100% which means an equivalent of instant power consumption of +/- 30.000 Watt. This is conform the documentation of my boiler ( Buderus Logamax plus GB192iT40S 30kW)

Any kind of comment is appreciated.

Kind regards
Bart Plessers

1 Like

Hi Bart,

This looks great and is exactly what I’m looking for. I now use a power meter on my ‘CV’ (central heating system) to see when it’s on but that only give a very rough idea.

I’m relatively new to HA so could you please give me some pointers on how I could add your code to my setup.

I’ve recently added a ZHA quirk so I know how to create and edit files and create new directories etc. but I’ve no idea where I should put your code.

Tia! Eduard.

Hi @Conservator ,

My global config file looks something like:

# ===============================================
# GLOBAL CONFIG FILE
# ===============================================
homeassistant:

  # Name of the location where Home Assistant is running
  name: PvO4

  # Location required to calculate the time the sun rises and sets
  latitude: xx.xxxxxx
  longitude: yy.yyyyyy

  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: zz

  # metric for Metric, imperial for Imperial
  unit_system: metric

  # country
  country: BE

  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Brussels

  # Customization file
  customize: !include customize.yaml

  # zie https://community.home-assistant.io/t/please-help-automation-for-ikea-tradfri-remote-control-e1524-e1810/142707/2
  packages: !include_dir_named my_packages

# Show links to resources in log and frontend
#introduction:

default_config:

As you can see, I made a reference to a custom directory
packages: !include_dir_named my_packages

So I created this directory:

and placed my *.yaml file in it, containing my custom config:

After restarting homeassistant, the whole contents of the directory is loaded

grtz
B

Hi Bart,

Thank you very much for your comprehensive answer. I’ll give it a try tomorrow (provided I can find the time). I’ll keep you posted. I’m looking forward to implementing this. Tx again!

Eduard aka Conservator.

Hi Bart,

I managed to add your package to my HA but I didn’t get the results expected. I suspect that the mapping from my meter to home assistant isn’t correct. It seems that ‘gas_meter_gasverbruik’ is showing the totals and ‘gasmeter_total_gas’ is unavailable.

So your package is working like it should (as far as I can see) and I’ll have to dig into my gas meter integration so that’s my next step.

I’ll keep you posted. Eduard