Sensor template not updating every minute

Hi Guys,

So i’m trying to create a template sensor to monitor “current_temperature” from a netatmo thermostat and need it to update every minute. I tried finding the answer on this forum but i can’t seem to get this sensor updating every minute. it only updates on reload of the configuration.

So this is what is tries but isn’t updating every minute:

Create “sensor.date_time” and put “sensor.date_time” in “entity_id” so the template sensor will update every minute because the “sensor.date_time” changes state every minute.

  - platform: template
    sensors:
      woonkamer_temp:
        value_template: "{{ state_attr('climate.netatmo_smart_thermostat', 'current_temperature') }}"
        entity_id: sensor.date_time
        friendly_name: "Woonkamer temperatuur"
        device_class: temperature
        unit_of_measurement: '°C'

This should be working right? :slight_smile:

The Netatmo backend does not provide sensor values every minute.
May I ask why you need it updating every minute?

1 Like

Hi cgtobi, thanks for the reply. Because the Netatmo backend doesn’t provide a sensor i decided to build a “template sensor” which will poll the atribute “current_temperature” from the netatmo climate entity.
This works but it updates pretty random, so my graphs aren’t consistent. thats why i want to make the template sensor poll the attribute every minute.

There is the option to make an automation which runs every minute and calls homeassistant.update_entity. but i dont like that option, seems like a “work around”.

all my sensor values are recorded to influxdb with grafana connected. as you can see in below screenshot it updates, but inconsistent. (dots in screenshots are the random datapoints)

It’s “inconsistent” because it only sends updates on changes. That’s the most efficient way to do it. Polling is not.

Also set your Grafana panel Display option “Staircase” switch off it will look a lot more linear.

3 Likes

Exactly what @tom_l wrote. So, even if we would poll the Netatmo every minute, which we don’t, shouldn’t nor wont, your graph would always look the same as only state changes are written to the state machine and therefore to the database.

1 Like

Thanks for the reply guys, but i dont need help on the grafana part. i’m using grafana as my go to data visualisation tool for years now, connected on different kinds of data source, etc. The screenshots was just an example to show you guys how inconsistent the template sensor is.

i dont really get what @tom_l means with “the most efficient way” are you reffering to the automation? just to be sure we are talking about the same subject i supplied a link to the manual i followed and are now talking about in this forum post.

As I already wrote, the data is not inconsistent. It is efficient as it only stores when the value differs.

1 Like

aha! sorry i didn’t get that! so you mean the template sensor is actually running every minute but because the value doesn’t change it doesn’t get stored? i thought the template sensor would just store the value every minute… :frowning:

Even if it would, nothing would change.
If the template sensor would store the value every minute the graph would not change at all. You just have more points on a straight line.

3 Likes

lol, hahaha :slight_smile: offcourse!

To explain why i want it every minute or every 5 minutes. (it seems like you guys are only focusing on this) is really simpel. So grafana works with time ranges, for example “last hour”. if there isn’t a data point in that time range grafana will not show anything, were it would show me a line in my graph(straight line if you wish) when it updates every minute.

Ah, I see, that makes sense.
Maybe you could adjust the query in Grafana something like this:

SELECT last("value") FROM "°C" WHERE ("entity_id" = 'woonkamer temperatur') GROUP BY time($__interval) fill(previous)

Haven’t used Grafana and InfluxDB for a long time, so this might be complete non sense :sweat_smile:

1 Like

I’m gonna try a different approach to get this done.

The Template Sensor works as it should but isn’t the solution for what i tried to achieve. I tried to create a Sensor which would record the value from a entity attribute to InfluxDB per minute. The template sensor actually runs every minute but only records the value when its not the same as the last value. (**last known value. homeassistant reload actually does update the value although the previous value is the same)

This Topic can be closed. Thanks for the explanation @Burningstone, @cgtobi and @tom_l!

1 Like

FYI, if you are familiar with python, this would be fairly easy to to in AppDaemon.

1 Like