what is the exact logic that you’re trying to achieve which doesn’t work with the above?
the way you currently wrote it, if the time is within one of the ranges, then the condition would return true as at least 1 condition is true (set with OR)
I assumed {{ input_datetime.lounge_ac_am_on_time }} would have to be in a condition: template rather than condition: time to actually evaluate. Though I haven’t tested it yet.
@tom_l I’ve never used input_datetimes, so if they have timestamps then it’s even easier. Assuming the timestamp has today’s date.
Also, you don’t need default(0) when using this method because strings converted to int’s default to zero when it can’t convert (if the string returns any character that’s not a number).
condition:
- condition: template
value_template: >
{% set current_time = now().timestamp() %}
{% set am_start = states('input_datetime.lounge_ac_am_on_time', 'timestamp') | int %}
{% set am_end = states('input_datetime.lounge_ac_am_on_time', 'timestamp') | int %}
{% set pm_start = states('input_datetime.lounge_ac_am_on_time', 'timestamp') | int %}
{% set pm_end = states('input_datetime.lounge_ac_am_on_time', 'timestamp') | int %}
{{ am_start <= current_time <= am_end or pm_start <= current_time <= pm_end }}
So I was attempting to adapt it for a condition for a range of times.
However I have just discovered an errant “)” in a completely unrelated automation miles away from where I was working that wasn’t there when I validated the config yesterday. This was causing errors unrelated to this current effort. Ugh.
It is unlikely that my time ranges will ever cross a date boundary but I like the the idea of accounting for it just in case.
Thank you both for your ideas. I’ll have a bit of an experiment and let you know how I go.
Oh good lord. There’s another problem I’ve just disovered in my action template,
This:
{% if (states.input_select.lounge_ac_mode.state != 'Normal Cool')%}
Needs to account for ‘Silent Cool’ and ‘Powerful Cool’ as well. Is there a way to test for the string ‘Cool’ in states.input_select.lounge_ac_mode.state?