Utility meter wrong monthly/yearly values for gas only

I have a p1meter installed in my environment based on an esp8266 (https://github.com/Diechel/esp8266_p1meter) and it works like a charm.
I have created the following gas content for file yaml file: utility_meter.yaml
Note: I removed the power configuration as I don’t have issues with those.

hourly_gas:
  source: sensor.P1_Gas_Usage
  cycle: hourly
daily_gas:
  source: sensor.P1_Gas_Usage
  cycle: daily
weekly_gas:
  source: sensor.P1_Gas_Usage
  cycle: weekly
monthly_gas:
  source: sensor.P1_Gas_Usage
  cycle: monthly
yearly_gas:
  source: sensor.P1_Gas_Usage
  cycle: yearly

This is my sensor (sensors.yaml) that is being used for it.

- platform: mqtt
  name: P1 Gas Usage
  unit_of_measurement: 'm3'
  state_topic: "sensors/power/p1meter/gas_meter_m3"
  value_template: "{{ value|float / 1000 }}"

And template sensors:

- platform: template
  sensors:
    # LAST PERIODS GAS
    yesterday_gas:
      friendly_name: Yesterday Gas
      unit_of_measurement: m3
      value_template: "{{ state_attr('sensor.daily_gas','last_period') }}"
    last_week_gas:
      friendly_name: last Week Gas
      unit_of_measurement: m3
      value_template: "{{ state_attr('sensor.weekly_gas','last_period') }}"
    last_month_gas:
      friendly_name: last Month Gas
      unit_of_measurement: m3
      value_template: "{{ state_attr('sensor.monthly_gas','last_period') }}"
    last_year_gas:
      friendly_name: last Year Gas
      unit_of_measurement: m3
      value_template: "{{ state_attr('sensor.yearly_gas','last_period') }}"
 
    # CACULATIONS
    #Gemiddeld
    average_gas_day:
      unit_of_measurement: 'm3'
      value_template: >-
        {% set a = states('sensor.last_month_gas') | float %}
        {{ (a / 30.41) | round(3) }}


    # PRICES GAS
    today_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.daily_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 365 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 365 %}
        {{ (((a * b) + c) + d) | round(2) }}

    yesterday_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.yesterday_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 365 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 365 %}
        {{ (((a * b) + c) + d) | round(2) }}

    week_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.weekly_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 52 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 52 %}
        {{ (((a * b) + c) + d) | round(2) }}

    last_week_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.last_week_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 52 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 52 %}
        {{ (((a * b) + c) + d) | round(2) }}

    month_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.monthly_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 12 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 12 %}
        {{ (((a * b) + c) + d) | round(2) }}

    last_month_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.last_month_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float / 12 %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float / 12 %}
        {{ (((a * b) + c) + d) | round(2) }}

    year_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.yearly_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float %}
        {{ (((a * b) + c) + d) | round(2) }}

    last_year_gas_price:
      unit_of_measurement: 'EUR'
      value_template: >-
        {% set a = states('sensor.last_year_gas') | float %}
        {% set b = states('input_number.all_in_enkeltarief_gas') | float %}
        {% set c = states('input_number.netbeheerkosten_gas') | float %}
        {% set d = states('input_number.vaste_leveringskosten_gas') | float %}
        {{ (((a * b) + c) + d) | round(2) }}

With above configuration I’m getting absurd values for month and year (and corresponding price calculations)
image

I’m searching for weeks now were i made a mistake and why the readings are wrong but can’t find it.
I hope someone else on this forum can help me with this?

Is it increasing values each time home assistant is restarted?

Seems you need availability template to avoid 0 state at startup.

Hi, thanks for thinking with me and my apologies for my late reply. Did some testing but values didn’t increase after reboot. Tomorrow morning I will check that availability template you referring to, thanks :+1: