Template sensor doesnt refresh every minute

Hi all,

I have a working set of template sensors, but they refresh every few minutes. The underlying data is refreshing every minute. How can I make this template sensor also refresh every minute?

The config shows as follows:

    energy_consumption_net_peak_kwh:
      friendly_name: Net Energy peak
      unit_of_measurement: kWh
      value_template: "{{ (states('sensor.energy_consumption_tarif_2')|float - states('sensor.energy_production_tarif_2')|float ) | round(2)}}"

The value shown is correct, but only the time is not equal to the times of the underlying sensors. Both the consumption and production are updated every minute (also shown in table)

The template sensor will only update if the incoming values actually change — that is, are different from the previous value. Both of the sensor values used in the calculation remain the same for the last three entries on your table, for example.

This shouldn’t be a problem. If it is, you need to get sensor.time installed and built into your calculation with something like:

value_template:
  {% set unused_variable = states('sensor.time') %}
  {{ (states('sensor.energy_consumption_tarif_2')|float 
 - states('sensor.energy_production_tarif_2')|float ) | round(2) }}
1 Like

That sounds plausible, thank you! Then I know I can just use the fill(previous) feature of incluxdb, so I dont need continuous new values :slight_smile: thank you!

1 Like

FYI, You don’t need to use 'sensor.time' anymore. You can simply use now()

{% set blah = now() %}