HA Node Red swing shift schedule

So I work a 4 week swing shift schedule: Fri-Mon night, then Fri-Sun day, then Tues-thurs night, then Mon- Thurs day, and finally off for a week to start over Fri night. I’m looking to automate some home features using Node red, but I’m really new to this and haven’t really found the best solution. Anyone have any suggestions (for the time triggers, I can figure out the automation part)? I thought about triggering it from my Google calendar, but I’m not really sure I trust it since it only downloads when HA restarts and there seems to be many workdays not showing up.

Thanks

This Node Red UI scheduler palette may help

time-scheduler-demo

If schedules are more complex, the Google calendar route might work too

This may help too

Thanks for the suggestions. The problem I’m having with these is that UI Scheduler only does days of the week; every week of my 4 week rotation is different and within a month end up working every shift of the week (7 day shifts and 7 night shifts). I’ve also looked at the big timer previously, and while I could go through my schedule every year and mark my dates, that seems like a lot of work for automation.

Is there a node that I’m missing that can let me add a manual date/ time input that I could use with a repeat every 4 weeks? So for example, I input a date, lets say tomorrow, 7/30/2021, because it’s my first night back, and set it to repeat every 4 weeks into the foreseeable future? I could do that for each individual work day to run a day or night routine. Setting up 14 individual days seems easier that every work day a year in big timer, and more reliable than Google calendars (does anyone actually use Google Calendar events for running automations?? Reliable??)

It might be be worth thinking about doing it a different way. I have an input select that has 3 modes - away, home, and night. That is used as conditions for most of my automations. I have a job where I travel, work from home, and go to the office. The input select “mode” changes based on device presence or if certain lights are on in the house at certain times.

Maybe you can create modes for day shift, night shift, and not working, and have those modes trigger by device presence or crossing a work location zone you create with the mobile app, motion sensors, lights being on/off or some combination. Then your automations trigger based on what mode/state the input select is in. That would be easier then trying to program a schedule or try and have node red keep track of a schedule for 4 weeks through system restarts.

This should work, I’m fairly new at this though. So set the date to the last time your shift changes. Inject it it will add 4 weeks and store the value.

The second inject will send a time stamp that will be compared to the date stored. If the timestamp injected is > the stored date it will output on through msg.date_time_now. Then it will send a timestamp that will have 4 weeks added to it, starting the cycle over.

You need to enable context storage to ensure that the date is saved through restarts and updates.

[{"id":"b8e1cab0.ea723","type":"inject","z":"7d105d71.cc18e4","name":"Set daily check time","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":370,"y":3220,"wires":[["e068dee8.1969c"]]},{"id":"e068dee8.1969c","type":"function","z":"7d105d71.cc18e4","name":"date checker","func":"var date_time = context.get(\"future_date\"); //change \"future_date\" for each instance\n\nif(msg.topic == \"set\") {\n    date_time = msg.payload;\n} else if (msg.payload >= date_time) {\n    date_time_now = \"on\";\n} else {\n    date_time_now = \"off\";\n}\ncontext.set(\"future_date\", date_time); //change \"future_date\" for each instance\nnode.status({ text: date_time_now });\n\nmsg.date_time_now = date_time_now; \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":995,"y":3220,"wires":[["e001e920.a9d21"]],"icon":"node-red-dashboard/ui_dropdown.png","l":false},{"id":"1080caa7.f9f055","type":"inject","z":"7d105d71.cc18e4","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"*/1 0 * * *","once":false,"onceDelay":0.1,"topic":"","payload":"2021-04-16","payloadType":"str","x":170,"y":3060,"wires":[["5813a7c1.38ccc8"]]},{"id":"ff5bba43.29bf78","type":"change","z":"7d105d71.cc18e4","name":"set timestamp","rules":[{"t":"set","p":"topic","pt":"msg","to":"set","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":3180,"wires":[["e068dee8.1969c"]]},{"id":"5813a7c1.38ccc8","type":"function","z":"7d105d71.cc18e4","name":"Convert to timestamp","func":"p = msg.payload;\nmsg.payload= Date.parse(p);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":3060,"wires":[["de35e328.267e2"]]},{"id":"796f3459.f435ac","type":"debug","z":"7d105d71.cc18e4","name":"\"on\", sent once every 4 weeks","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1290,"y":3060,"wires":[]},{"id":"de35e328.267e2","type":"moment","z":"7d105d71.cc18e4","name":"","topic":"","input":"payload","inputType":"msg","inTz":"America/New_York","adjAmount":"04","adjType":"weeks","adjDir":"add","format":"x","locale":"C","output":"payload","outputType":"msg","outTz":"America/New_York","x":760,"y":3060,"wires":[["ff5bba43.29bf78"]]},{"id":"e001e920.a9d21","type":"switch","z":"7d105d71.cc18e4","name":"","property":"date_time_now","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1170,"y":3220,"wires":[["de35e328.267e2","796f3459.f435ac"],[]]},{"id":"7ba58f52.e395f","type":"comment","z":"7d105d71.cc18e4","name":"set start date of most recent shift change, keep the same format.","info":"","x":290,"y":2980,"wires":[]}]

https://nodered.org/docs/user-guide/context#saving-context-data-to-the-file-system

1 Like

Hey, I think you’re on to something here! I’ll play around with it tonight and see how it works but this looks like what I was thinking. thanks.