BLOCK kWh measurement from going to 0

Hi guys!

6 Month already now and I still struggle with this issue…
As you can see on my screenshot, I have a measurement coming via mqtt - it measures energy in kWh. My problem is, that from time to time, this value hits 0, 1 or something far away from the current value, which (by nature) can ONLY increase.
So how can I force this sensor to ONLY increase its value, never ever go to zero and not decrease its value?

My current config for this MQTT Sensor:

    - name: Wallbox-Energy-Total  
      state_topic: "modbus/1/inputRegisters/1/307 EnergyMeterReading"
      unit_of_measurement: "kWh"
      state_class: total_increasing
      device_class: energy
      min: 100
      unique_id: 'sensor.wallbox_energy_total'

I really hope, someone has a working solution for me :slight_smile: My nervs are already blank… :sleepy:
Thanks in advance!!!

value_template: >-
  {% set p = states('sensor.wallbox_energy_total')|float(0) %}
  {{ value if (value|float(0)) > p else p }}

If the value is more than the previous value then new value, else existing value.

Add that.

1 Like

ohhh thanks!! It seems to work!! :slight_smile:
I always did the mistake to create an extra template in the helpers section, but now I simple added that to the sensor config (had to remove the “min” setting).

1 Like