Quantcast
Channel: Configuration - Home Assistant Community
Viewing all articles
Browse latest Browse all 95365

Template sensor doesn't recalculate on attribute change

$
0
0

@Linwood wrote:

So I think I know what’s happening but am wondering if there is an appropriate way to fix it. I have the following value template.

        {% if (states('sensor.hvac_operating_state') == 'cooling') and states.sensor.ac_split_ambient_temp is defined and states.sensor.ac_split_cold_temp is defined %} 
           {% if (as_timestamp(now()) - as_timestamp(states.sensor.hvac_operating_state.last_updated) > 240 ) %}
               {{ (states('sensor.ac_split_ambient_temp') | float - states('sensor.ac_split_cold_temp') | float ) | round(1)  }}
           {% else %} 
               {{ "unknown" }} 
           {% endif %}
        {% else %}
          {{ "unknown" }} 
        {% endif %}

The purpose of this is, when the AC is cooling, and has been cooling for at least 240 seconds, it takes a difference of two temperatures. If anything isn’t true, like it has not been running that long or it is not cooling or for some reason the temperatures go missing it just returns Unknown.

The problem is that it takes much longer than 240 seconds to calculate. I am pretty sure the issue is that the value templates are recalculating only when the states of the expressions change, and it is not recalculating based on the last_updated times’ difference changing. Or more precisely when now() changes.

Which makes sense… Wouldn’t want it calculating every millisecond or whatever the resolution is there for “now”:.

So is there any way to do the above but make it evaluate every minute or some such? The only thing I can think of (and have yet to code to try) is to create a new sensor that contains a minute-by-minute time, and somehow include that in the template. Ugly.

So thought I would ask: Is my presumption correct about why?

And is there a better way?

Posts: 1

Participants: 1

Read full topic


Viewing all articles
Browse latest Browse all 95365

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>