Hi everyone,
I like to visualize my history in grafana.
To have continuity of my sensor, I create a “virtual sensor” as follows:
# ---------------------------------------------------
- name: "Elektriciteitsverbruik koelkast_smeg"
unique_id: "sensor.elektriciteitsverbruik_koelkast_smeg"
icon: mdi:flash
unit_of_measurement: "W"
device_class: energy
state_class: measurement
state: >
{% if ( states('sensor.shellyplug_s_69e086_power') not in ['unknown', 'unavailable', 'None'] ) %}
{{ states('sensor.shellyplug_s_69e086_power') | float | round(0, default=0 ) }}
{% else %}
{{ "0" | float }}
{% endif %}
availability: >
{{ states('sensor.shellyplug_s_69e086_power') }}
where
sensor.shellyplug_s_69e086_power
→ “physical” sensor of my powerplug
sensor.elektriciteitsverbruik_koelkast_smeg
→ virtual sensor
Reason:
I have more control over my virtual sensor. If my shellyplug is defect and has to be replaced, I just reconfigure my virtual sensor, so I’m sure I can save long-term statistics of my sensor.
So far so good.
If I visualize those stats in grafana, I get following result:
(1) the physical sensor
(2) the virtual sensor
You can notice that at several places, the graph does not display correctly: it seems that there is some power usage at that periode, which isn’t.
If I zoom in in grafana, this dissapears (almost):
But sometimes you still can see an anomalie (3)
I think this has something to do with my granularity of the virtual sensor: as you can see in its definition, I round to 0
{{ states('sensor.shellyplug_s_69e086_power') | float | round(0, default=0 ) }}
and indeed, If I zoom in again, you can see that my virtual sensor (2) has less datapoints than the physical one (1):
(1) shows more “ripples” than (2)
This is on purpose. I don’t think my shelly plug is that accurate that I need those numbers after the comma…
BUT
You can also see that the latest value around 10:21:30 is 1W. This will remain for a while as my fridge doesn’t work for the next half hour.
If I zoom out again: grafana will display this as
So on first sight you have the impression that the latest datapoint was 21.5 W and NOT 1 W
This is very confusing…
Of course I can drop the round() and register more points, but the issue remains: If a sensor does not updates it’s data for a while (because there is no change), it’s hard to interpret the graphs.
Is there a solution for this?
Kind regards,
Bart