Hey All.
I’m trying to create template sensors between times of day.
Example: If it’s between 07:00:00 and 07:30:00, then show such n such value.
Basically my use case is that I’ve made my own circadian lighting automations that change brightness and color_temp. Currently I have a different automation for each time of day and each device. While it works, it’s not very sexy and is LOTS of code (19 automations per device and 4 devices). I created these when I wasn’t as skilled with HA, so I’m trying to go back and clean it up.
To head off the suggestions at the pass pointing me to other options:
I’ve tried the flux component and the circadian lighting custom component. Both are fine, but I’m not crazy about the actual lighting (Flux seemed to be too pink most of the time and CL didn’t give me enough control. I also like my nightlights to be red rather than ‘starry sky’ white).
This post shows an example for the hours only like this
{% set current_hour = strptime(states('sensor.time'), "%H:%M").hour %}
{% if current_hour < 12 %}
Morning
{% elif 12 <= current_hour < 18 %}
Afternoon
{% else %}
Evening
{% endif %}
That’s fine, except I would like the times to also include minutes (or at least half hours) so I can change the sensor value on the half hour as well.
I’ve also tried this from another post
{% if as_timestamp(now()) > as_timestamp(states.sensor.date.state ~ ' 05:00:00') %}
25
{% elif as_timestamp(now()) > as_timestamp(states.sensor.date.state ~ ' 05:30:00') %}
50
#........continued for rest of day............
{% else %}
1
{% endif %}
When typing this into the template editor, it only shows the first value of “25” and doesn’t change at 5:30 to the next value. Makes sense. Overnight it shows the “else” value until 5a again.
So any suggestions? Or am I going about this the wrong way?
Thanks in advance!