I offer you the following alternative solution. I tested it and it works.
- platform: template
sensors:
tod_light_level:
friendly_name: 'TOD Light Level'
value_template: >
{% set hours = [[0,500,1],[501,600,25],[601,630,65],[631,700,75],[701,730,125],[731,800,190],
[801,900,210],[901,1630,255],[1631,1700,255],[1701,1730,240],[1731,1800,235],
[1801,1830,225],[1831,1900,200],[1901,1930,175],[1931,2000,125],[2001,2030,115],
[2031,2100,110],[2101,2200,100],[2201,2230,85],[2231,2300,25],[2301,2359,1]] %}
{% set t = states('sensor.time').replace(':','')|int %}
{% for h in hours if h[0] <= t <= h[1] %}
{{h[2]}}
{% endfor %}
Here’s how it works:
-
hours
is a list. Each item in the list is also a list which represents a period of the day and the desired light level in this format:[start time, end time, light level]
. For example, a light level of240
between17:01
and17:30
is represented like this:[1701,1730,240]
- The
hours
list covers all hours of the day from00:00
to23:59
(represented as0
and2359
). - The current time comes from
sensor.time
. It’s converted to an integer value (08:15
becomes815
) and assigned to the variablet
. - A for-loop is used to iterate through all items in
hours
. However, it is constrained to iterate only for the condition wheret
is between the ‘start’ and ‘end’ time. That’s performed byif h[0] <= t <= h[1]
in the for-loop’s declaration. - The light level is reported from the matching item.