Error in making sensor, please help

The beginning of the sensor was make by someone that solves the negative part. So this should work. Now the positive remains. The idea was to replace the high value (higher than x) with no value, not 0 otherwise the counting will start at 0 again.

Are these the graphs you are looking for?


Try this:

  - sensor:
      - name: “Schrek Verlichting Energie verbruik”
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >
          {% set value = states('sensor.schrek_verlichting_electric_consumption_kwh') | float(6) %}
          {% if 5 > value > 0 %}
            {{ value }}
          {% else %}
            {{ this.state }}
          {% endif %}
        availability: >
          {{ states('sensor.schrek_verlichting_electric_consumption_kwh') | is_number }}

This will copy all values from the source sensor if in the range of greater than 0 to less than 5. If it is outside that range the value will not change from the previous value. The sensor will become unavailable if the source sensor is unavailable.

1 Like

Thanks again. I have copied this but have the same error again… I have restarted HA.

Schermafbeelding 2023-07-19 202751

Confirguration.yalm

Entity ID is mentioned correct
Schermafbeelding 2023-07-19 203108

Go to Developer Tools → Statistics.

Are there any FIX ISSUE buttons there for you to press?

Also what is the current state of sensor.schrek_verlichting_electric_consumption_kwh?

There are a lot of FIX ISSUEs to press but non for this sensor.
This is new for me, I will these. Thanks!

Is this the state you are looking for?

Your source sensor is 81.9, which is quite a bit above 5 so the template sensor is not updating. You specified the source sensor must be between 0 and 5 for it to update.

oke, this I understand.
The correct values I see are 0.1 to 0.6 kWh, see image. These are correct and need to be used for the engery report. Between 0 and 5 is in this range. 81.9 is the total usage from start till now.

Do we need if the value updates the state to a maximum current state + 5 than ad value if not ignore value? (I am thinking in Excel :slight_smile: )

I hope we are getting there step by step… fingers crossed…

Schermafbeelding 2023-07-19 212726

So only the increment has to be less than 5.

  - sensor:
      - name: “Schrek Verlichting Energie verbruik”
        unit_of_measurement: kWh
        device_class: energy
        state_class: total_increasing
        state: >
          {% set value = states('sensor.schrek_verlichting_electric_consumption_kwh') | float(0) %}
          {% if value > 0 and value - this.state < 5 %}
            {{ value }}
          {% else %}
            {{ this.state }}
          {% endif %}
        availability: >
          {{ states('sensor.schrek_verlichting_electric_consumption_kwh') | is_number }}

You will have to manually set the first value of this sensor in Developer Tools → States. Set it equal to the state of sensor.schrek_verlichting_electric_consumption_kwh

so far so good, no errors. Now waiting to see the data getting in.
Big thanks !!!

Did you initialise the sensor?

Yes I did. I made 2 sensors. Unfortunately the sensor is not adding the usage.

1st sensor
No Energy update yet.

2nd sensor
Total usage when I made the sensor was 262.23. Real sensor is now at 264.5. New sensor is not updated. See image

Why?

2 different sensors for 2 different plugs with these issues

Did you initialise both?

Did you change the sensor source in two places for the second sensor (state and availability)?

Post you config for the two sensors.

Yes I did ( I think)

Below this images of what I did.

yesterday when I made the sensor it was 81.91, the original is now 81.92, new sensor stays 81.91

yesterday when I made the sensor it was 262.23, the original is now 265.17, new sensor stays 262.23

The original sensor has more attributes, meter_type: 1 and meter_type_name: ELECTRIC. Can this be important?

No, not important.

So they are both working then?

I see no values in the new sensors. Or is the new sensor making the adjustments in the original sensor?

The first one, is the original sensor, the last one is the new one. The last one has no values. See image

Has it been an hour and 12 minutes since the sensor started updating?

Have you fixed all your statistics issues?

No I haven’t fixed the statistics issues because there we none with the related sensors. I will do the fixes now.

I will have some patients and see again.

The statics issues are fixed.
The new sensors have been active since yesterday.

The original sensor has values. see image at 10:50 and 11:10

The new sensor has no values, while the above values are between 0 and 5