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.
- 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.
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 )
I hope we are getting there step by step… fingers crossed…
- 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