I just noticed this thread linked from the release notes and skimming through it, I didn’t really see this question answered. Forgive me if I missed it, it’s already a long thread.
A template like this (which I use to turn my amplifier on/off):
{{ is_state("media_player.samsungtv", "on") or is_state("media_player.apple_tv", "playing") }}
used to be recalculated whenever one of the two entities changed. However, if the TV is on, we know the template will always be true so updating the template when the Apple TV is (de)paused is a waste of effort. The Apple TV state cannot affect the result when the TV is on! With 0.115, the template is thus only recalculated when the TV changes state or if it is already off. The current state of the system is used to deduce which parts of the template can currently be ignored.
That is just a performance improvement (less template recalculations) but if we change it like this:
{{ is_state("media_player.samsungtv", "on") or is_state(state("input_select.media"), "playing") }}
the performance improvement becomes significant. We now watch the TV state, the media selector and the currently selected media player. The old way would always watch all possible media players.
Furthermore, previously you had to carefully list all possible input_select.media
values as entity_id:
on any template that used input_select.media
as input like above. This is now completely automatic, a huge improvement in usability and much less error-prone.
Moving on, we can change the template like this:
{{ is_state("media_player.samsungtv", "on") or is_state(state("input_text.media"), "playing") }}
and we now have something that was impossible to do before. An input_text
can contain any value so you cannot possibly list them all as entity_id:
in advance.
So that’s the reasoning for the change. Everything is now faster, easier, smaller and it always works.
The downside is that we need to rework templates that rely on time to use a new workaround for periodic recalculation – which is what this thread was about.
(Another arguable downside is that interdependent templates will have to be untangled to not cause a CPU spike due to an essentially infinite loop. In essence, if template a is b+1 and template b is a+1 each template will now continuously update forever. This is actually correct but probably not very useful so I think code will be added to detect this and abort after a certain depth. This could not all be in place for the first release because we are still learning about such situations as people report templates that they use.)