Slowing down the update for a Sensor template

Hi!

I have 13 sensors which are updateing every 2 seconds, not all in the same time… and I have created a template sensor, in order to have the SUM of those 13 sensors, but this template sensor it is updating like crazy fast, and it is logical to do so, but still… there in any way to slow it down? To make it show the update every 2 seconds only?

This is the template sensor:

    home_total_consumption:
      value_template: >
        {{ (states("sensor.tuya_cb_ac_bedroom_balcony_power_watts") | float + states("sensor.tuya_cb_ac_gym_power_watts") | float + states("sensor.tuya_cb_ac_living_power_watts") | float + states("sensor.tuya_cb_bathroom_sockets_power_watts") | float + states("sensor.tuya_cb_dishwasher_power_watts") | float + states("sensor.tuya_cb_dressing_gym_bedroom_sockets_power_watts") | float + states("sensor.tuya_cb_kitchen_fridge_power_watts") | float + states("sensor.tuya_cb_kitchen_sockets_power_watts") | float + states("sensor.tuya_cb_lights_power_panel_sockets_power_watts") | float + states("sensor.tuya_cb_living_computer_sockets_power_watts") | float + states("sensor.tuya_cb_oven_power_watts") | float + states("sensor.tuya_cb_server_power_watts") | float + states("sensor.tuya_cb_washing_macine_power_watts") | float) | round(1)  }}
      icon_template: "mdi:flash"
      unit_of_measurement: "W"

Thank you in advance!

Create a Trigger-based Template Sensor with a Time Pattern Trigger that triggers every 15 seconds (or whatever interval you prefer). The Trigger-based Template Sensor will compute the sum every 15 seconds exclusively (not when any of the 13 sensors changes state).

template:
  - trigger:
      - platform: time_pattern
        seconds: '/15'
    sensor:
      - name: Home Total Consumption
        state: >
          {{ expand('sensor.tuya_cb_ac_bedroom_balcony_power_watts',
            'sensor.tuya_cb_ac_gym_power_watts',
            'sensor.tuya_cb_ac_living_power_watts',
            'sensor.tuya_cb_bathroom_sockets_power_watts',
            'sensor.tuya_cb_dishwasher_power_watts',
            'sensor.tuya_cb_dressing_gym_bedroom_sockets_power_watts',
            'sensor.tuya_cb_kitchen_fridge_power_watts',
            'sensor.tuya_cb_kitchen_sockets_power_watts',
            'sensor.tuya_cb_lights_power_panel_sockets_power_watts',
            'sensor.tuya_cb_living_computer_sockets_power_watts',
            'sensor.tuya_cb_oven_power_watts',
            'sensor.tuya_cb_server_power_watts',
            'sensor.tuya_cb_washing_macine_power_watts')
            | map(attribute='state') | map('float', 0)
            | sum | round(1) }}
        icon: "mdi:flash"
        unit_of_measurement: "W"

EDIT

Correction. Replaced 15 with /15

1 Like

Wow… a trigger based sensor, nice! :smiley:

Hmmm… I see you done something different about sum calculation, I don’t understand nothing, except “sum” and “round” :smiley: But I will use it like you told me.

Thank you!

1 Like

Another small question:

I used 3 seconds for the time_pattern and all good, but when I changed to 2 seconds, it is acting like I put 30 seconds :smiley:

As far as I tested more… Seems that does not care if I put 2, 3 or 15 seconds, the sensor will update every 1 minute… or close to a minute…

Any idea?
Thanks!

I made a mistake in the example’s Time Pattern Trigger. The 15 should be /15 to indicate the trigger should occur every 15 seconds (change the value to whatever you prefer but ensure it’s prefixed with a slash). I have corrected the example posted above.

The template uses a different approach, to add the values of 13 sensors, simply to demonstrate that there’s often more than one way to achieve the goal. If you wish, you can replace it with your template.

1 Like

Niceeeee

Thank you so much!

By mistake, don’t you know how to change the style of “more-info” popup using card-mod? :smiley:

Sorry, no, I don’t know the answer to that question. I suggest checking the long topic dedicated to card-mod.

1 Like