Meter reading

Hello,

Im using dsmr intergration to reed my elektric meter.
But everytime im rebooting my raspberry the meter goes to 0.
Because of that the trend is not realy usefull anymore.
Is there a way to keep the last value until the raspberry is fully started again.

You can build a flow in node red to record the highest value in a file and use it after any reboot.

The easiest way would be to create a template sensor that filters out undefined readings:

sensor:
  - platform: template
    sensors:
      my_template_sensor:
        value_template: >
          {% if states('sensor.whatever') is undefined %}
            {{ states('sensor.my_template_sensor') }}
          {% else %}
            {{ states('sensor.whatever') }}
          {% endif %}

Is there another way to do this?
I have a lot of solar panels placed and i think my meter wil get above 0 in summer and below 0 in winter.
So picking the highest or lowest value doesnt work for me i think.

Is this like a loop or something that only takes a new value when its something else then 0?

I had the same issue with my pzeom energy meter. The value of the energy measured used to get zero with reboot. In this case I created a virtual sensor with nodered custom addon which got updated with the value of my energy meter until it had malfunction. Also I created a flow in node red to record the latest highest value and store it in a file. And a second flow which detects my device shutdown or mal functions and then uses the stored value to correct the virtual sensor value.

No it only takes a new value if the sensor actually exists.

If the issue is that the sensor exists but it actually reads 0 then you could do the following:

value_template: >
  {% if states('sensor.whatever') | int = 0 %}
    {{ states('sensor.my_template_sensor') }}
  {% else %}
    {{ states('sensor.whatever') }}
  {% endif %}

or if it could be both undefined or 0 then you could combine those with an or:

value_template: >
  {% if states('sensor.whatever') is undefined or states('sensor.whatever') | int = 0 %}
    {{ states('sensor.my_template_sensor') }}
  {% else %}
    {{ states('sensor.whatever') }}
  {% endif %}

i tried the 2nd option but i get an error any idea what it could be?

Nevermind i found the problem i dint placed 2 times the == after int.
Thanks a lot for the time and help guys.

Nope that was my fault. I missed it in the first one and copied the mistake in the second one.