Utility_meter: Add value ONCE

  pv_erzeugung_heute:
    source: sensor.pv_erzeugung_in_kwh
    name: pv_erzeugung_heute
    cycle: daily
    unique_id: pv_erzeugung_heute

  pv_erzeugung_monat:
    source: sensor.pv_erzeugung_in_kwh
    name: pv_erzeugung_monat
    cycle: monthly
    unique_id: pv_erzeugung_monat

  pv_erzeugung_jahr:
    source: sensor.pv_erzeugung_in_kwh
    name: pv_erzeugung_jahr
    cycle: yearly
    unique_id: pv_erzeugung_jahr

I am stupidly missing 3 days this year. Power cut.
But I have the values. They are supplied by the PV system.

But how can I add the value?
I have already tried it with a reset + start value:

/homeassistant/automations.yaml
  automation:
  - alias: "Einmalig Startwert setzen"
    trigger:
      - platform: homeassistant
        event: start
    action:
      - service: python_script.set_state
        data:
          entity_id: sensor.pv_erzeugung_monat
          value: 40
    mode: single
/homeassistant/python_scripts/set_state.py
entity_id = data.get('entity_id')
value = data.get('value')
attributes = hass.states.get(entity_id).attributes
hass.states.set(entity_id, value, attributes)

The value is also set to 0. Then briefly 40 and then it continues with 0.001 again. So it counts up again at 0. The start value is ignored.

Idea 2: But I have discarded it. I set a fake sensor with a value of 40 and it then calculates this value + the new PV buzzer from tomorrow. But that’s stupid. Then I’ll be lugging around a dead fake sensor for years.

Does anyone have any ideas?
I have already sent an update command to the DB. But without success. I must have got the wrong sensor or something.

THANKS for Ideas

P.s.
Developer tools => States

  • Set entity + state

The same as before. Sensor briefly gets 40 as value and then calculates back to its original value. e.g. 6.71