Calculate gas consumption for heating

I would like to measure how much gas is used when my underfloor heating is turned on. This is switched with a smart plug when my Tado has a heating request above 3% and switched off when the heating request is below 1%.

I asked ChatGPT how to do this and they came up with the following result:

*To set the start number of your P1 meter for monitoring gas consumption when the smart plug of your underfloor heating switches on and off, you can follow the steps below in Home Assistant:

Step 1: Ensure the correct setup

  1. P1 meter: Ensure that your P1 meter is set up correctly and that your Home Assistant can read the data.

  2. Smart Plug: Ensure that your smart plug of the underfloor heating is also properly integrated in Home Assistant.

Step 2: Set Input Numbers

Create two input numbers in your configuration.yaml or via the Home Assistant UI to store the start and end number.

input_number:
  start_getal:
    name: Start vloerverwarming aan
    min: 0
    max: 100000
    step: 1

  eind_getal:
    name: Stop vloerverwarming aan
    min: 0
    max: 100000
    step: 1

Step 3: Set up automations

Create two automations: one to store the start number when the smart plug turns on, and one to store the end number when the smart plug turns off.

Automation for the start number

automation:
- alias: 'Gas vloerverwarming Start'
trigger:
platform: state
entity_id: switch.vloerverwarming
to: 'on'
action:
- service: input_number.set_value
target:
entity_id: input_number.start_getal
data:
value: "{{ states('sensor.gas_meter_gas') }}"

Automation for the end number

- alias: 'Gas vloerverwarming Stop'
trigger:
platform: state
entity_id: switch.vloerpompen
to: 'off'
action:
- service: input_number.set_value
target:
entity_id: input_number.eind_getal
data:
value: "{{ states('sensor.gas_meter_gas') }}"

Step 4: Calculate the consumption

You can add a template sensor to calculate consumption based on the stored start and end numbers.

template:
- sensor:
- name: "Gasverbruik Vloerverwarming"
unit_of_measurement: "m³"
state: >
{% set start = states('input_number.start_getal') | float %}
{% set end = states('input_number.eind_getal') | float %}
{% setverbruik_kwh = (end - start) %}
{% setverbruik_m3 = (verbruik_kwh * 3.6) / 31.65 %}
{{verbruik_m3 }}

Step 5: Testing and monitoring

  1. Switch the underfloor heating on and off to check if the start and end numbers are stored correctly.

  2. Check the value of the sensor “Gas Consumption Underfloor Heating” to see how much gas has been used.

Tips

  • Make sure your Home Assistant is configured correctly and that all sensors are functioning correctly.
  • Monitor the automations to make sure they are activated at the right time.
  • Adjust the max value of the input numbers if you think you can use more than 10,000 kWh.

This should help you monitor the gas consumption of your underfloor heating!*

I have done everything as prescribed but in the automation I am running into a problem and I get an error message.


Does anyone have any idea whether the proposed method is the correct one and why I get the error message in the automations.
It has something to do with this line “Waarde”:
value: “{{ states(‘sensor.gas_meter_gas’) }}” because I can actually only enter numbers in data but those numbers have to be taken from my P1 meter “sensor.gas_meter_gas”.

Thanks.

#1 Don’t waste your time asking ChatGPT
#2 The solution it’s describing doesn’t really make any sense to me.
#3 You haven’t really provided much info on your setup. What data do you have to work with? It sounds like you have data on your total gas usage and a smart plug controlling your underfloor heating. What else is using gas, just the boiler? Is it serving other things or just your underfloor heating?

I have a similar setup in a flow on my Homey and it works well. Eventually I want to completely move away from Homey and do everything in Home Assistant.

What I want is that every time my underfloor heating pumps are turned on, a start number of my P1 gas meter is determined and when my underfloor heating pumps are turned off, an end number of my P1 meter is determined.
When the start number is subtracted from the end number, the number of m3 of gas used for this session remains.
I would also like to know at the end of the day how much gas all heating sessions have used together.

My underfloor heating is turned on with a Blitzwolf SPH13 smart plug and turns on when my Tado thermostat has a heating demand of more than 3% and turns off when the heating demand is less than 1%.

I have a Homewizard P1 meter for elektricity and gas.

I hope I have made things a bit clearer now.

You didn’t mention what else is using gas. If it’s the only thing, then this is overly complicated and if there are other users of gas then what stops them from also using gas at the same time?

hot water, shower etc.
I just want to see what is using how many gas.