Disable template sensor auto update

Hi All,

I am trying to use a custom component to display the power distribution in my house. It is called power distribution card (you can find it here: LINK and it has a nice graphical overview to show on your dashboard.

For this to work, I have to create some template sensors, which convert everything into watts and calculates the correct values. I use the following code to do this:

sensor:
  - platform: template
    sensors:
      powercard_solar:
        friendly_name: 'PCard Zonnepanelen'
        unit_of_measurement: 'W'  
        value_template: "{{states('sensor.zonnepanelen_output_w') | float | round(0)}}"
      powercard_net:
        friendly_name: 'PCard Stroomnet'
        entity_id: 'sensor.zonnepanelen_output_w'
        unit_of_measurement: 'W'  
        value_template: >-
          {% set cons = (states('sensor.power_consumption') | float * 1000) | round(0) %}
          {% set prod = (states('sensor.power_production') | float * 1000) | round(0) %}
          {{ cons - prod }}
      powercard_home:
        friendly_name: 'PCard Thuisverbruik'
        entity_id:
        entity_id: 'sensor.zonnepanelen_output_w'
        unit_of_measurement: 'W'  
        value_template: >-
          {% set zon = states('sensor.zonnepanelen_output_w') | float | round(0) %}
          {% set prod = (states('sensor.power_production') | float * 1000) | round(0) %}
          {{ zon - prod }}

The calculations are all working and show the correct values. However, the update of my solar panels data (sensor.zonnepanelen_output_w) is much less frequent then the values of my power meter (sensor.power_production & consumption). This can lead to display strange distribution of the power when there is provide lots of power to the grid, but the solar panels sensor is not updated yet. So basically the update of ‘powercard_net’ and ‘powercard_home’ should only occur right after ‘sensor.zonnepanelen_output_w’ (or the template sensor ‘powercard_solar’) is updated.

I already tried to set the ‘sensor.zonnepanelen_output_w’ as entity id. Although this indeed triggers an update when a new solar panel output comes in, the sensors are still also updated when the power meter values change.

I know I can manually force an update via an automation and the sensor update service, but how can I disable the auto-update of these sensors? Thanks for any help!

Hi,

I see, personally I would create an automation to calculate and update the values triggered by a state change on sensor.zonnepanelen_output_w instead of wrapping the calculations into sensor entities.

The other concern I have is whether these custom powercard_* entities need to be sensors ?
Maybe they should be number entities instead as I presume you only need these values to plug into cards ?

Hope this helps

2 Likes

As of several versions ago, the use of entity_id in a Template Sensor is no longer supported. A template’s update frequency is now governed exclusively by the the entities within the template. In this case:

        value_template: >-
          {% set cons = (states('sensor.power_consumption') | float * 1000) | round(0) %}
          {% set prod = (states('sensor.power_production') | float * 1000) | round(0) %}
          {{ cons - prod }}

It means the template will be evaluated every time either sensor changes state (and no less).

To limit the re-calculations, you will need to try the suggestion provided by _dev_null.

1 Like

Hi _dev_null,

That sounds like a good solution! (Why didn’t I think of that myself…). Let me check if this works and I will get back on this topic.

EDIT: Tried it! Created input_number helpers instead of template sensors and created an automation to calculate the needed values and set the input numbers, as soon as the solar_output changes. Works like a charm! Simply tried a too complex solution. Thanks _dev_null!

1 Like

No problem Rene,

Glad it worked out - all the best !