Hi all
I’ve been at this for about 18 months now and my configuration is slowly getting more complex - my hardware is nowhere near full in any sense, but as I pile more stuff in I am beginning to wonder if some of my coding is rather inefficient - in particular, with time-related templates being evaluated FAR too often. Here’s an example - its the code for a template helper.
- name: Event Waste Garden
state: >
{% set midnight = today_at() %}
{% set event = state_attr('calendar.waste_garden', 'start_time') | as_datetime | as_local %}
{% set delta = event - midnight %}
{% if delta.days == 0 %}
Today
{% elif delta.days == 1 %}
Tomorrow
{% else %}
In {{ delta.days }} days
{% endif %}
Now, this works perfectly: my concern is that according to the template testing tool, this expression is reevaluated every minute … when, really, it only needs to be evaluated once a day. I have lots of similar things going on!
One thought would be to refactor this completely - take everything that I know only changes once a day and write a script, automated to run just after midnight, that recalulates all the helpers like this one.
Another thought is to wonder if I can replace today_at() (which, AFAIK, is what is being recalulated every minute) with a different method that is only tested daily.
Any thoughts?