How to check if a value is larger then last time

Hi,

I this YAML running, it reads my PV power meter. it works fine, except that my power meter sometimes report a negative number.

 sensors:
     smartmeter_import:
        device_class: power
        unit_of_measurement: 'kWh'
        value_template: '{{ states.sensor.smartmeter.attributes["CounterReadingImport"]|float }}'

is there a way to ignore a value that less that last good reading ?

Perhaps something like this:

   sensors:
     smartmeter_import:
        device_class: power
        unit_of_measurement: 'kWh'
        value_template: >
          {% set cr = state_attr('sensor.smartmeter', 'CounterReadingImport') | float %}
          {{ cr if cr > 0 else states('sensor.smartmeter_import') }}

Thanks, I’ll try it out… unfurtally it can take 8-16 hours before it misbehaves…

If you don’t like to wait, you can set a negative value for the attribute manually in the developer tools state page.

1 Like

If you wish, you can force the attribute to be a negative value (or any value you want).

  1. Go to Developer Tools > States.
  2. In the Entity field, select sensor.smartmeter
  3. In State Attributes, locate CounterReadingImport and change its value.
  4. Click the SET STATE button.

Screenshot from 2020-11-24 12-52-09


EDIT

Ninja’d by tjntomas!

2 Likes

What a fantastic service for a noob like me…

Thanks a lot for the help, it seams to be working… (now real lift testing is needed) :slight_smile:

But thanks for the TIP on how to “test”…

So it’s a day later. Is it working properly?

Hi,

Yet, it working perfectly, had to make a small change, had to replace the “0” with a higher number, but it’s a perfect solution for me…

THANKS!

1 Like