Is this the best way to pass in the current day of the week to get the array for today?
{% set d = as_timestamp(states('sensor.date')) | timestamp_custom('%A') %}
{% set tProgDHW = state_attr('water_heater.home_domestic_hot_water_0','time_program_dhw') %}
{% for item in tProgDHW[d.lower()] %} {# expects lowercase weekday string #}
{%- set st = as_timestamp(today_at(timedelta(minutes=item["start_time"]))) | timestamp_custom('%H:%M') %}
{%- set et = as_timestamp(today_at(timedelta(minutes=item["end_time"]))) | timestamp_custom('%H:%M') %}
{{ st }}{{ " - " }}{{ et }}
{%- endfor %}
Renders the following for ‘tuesday’ :
03:00 - 05:00
21:00 - 22:00
Is there a better/simpler way to convert the minutes from midnight in to HH:MM, please?
Any recommendations for a dashboard card to display this info?
Simplest option I guess is a markdown card.
I overlooked this important detail. I have Template Sensors on the brain and thought this was yet another Template Sensor.
I may be wrong but I think the template in a Markdown card is evaluated only while the card is displayed. In other words, the code only runs when there’s a need to run it. So unless you are displaying that card all day, the template will update every minute while the card is displayed (it’s not a resource hog).
In contrast a template in a Template entity (sensor, binary_sensor, lock, cover, etc) or in a Template Trigger is evaluated, continuously, according to the frequency described in the documentation.
Thanks, that’s really worth knowing.
Amusingly, I opted to use my template as the state in an paper-buttons-row card.
I will swap that out for the markdown card.
If you ever need to create a Template Sensor having a complex template but you want fine-grained control over when it’s evaluated, consider using a Trigger-based Template Sensor.
A Trigger-based Template Sensor will evaluate its template only when triggered by one of its triggers. In other words, a template containing now() or today_at() won’t be evaluated every minute. Nothing that changes state in the template forces an update. Evaluation only occurs when one of the triggers is triggered.