Hi
Everything in my HA depends on my work shifts.
I need a sensor that automatically “shows” me early, late or night shift every 3 weeks.
I played with {{ now().isocalendar()[1] }} and searched the forum but didn’t find a solution.
Does anyone have an idea how I can create a “work shift sensor”?
I assume, you are interested in setting up schedule every week automatically. right? you can move to next schedule with an automation using these services select_next, select_previous, select_first, select_last.
If you manually override it in any day, next time automation will pick it up and continue from that point.
Ahh, I see now, I was thinking like, you set the today’s shift into input_select once and with an automation to be run every midnight/week, you just push it forward.
I am leaning into input_select, because, to my experience, there is always a slight chance on moving shifts around.
But, I would share one fully template based example with you, give me some time.
{% set known_early_week_monday = strptime("2023-09-04","%Y-%m-%d") | as_local | as_timestamp %}
{% set now_as_timestap = today_at("00:00") | as_timestamp %}
{{ known_early_week_monday }}
{{ now_as_timestap }}
{% set weeks_diff = ((now_as_timestap - known_early_week_monday)/(86400*7))|round(0, "floor") %}
{{ weeks_diff }}
{% set modus = weeks_diff % 3 %}
{{ modus }}
{% if modus == 0 %}
Early
{% elif modus == 1 %}
Late
{% else %}
Night
{% endif %}
You need to store the beginning of shift, a known early shift week’s Monday date The rest will calculate the number of weeks difference. take modus of 3 and see how many shifts to move forward.