I have a sensor, that calculates the consumption without my wallbox. Yet, at 0:00 a have huge spike in the sensor values (both original sensors are consumption meters that are set to 0 at 0 o’clock.)
- sensor:
- name: "Verbrauch ohne Wallbox täglich"
unique_id: "house_consump_w_o_wallbox"
unit_of_measurement: "Wh"
state: >
{% set ver = states('sensor.verbrauch_taglich') | float | round(0) %}
{% set wal = states('sensor.wallbox_taglich') | float | round(0) %}
{{ ver - wal}}
Here are the three sensor values:
sensor.verbrauch_ohne_wallbox_taglich
11222
2024-12-14T22:59:52.256Z
sensor.verbrauch_ohne_wallbox_taglich
19634
2024-12-14T23:00:00.008Z
sensor.verbrauch_ohne_wallbox_taglich
0
2024-12-14T23:00:00.010Z
sensor.verbrauch_taglich
19634
2024-12-14T22:59:52.254Z
sensor.verbrauch_taglich
0
2024-12-14T23:00:00.008Z
sensor.verbrauch_taglich
1
2024-12-14T23:00:06.448Z
sensor.wallbox_taglich
8412
2024-12-14T22:50:00.000Z
sensor.wallbox_taglich
0
2024-12-14T23:00:00.002Z
sensor.wallbox_taglich
1
2024-12-14T23:03:44.910Z
However, both source sensor values are 0 at 0:00 - the difference is not 0. What is the cause of this problem and how can I solve it? My first idea was to check the time and not allow a calculation at exactly 0:00. But then I did not know what value to return at that time.
The sensors won’t reset to zero at exactly 0:00, there will be some delay (in milliseconds), and that delay is different for each sensor. There is nothing you can do about this, it is expected and normal.
I would suggest not returning a new calculation if either sensor is zero.
- sensor:
- name: "Verbrauch ohne Wallbox täglich"
unique_id: "house_consump_w_o_wallbox"
unit_of_measurement: "Wh"
state: >
{% set ver = states('sensor.verbrauch_taglich') | float | round(0) %}
{% set wal = states('sensor.wallbox_taglich') | float | round(0) %}
{{ this.state if ver == 0 or wal == 0 else ver - wal}}
Thank you - the idea is great, I’ll give it a try.
But I have two thoughts. Firstly, the suggestion only works as long as sensor.wallbox_daily gets greater than 0 after 0 o’clock. If I disconnect the wallbox from the grid, there is no standby consumption.
Secondly, with the new logic, it may be that the sensor only jumps to 0 at 0:02. This means that the maximum from the previous day is still logged after 0 o’clock. Since I visualize the maximum daily values, this would be a problem.
I’ll let you know if my thoughts have the impact I’m currently thinking.