and an automation - 'if there is motion, and the time is between the ‘dark_mode_start’ and ‘dark_mode_end’ times, turn the hall lights on. I’ve snipped the full automation as it worked when the ‘condition’ was hardcoded to 23:30:00 and 07:00:00. But using value templates and input_time doesn’t trigger a thing!! Convinced it’s my time formatting here. On a side note, is there anyway to debug / console.write values out anywhere? I found the sample online and doctored it.
[edit] : will take a look at the TOD sensor as well tomorrow - can’t have too many options at the moment.
Cheers
[edit 2]
hate giving up. Because it spans midnight - the logic operator should be an ‘or’. Doh. Anyway - at least i can see where i am going now as i head off to bed :).
i think you can compare as strings as long as the hours / minutes have leading spaces - as
“01” will ‘sort’ before “02” and “23” will come after “22” if you sort based on they char values- which is standard. So ‘for now’, whilst i am sill getting my head around this, it works. It also, as you said, prevents me constructing a full date / timestamp and i can just use the hours.
Adding the date back in is a good method, but not sure your implementation will handle time spans that cross teh date line - eg. start at 11pm and end at 2am. I think you’re adding teh same ‘date’ onto the start and end - which is good for jobs that start / end same day.
I will definitely take a look at teh date handling / formatting here as when I was googling / searching it seems to be a very common problem.
If you have a 1 line template, and you put it on the same line as the value_template: then you don’t need the ‘>’ but you do need the external quotes (as Malcolm was sort of trying for).
If you use the multiline template with the ‘>’ = you don’t
If you are using input datetimes you never know what your users will put in to them (even if the user is you) so you always have to test.
Here is a sample test that I use for my switches (it is for two time slots in the day, but you get the idea) and it compares strings : -
value_template: >
{% set time = states('sensor.time') %}
{% set slt1en = is_state('input_boolean.ib_switch_pifi01_timeslot1_enable', 'on') %}
{% set slt1start = states('input_datetime.id_switch_pifi01_tmeslt1_on') [0:5] %}
{% set slt1stop = states('input_datetime.id_switch_pifi01_tmeslt1_off') [0:5] %}
{% set slt2en = is_state('input_boolean.ib_switch_pifi01_timeslot2_enable', 'on') %}
{% set slt2start = states('input_datetime.id_switch_pifi01_tmeslt2_on') [0:5] %}
{% set slt2stop = states('input_datetime.id_switch_pifi01_tmeslt2_off') [0:5] %}
{% set slt1on = (slt1start <= time < slt1stop) if (slt1start < slt1stop) else (slt1start <= time or time < slt1stop) %}
{% set slt2on = (slt2start <= time < slt2stop) if (slt2start < slt2stop) else (slt2start <= time or time < slt2stop) %}
{{ (slt1on and slt1en) or (slt2on and slt2en) }}
I am sort of trying for any successes where I can. I am trying to get fairly ‘wide’ across HA before i start doing real automations beyond testing with a few bulbs and sensors.
This is a great forum though - I hope in time I can contribute back.
My work schedule is screwy. I work a rotating 12 hour shift, 4 days on day shift, 4 days off, 4 days on night shift, 4 days off & then back to day shift. I just happen to be on night shift now.
I’ve been working a rotating schedule for so long I don’t know how I would act if I ever worked a straight day schedule. Between 10 years in the Navy and then working rotating shifts in various forms as factory maintenance I’ve been doing rotating shifts for almost 35 years.
I think I’ll probably need to keep on a rotating “shift” even after I retire in a few years or my head will probably explode…
Maybe someone will be interested in my solution.
I have create 2 input_datetime helpers.
And next I have defined binary_sensor which is working like TOD.
Code of binary_sensor below: