Gas consumption costs seem to be buggy calculated

Hi guys,

I have build up an esp to count my gas meter inductivly which works perfectly. Now I want to calculate the price in the energy dashboard.

Since I count the gas in m³ and the price is per kWh, I created a sensor which calculates the price for every m³ of gas (which is pretty straight forward in germany):

 - name: Gaspreis (m³)
        state: "{{ ((((states ('input_number.gaspreis') | float) | float * (states ('input_number.gas_zustandszahl') | float)) | float * (states ('input_number.gas_brennwert') | float)) | round(4)) }}"
        unit_of_measurement: "€/m³"

Gas price for 1 kWh:
image

“Brennwert” and “Zustandszahl”:
image

The conversion from m³ to kWh is:
Consumption * Zustandszahl * Brennwert

For explanation:

“Brennwert” is the energy of the gas itself when it’s burned. The “Zustandszahl” describes the ratio of a gas volume in the standard condition to the gas volume in the operating condition. It mathematically converts the (geometric) gas volume measured by the gas meter under ambient conditions to a defined standard state.

I added my gas meter sensor to the energy dashboard and attached a price entity to this:

But the price seems to be calculated false:

Now I consumed 1,66m³ of gas actually. Which is around 16,6 kWh (rounded for simplification). The price for 1 kWh is currently around 0,09€.

My sensor entity for the gas price in m³ is (after calculation in the template) around 0,90€ per m³. But the dashboard shows 0,20€.

Is there any delay or other calculations done in the dashboard or is the price calculated by the price which was actual price when the consumption was and how can I fix/correct this?

Its seems to be fixed by waiting several hours. It seems the price is used the entire day.

Hi Marco,

could you tell me where you implemented the script for the sensor? Did you put it in your sensor.yaml or in your configuration.yaml?

@saftmacke Its only only in the config:

mqtt:
  sensor:
    - state_topic: "home/KellerESP/Gas/Total"
      name: "Gaszähler MQTT"
      unit_of_measurement: "m³"
      state_class: total_increasing

      # state_class: measurement
      device_class: energy
      unique_id: sensor.gaszaehler_keller_m3

template:
  - sensor:
      - name: Gas Meter (kWh)
        state: "{{ (states ('sensor.gas_meter_m3')  | float * states ('input_number.gas_zustandszahl') | float * states ('input_number.gas_brennwert') | float) | float | round(2) }}"
        unit_of_measurement: "kWh"
        device_class: "energy"
        state_class: total_increasing

      - name: Gas Meter (m3)
        state: "{{ states ('sensor.gaszahler_mqtt') | float }}"
        unit_of_measurement: "m³"
        device_class: "gas"
        state_class: total_increasing

      - name: Gaspreis (m³)
        state: "{{ ((((states ('input_number.gaspreis') | float) | float * (states ('input_number.gas_zustandszahl') | float)) | float * (states ('input_number.gas_brennwert') | float)) | round(4)) }}"
        unit_of_measurement: "€/m³"
1 Like

HI Marc, im also in germany…where do you get the values for gas_zustandszahl, gas_brennwert…

I have m3’ from my gas sensor, and the Gaspreis from the gas company…

In Germany your provider has to provide the Brennwert and the Zustandszahl in your invoice so you can reconstruct the unit conversion from m3 to kWh (which is the main unit for calculating your invoice)

How are Brennwert and Zustandszahl beeing configured in HA? (GUI or yaml and how exactly)
@Disane87

just normal number inputs on the UI

this way?

1 Like

looks good :slight_smile:

so brennwert is 11.468 zustand 0,964 price per kwh is 11,09ct/kWh .
is a price per m³ of 1.226 real? are this Euro?

did you include the Grundpreis also in your calc?
@Disane87

around 1€ should be normal. That seems to be ok:

My consumption today:

I dont have the Grundpreis included because thats every month the same

1 Like

Hey Marco,
can you show me how i can get this price entity for the energy dasboard?
I have the Brennwert and Zustandszahl and my gas consumption in m³. But the cunsumption is not for a day. Its Only a total consumption since installation.

yes, exactly what I was looking for. Thanks for your groundwork @Disane87 :wink:

By the way, I get the Brennwert directly from my network provider’s website using “multiscrape”. They even provide the 12-month review there, so I always automatically have the value that my provider also uses.

Unfortunately, I can’t find any publication of the Zustandszahl, otherwise I could get it directly

Have a nice Day =)