Grafana and sensor values: problems with granularity

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

The better solution is to not do it.

This is not required. You only have to change the new sensor entity id to match the old one.

Hi @tom_l ,
Thanx for your anwser, but this was not really the question.
I have enough other reasons to create my virtual sensors. If you want to discuss about this, please open another ticket.

So my question remains: why does grafana not show the “latest” value when zoomed out.

FYI,
This has nothing to do with the template sensor. Here a graph with native values of my boiler sensors:

Here you can see in period (1)

  • first graph: my boiler modulation seems to be around 30%
  • second graph and third graph: you clearly can see that the boiler is off: no electricity consumption of the circulation pump and temperatures also drop. So modulation is definitly 0% (off)

PS
I modified the title to drop the “template” because this is not related

Try making this larger:

Ok, this helps.
But than: wat is an “appropriate” value?
And why does the graph of a calculated field (even without round() ) needs different settings than the original sensor…