Troubles with start value in Energy Dashboard for manual sensors

Hi,

I have set up a manual sensor for water and for gas. They show up in the energy dashboard. Unfortunately, I cannot set the start value to, for example, 1790 m3 in my configuration. This leads to a consumption of 1790 m3 for the day. I tried already a lot with “initial”, “offset”, “minimum”, but with no success. My last configuration.yaml entry looks like this:

input_number:
  gas_meter_reading:
    name: Gas Meter Reading
    min: 2907
    max: 99999
    step: 0.001
    unit_of_measurement: m³
    initial: 2907
  water_meter_reading:
    name: Water Meter Reading
    min: 1790
    max: 99999
    step: 0.001
    unit_of_measurement: m³
    initial: 1790
    
template:
  - sensor:
      - name: "Gas Daily Consumption"
        unique_id: gas_daily_consumption
        device_class: gas
        state_class: total
        unit_of_measurement: "m³"
        state: >
          {% set now = now() %}
          {% set last_reset = states('sensor.gas_last_reset') %}
          {% if now.strftime('%Y-%m-%d') != last_reset %}
            {% set value = 0 %}
          {% else %}
            {% set value = states('sensor.gas_daily_consumption') | float(0) %}
          {% endif %}
          {% set current = states('input_number.gas_meter_reading') | float %}
          {% set initial = states('sensor.gas_daily_initial') | float(current) %}
          {{ (value + current - initial) | round(3) }}
        attributes:
          last_reset: "{{ now().strftime('%Y-%m-%d') }}"
          initial_reading: "{{ states('input_number.gas_meter_reading') }}"

      - name: "Water Daily Consumption"
        unique_id: water_daily_consumption
        device_class: water
        state_class: total
        unit_of_measurement: "m³"
        state: >
          {% set now = now() %}
          {% set last_reset = states('sensor.water_last_reset') %}
          {% if now.strftime('%Y-%m-%d') != last_reset %}
            {% set value = 0 %}
          {% else %}
            {% set value = states('sensor.water_daily_consumption') | float(0) %}
          {% endif %}
          {% set current = states('input_number.water_meter_reading') | float %}
          {% set initial = states('sensor.water_daily_initial') | float(current) %}
          {{ (value + current - initial) | round(3) }}
        attributes:
          last_reset: "{{ now().strftime('%Y-%m-%d') }}"
          initial_reading: "{{ states('input_number.water_meter_reading') }}"

      - name: "Gas Last Reset"
        unique_id: gas_last_reset
        state: "{{ now().strftime('%Y-%m-%d') }}"

      - name: "Water Last Reset"
        unique_id: water_last_reset
        state: "{{ now().strftime('%Y-%m-%d') }}"

      - name: "Gas Daily Initial"
        unique_id: gas_daily_initial
        state: "{{ states('input_number.gas_meter_reading') }}"

      - name: "Water Daily Initial"
        unique_id: water_daily_initial
        state: "{{ states('input_number.water_meter_reading') }}"
    

Has anybody a clue how I can start with 0 consumption?

You don’t need a start value, if you want to remove that consumption, use the Adjust Sum dialog in developer-tools statistics, find this large value and change it to 0. That will remove the erroneous consumption.

@karwosts Thanks for your suggestions, I really appreciate. I have changed my script to the following:

# Gas Wasser 
# Input Number für manuelle Eingabe der Zählerstände
input_number:
  gas_meter_reading:
    name: Gas Zählerstand
    min: 0
    max: 10000
    step: 0.1
    unit_of_measurement: "m³"
    mode: box

  water_meter_reading:
    name: Wasser Zählerstand
    min: 0
    max: 10000
    step: 0.1
    unit_of_measurement: "m³"
    mode: box

# Template Sensoren für die Berechnung des Verbrauchs
template:
  - sensor:
      - name: "Gas Verbrauch"
        unique_id: gas_consumption
        unit_of_measurement: "m³"
        state_class: total_increasing
        device_class: gas
        state: >
          {% set current = states('input_number.gas_meter_reading') | float %}
          {% set previous = states('sensor.gas_verbrauch') | float(0) %}
          {{ current if previous == 0 else current - previous }}

      - name: "Wasser Verbrauch"
        unique_id: water_consumption
        unit_of_measurement: "m³"
        state_class: total_increasing
        device_class: water
        state: >
          {% set current = states('input_number.water_meter_reading') | float %}
          {% set previous = states('sensor.wasser_verbrauch') | float(0) %}
          {{ current if previous == 0 else current - previous }}

# Utility Meter für die Verteilung des Verbrauchs
utility_meter:
  gas_daily:
    source: sensor.gas_verbrauch
    cycle: daily

  gas_monthly:
    source: sensor.gas_verbrauch
    cycle: monthly

  water_daily:
    source: sensor.wasser_verbrauch
    cycle: daily

  water_monthly:
    source: sensor.wasser_verbrauch
    cycle: monthly

Unfortunately, I did not precisely follow your suggestion and deleted the large value for the utility sensors instead of setting it to zero. Can I fix it to eliminate the intial value I created today when adding the meter reading?

And why is the consumption still showing up on the energy board?