Sensor with 3 states for early-, late- and night shift

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”?

Thanks

You can create an input select (Dropdown) helper and store 3 different options there.

1 Like

I already thought about it. But switching every week is too complicated for me.

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.

1 Like

I was thinking more like:
´if {{ now().isocalendar()[1] }} = 1,4,7,10.... then early shift.....´

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.

1 Like

where can I find this: select_next, select_previous, select_first, select_last.?

these are services to be used in conjunction with input_select/Dropdown helper, check the first link I shared

1 Like

Look at this.

Post 3 might be interesting.
I think you just need to change the 2 to 3 to get what you want.

1 Like

definitely long way of doing what you want :slight_smile:

{% 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 :slight_smile: The rest will calculate the number of weeks difference. take modus of 3 and see how many shifts to move forward.

1 Like

This is not related to blueprints, so maybe that should be changed in the topic. However, this might help you when dealing with time…

2 Likes

This is another approach that might be useful. Found in HACS. You could set a weekly scheduled event to change the value of an input_select.

1 Like

Or this?

1 Like

Thank you all so much for the help