Change (slow down) interval update template sensor

Hi all,

In The Netherlands there is a support from the government regarding energy prices. For that there is a limitation to those prices until a certain level (kWh’s for electricity and m3’s for gas). I implemented a few template sensors in my configuration.yaml to track how much of this level we have consumed. These template sensors are now every minute/second when electricity or gas is used/returned. For me it is ok to have them fired once each hour or even once a day, as it is creating irrelevant logging and therefore lets my db grow.

Until now I could not figure out a way to change the update interval. Any suggestions?
As you can see below I use more sensors. It is the one after the remmed comment “Prijsplafond energie stroom”.

Thanks a lot!

# SENSOREN NIET-MQTT
# ODROID temperatuur
sensor:
  - platform: command_line
    name: CPU Temperature
    command: "cat /sys/class/thermal/thermal_zone0/temp"
    # If errors occur, make sure configuration file is encoded as UTF-8
    unit_of_measurement: "°C"
    value_template: "{{ value | multiply(0.001) | round(1) }}"

# Prijsplafond energie stroom
  - platform: template
    sensors:
     resterend_stroomverbruik_in_het_plafond:
      friendly_name: 'Resterend stroomverbruik in het plafond'
      device_class: energy
      unit_of_measurement: kWh
#      state_class: total
      value_template: >
            {{ 2746 | float(default = 0) -((states('sensor.verbruik_laag') | float(default = 0) + 72 - states('sensor.retour_laag') | float(default = 0)) - 3 + (states('sensor.verbruik_hoog') | float(default = 0) + 81.9 - states('sensor.retour_hoog') | float(default = 0))) - 5 | round(2, default=0) }}
#correctie van 154 kWh per 12-1-2023 voor later starten met meten

You can throttle template sensors by changing to a trigger-based sensor. That will require you to switch the sensor in question over to the current format since triggers are not available with the legacy format.

What I do is have two sensors. The first one is the fast one like you have, the second is a periodic sample of the first one.

So in this example I have a current sensor that updates every 5 seconds, then I have a second sensor that updates once a minute. I don’t log the 5 second one, I do log the 1 minute one. Benefit is I can still see the fast one in Lovelace.


template:
  - trigger:
      - platform: time_pattern
        minutes: "/1"
    sensor:
      - name: "phase_a_current"
        state: "{{ states('sensor.phase_a_current_fast') }} "
        unit_of_measurement: Amp
        device_class: current

1 Like