Not sure if this is the right thread to post this in. I have an automation to update template sensors that only have the now() function. They would update every hour or so, depending on what I needed. Now I understand they will update every minute due to the now() function, so the automation is obsolete.
The sensor template looks like this (this one adjusts the thermostat in the morning to something more comfortable before we actually get up for coffee):
prep_hvac_for_wakeup:
friendly_name: Prep HVAC for wakeup
value_template: >
{% set delta_between_now_and_midnight = now().timestamp() - now().replace(hour=0).replace(minute=0).replace(second=0).timestamp() %}
{% set target_start_timestamp = state_attr('input_datetime.morning_wakeup_workday_start','timestamp') - state_attr('input_datetime.pre_condition_morning_hvac','timestamp') %}
{% set target_end_timestamp = state_attr('input_datetime.morning_wakeup_workday_start','timestamp') %}
{{ ((delta_between_now_and_midnight >= target_start_timestamp and delta_between_now_and_midnight < target_end_timestamp)) }}
It checks to see if the current time (now()
) is within the times specified by the input_datetime
values. If it is, then the {{logic above}}
returns true
I have similar sensors to trigger various time frames throughout the day (morning, late_morning, afternoon, etc) to adjust thermostats and other things.
Is there a better way to do this so itās not updating every minute because of now()
? Orā¦ maybe updating a few sensors every minute when they donāt need to is not a big deal on the olā CPU.
Thoughts?
And the discussion in this thread is very interesting and helpful!! Thanks, @123 and @petro and @frenck for the helpful discussion!! I hadnāt updated since maybe 0.114, and it didnāt take long at all the hunt down and eliminate the entity_id
statements in my templates.