Add configurable minutes to time stored in an input.datetime

After many hours of research, and attempts, I can’t figure it out. Any input would be greatly appreciated!

Goal: I have a set time for my kids to wake up on weekends and week days. At times, I want to delay the wake-up time by a configurable number of minutes.

I believe I found a way to add a configurable delay that is only active if the “Delay Kids’ Wake-up” is on. Soon I will make it so the switch resets to off once the delay is over so that it will not apply the next day.

PROBLEM: I would like to calculate the adjusted wake up time and store it in an input_datetime for use elsewhere and possibly to simplify the node red sequence below.

In the snapshot above, I’d like 00:00 to show 10:00 given the delay is configured to 60 minutes and the wake up time is set at 9:00. I don’t want to do this via a template for the reason mentioned above.

The node red code I was testing was using “current state” to grab wake up time and delay, and then I had a function trying to do the calculation but I never even got close so I did not include the code.

[{"id":"736f6074eb310fd7","type":"ha-time","z":"44181540ccea04aa","name":"Awake Mode - Week - Start (Kids)","server":"6f1799ba.17e938","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.awake_mode_week_start_kids","property":"","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"sunday":false,"monday":true,"tuesday":true,"wednesday":true,"thursday":true,"friday":true,"saturday":false,"debugenabled":true,"x":200,"y":960,"wires":[["6348548611748eb4"]]},{"id":"3b9e05d62d77bcab","type":"ha-time","z":"44181540ccea04aa","name":"Awake Mode - Weekend - Start (Kids)","server":"6f1799ba.17e938","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.awake_mode_weekend_start_kids","property":"","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"sunday":true,"monday":false,"tuesday":false,"wednesday":false,"thursday":false,"friday":false,"saturday":true,"debugenabled":true,"x":210,"y":1040,"wires":[["6348548611748eb4"]]},{"id":"bb07dead69144c02","type":"api-call-service","z":"44181540ccea04aa","name":"Kids Mode - Awake","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.kids_mode","data":"{\"option\":\"Awake\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1370,"y":1000,"wires":[[]]},{"id":"6348548611748eb4","type":"api-current-state","z":"44181540ccea04aa","name":"Delay Kids Wakeup - On?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wakeup","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":530,"y":1000,"wires":[["7c1c2ca08c8525b9"],["bb07dead69144c02","2b69ca446cdef536"]]},{"id":"fc3959b81a986c08","type":"delay","z":"44181540ccea04aa","name":"","pauseType":"delayv","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"allowrate":false,"x":1160,"y":940,"wires":[["bb07dead69144c02"]]},{"id":"7c1c2ca08c8525b9","type":"api-current-state","z":"44181540ccea04aa","name":"Kids Wake Up Delay (min)","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_select.wake_up_delay","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":790,"y":880,"wires":[["7c77fd1951559c1c"]]},{"id":"7c77fd1951559c1c","type":"function","z":"44181540ccea04aa","name":"min to ms","func":"msg.delay = msg.payload * 60 * 1000 ;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1000,"y":880,"wires":[["fc3959b81a986c08"]]},{"id":"7e846d82c73e869e","type":"server-state-changed","z":"44181540ccea04aa","name":"Delay Kids Wake-up","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.delay_kids_wakeup","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":250,"y":880,"wires":[["7c1c2ca08c8525b9"],["3fa14809cad4ca68"]]},{"id":"3fa14809cad4ca68","type":"change","z":"44181540ccea04aa","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":940,"wires":[["fc3959b81a986c08"]]},{"id":"2a55afc09ce73761","type":"api-call-service","z":"44181540ccea04aa","name":"Adjusted Kids Wake-Up Time","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.adjusted_kids_wake_up_time","data":"{\"time\":\"11:02:35\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":980,"y":1080,"wires":[["84c69448af00ae23"]]},{"id":"2b69ca446cdef536","type":"change","z":"44181540ccea04aa","name":"Set Time","rules":[{"t":"set","p":"data","pt":"msg","to":"01:37:00","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":740,"y":1080,"wires":[["2a55afc09ce73761"]]},{"id":"84c69448af00ae23","type":"debug","z":"44181540ccea04aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1270,"y":1080,"wires":[]},{"id":"c553f2a16965eeb3","type":"inject","z":"44181540ccea04aa","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":550,"y":1080,"wires":[["2b69ca446cdef536"]]},{"id":"6f1799ba.17e938","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

In case this matters, this is one of my input_datetime that I am using to hold the wake up time.

You could move the offset into the time node using something like

$entities("input_boolean.delay_kids_wakeup").state = "on" ? $entities("input_select.wake_up_delay").state : 0

edit:

Set adjusted time

[{"id":"28923cd8f7c8e9cc","type":"api-current-state","z":"43077264f8f2867f","name":"delay","server":"","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wakeup","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"delay","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":594,"y":688,"wires":[["277c799bcca86f83"]]},{"id":"508d3f260ea7a173","type":"server-state-changed","z":"43077264f8f2867f","name":"Adjusted Time","server":"","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.awake_mode_week_start_kids,input_boolean.delay_kids_wakeup,input_select.wake_up_delay","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":294,"y":688,"wires":[["d0eb2e034631d560"]]},{"id":"277c799bcca86f83","type":"api-current-state","z":"43077264f8f2867f","name":"amount","server":"","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_select.wake_up_delay","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":748,"y":688,"wires":[["40919cf2dffe40cf"]]},{"id":"3b055b430a9bd905","type":"api-call-service","z":"43077264f8f2867f","name":"Adjusted Kids Wake-Up Time","server":"","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.adjusted_kids_wake_up_time","data":"{\"time\": payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1096,"y":688,"wires":[[]]},{"id":"40919cf2dffe40cf","type":"function","z":"43077264f8f2867f","name":"time","func":"const delay = msg.delay == \"on\" ? msg.payload * 60 : 0;\nconst alarm = (msg.alarm + delay) * 1000;\nconst adjusted = new Date(alarm);\nmsg.payload = adjusted.toISOString().split('T')[1].split('.')[0];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":882,"y":688,"wires":[["3b055b430a9bd905"]]},{"id":"d0eb2e034631d560","type":"api-current-state","z":"43077264f8f2867f","name":"alarm","server":"","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.awake_mode_week_start_kids","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"alarm","propertyType":"msg","value":"$entity().attributes.timestamp","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":450,"y":688,"wires":[["28923cd8f7c8e9cc"]]}]
1 Like

Hi there you can achieve this with the following template also. You will have to call the template and use the payload to set the value for date time. Instead of nodered you can also achieve this in HA automations.

{{(state_attr('input_datetime.awake_mode_weekend_start_kids' , 'timestamp')+ (states('input_select.wake_up_delay')|int * 60))|timestamp_custom('%H:%M:%S', false)}}
2 Likes

@Kermit - You are awesome! I will study your code to fully understand it, anyhow it worked as I was hoping simply by importing the sequence into the flow! Thank you so much!

I wish some of what you did were documented better online, or at least, easier to find. I spent many hours researching and could not find anything that looks similar to what you did.

On a side note, I noticed you referenced multiple entities on the “Adjusted Time” node. While it saves space and reduces visual complexity, is there any drawback to having the two entities in their own individual “events: state” nodes? The reason I prefer them being separate is simply for readability of the code. Another case, where I split things out is turning on multiple lights - each one will have its own ‘call service’ node (vs listing all lights within one node). Is doing so penalizing performance?

@sheminasalam - Thank you for the template code! While I was trying to not use a template for this specific automation, your code is of great value and use to me for other things I am thinking of implementing, so thank you for sharing!!

The first part is just using JSONata with the custom function available in the HA nodes https://zachowj.github.io/node-red-contrib-home-assistant-websocket/guide/jsonata.html

Every event node is going to add a little overhead in memory and processing when an event arrives from HA. What’s that amount? Probably really small I’ve never looked into it.

Each call-service node would make an individual call to HA where a single one using a delimited list of ids would only make a single call. Once again probably not going to be noticed by the normal user, but definitely more overhead.

Here’s a link to how many service calls I could do without killing my HA instance. https://community.home-assistant.io/t/que-messages-and-send-with-specific-rate/334457/3?u=kermit

@Kermit - Thank you for the help and information! I have lots to learn and it is of great help to be pointed in the right direction.

My project has evolved a bit and my current difficulties are likely due to me not fully understanding the innerworkings of time / date in JavaScript.

This is the latest version of the configuration “panel” for the kids morning wake up routine. In a different tab I have input.datetime entities holding the alarm time for week days and weekends. The “Kids Wake-Up Time” alarm time must match whether the next day (if we are looking at this before midnight) is a school day or not. I used the workday integration for this and have two sensors setup for today and tomorrow.

The “Next Alarm” filed should reflect when the alarm being set applies. Displaying it is not necessary but I use this logic to determine what the default wake up time is so why not show it too. The logic is that if now() is after the alarm time (default or adjusted depending on toggle) then it should show “Tomorrow” as long as it is before midnight. Between midnight and the alarm time (default or adjusted depending on toggle), then it should show “Today”.

Taken at 10am:

Delay is off, so since the applicable alarm time is in the past, it correctly shows tomorrow along with using tomorrow’s correct wake up time (8.30 temporarily later than normal for testing).

If I turn on the delay, the “Kids Wake-Up Time” updates to the weekend default time (8.45 temporarily later than normal for testing) and since the delay is set to 120 minutes, the adjusted alarm time is 10.45. Since it is now 10am, the Next Alarm is set to Today.

As soon as the alarm goes off, the default alarm time should revert to 8.30, and Next Alarm to Tomorrow (Monday).

For the most part this works, but while trying to figure this out, I’ve seen the Today/Tomorrow not update when desired so there is something wrong with how I look at dates and compare them. I am neck deep in web pages discussing time, and date processing in JavaScript but I can’t seem to find how to just look at time discarding date. I suspect the date changing as time passes is screwing this up (due to bad logic…).

[{"id":"28923cd8f7c8e9cc","type":"api-current-state","z":"44181540ccea04aa","name":"Delay Kids Wake-up","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wake_up","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"delay","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1300,"y":1160,"wires":[["277c799bcca86f83"]]},{"id":"508d3f260ea7a173","type":"server-state-changed","z":"44181540ccea04aa","name":"Wake Up Delay (min)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.wake_up_delay","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":220,"y":1100,"wires":[["bb061668327dd2f1"]]},{"id":"277c799bcca86f83","type":"api-current-state","z":"44181540ccea04aa","name":"Wake Up Delay (min)","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_select.wake_up_delay","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1540,"y":1160,"wires":[["40919cf2dffe40cf"]]},{"id":"3b055b430a9bd905","type":"api-call-service","z":"44181540ccea04aa","name":"Adjusted Kids Wake-Up Time","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.adjusted_kids_wake_up_time","data":"{\"time\": payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1560,"y":1080,"wires":[[]]},{"id":"40919cf2dffe40cf","type":"function","z":"44181540ccea04aa","name":"time","func":"const delay = msg.delay == \"on\" ? msg.payload * 60 : 0;\nconst alarm = (msg.alarm + delay) * 1000;\nconst adjusted = new Date(alarm);\n\nmsg.payload = adjusted.toISOString().split('T')[1].split('.')[0];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1730,"y":1160,"wires":[["3b055b430a9bd905"]]},{"id":"d0eb2e034631d560","type":"api-current-state","z":"44181540ccea04aa","name":"Awake Mode Week Start Kids","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.awake_mode_week_start_kids","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"alarm","propertyType":"msg","value":"$entity().attributes.timestamp","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":970,"y":1160,"wires":[["28923cd8f7c8e9cc","67382ca028721bfc"]]},{"id":"1e985f61d47f2c03","type":"server-state-changed","z":"44181540ccea04aa","name":"Awake Mode - Week - Start (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.awake_mode_week_start_kids","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":180,"y":980,"wires":[["bb061668327dd2f1"]]},{"id":"49f885c82e3b9a38","type":"server-state-changed","z":"44181540ccea04aa","name":"Delay Kids Wake-up","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.delay_kids_wake_up","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":230,"y":1160,"wires":[["bb061668327dd2f1"]]},{"id":"1181df040a902c4a","type":"api-current-state","z":"44181540ccea04aa","name":"Awake Mode Weekend Start Kids","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.awake_mode_weekend_start_kids","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"alarm","propertyType":"msg","value":"$entity().attributes.timestamp","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":980,"y":1240,"wires":[["28923cd8f7c8e9cc","67382ca028721bfc"]]},{"id":"ad3bcaffebd2fc38","type":"ha-time","z":"44181540ccea04aa","name":"Adjusted Kids Wake-Up Time","server":"6f1799ba.17e938","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.adjusted_kids_wake_up_time","property":"","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"sunday":true,"monday":true,"tuesday":true,"wednesday":true,"thursday":true,"friday":true,"saturday":true,"debugenabled":false,"x":200,"y":1360,"wires":[["0ef95a7847b288db","eee677ab4511eafa","bb061668327dd2f1"]]},{"id":"30e591830692a445","type":"server-state-changed","z":"44181540ccea04aa","name":"Awake Mode - Weekend - Start (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.awake_mode_weekend_start_kids","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":170,"y":920,"wires":[["bb061668327dd2f1"]]},{"id":"6cf7326c0f33bc2d","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.next_wake_up_alarm_kids","data":"{\"time\": payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":1240,"wires":[[]]},{"id":"67382ca028721bfc","type":"function","z":"44181540ccea04aa","name":"time","func":"const alarm = msg.alarm * 1000;\nconst adjusted = new Date(alarm);\n\nmsg.payload = adjusted.toISOString().split('T')[1].split('.')[0];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1250,"y":1240,"wires":[["6cf7326c0f33bc2d"]]},{"id":"0ef95a7847b288db","type":"api-call-service","z":"44181540ccea04aa","name":"Kids Mode - Awake","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.kids_mode","data":"{\"option\":\"Awake\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":550,"y":1360,"wires":[[]]},{"id":"68d015c35725b1a5","type":"function","z":"44181540ccea04aa","name":"Compare Times","func":"var adjAlarm = msg.adjAlarm\nvar adjAlarmTS = (new Date(adjAlarm)).getTime();\nvar Alarm = adjAlarm.toLocaleString('en-US', {hour12: false});\n\nvar lastMidnightUTC = new Date();\nlastMidnightUTC.setHours(0,0,0,0);\nvar lastMidnight = lastMidnightUTC.toLocaleString('en-US', {hour12: false});\nvar lastMidnightTS = lastMidnightUTC.getTime();\n\nvar nextMidnightUTC = new Date();\nnextMidnightUTC.setHours(24,0,0,0);\nvar nextMidnight = nextMidnightUTC.toLocaleString('en-US', {hour12: false});\nvar nextMidnightTS = nextMidnightUTC.getTime();\n\n/*\nvar testvar = new Date();\nvar testvar2 = testvar.getTime();\n*/\n\nvar nowUTC = new Date();\nvar now = nowUTC.toLocaleString('en-US', {hour12: false});\nvar nowTS = nowUTC.getTime();\n\n\n/*\nnearest midnight in the past:\nvar d = new Date();\nd.setHours(0,0,0,0); // last midnight\n\nnearest midnight in future:\nvar d = new Date();\nd.setHours(24,0,0,0); // next midnight\n*/\n\n/*\nvar d=new Date();\nvar currentTime2=d.getTime()\n\nd=new Date();\ntime2=d.getTime()\n*/\n\nif(nowTS >= lastMidnightTS && nowTS <= adjAlarmTS) {\n    msg.payload = \"Today\";\n} else {\n    msg.payload = \"Tomorrow\";\n}\n\nvar debugMSG = {payload: msg.payload, nowTS, now, lastMidnightTS, lastMidnight, nextMidnightTS, nextMidnight, adjAlarmTS, Alarm};\n\nreturn debugMSG;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1000,"wires":[["dcce2857ebb3edfa","6903a374149c7e92"]]},{"id":"dcce2857ebb3edfa","type":"switch","z":"44181540ccea04aa","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Today","vt":"str"},{"t":"eq","v":"Tomorrow","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":730,"y":1000,"wires":[["c0cf7572ff286da7"],["9cf435f4548a6b1f"]]},{"id":"c0cf7572ff286da7","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm Kids - Today","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.next_wake_up_alarm_kids","data":"{\"option\":\"Today\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1000,"y":980,"wires":[["c247a3a6747436de"]]},{"id":"9cf435f4548a6b1f","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm Kids - Tomorrow","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.next_wake_up_alarm_kids","data":"{\"option\":\"Tomorrow\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":1040,"wires":[["4a4073c5b8678d13"]]},{"id":"6903a374149c7e92","type":"debug","z":"44181540ccea04aa","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":530,"y":1060,"wires":[]},{"id":"405e4133fe0e5843","type":"server-state-changed","z":"44181540ccea04aa","name":"Adjusted Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.adjusted_kids_wake_up_time","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"true","valueType":"bool"}],"x":190,"y":1040,"wires":[["bb061668327dd2f1"]]},{"id":"7f7284cea7358d6f","type":"inject","z":"44181540ccea04aa","name":"Midnight","props":[{"p":"midnight","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"","x":260,"y":1220,"wires":[["bb061668327dd2f1"]]},{"id":"bb061668327dd2f1","type":"api-current-state","z":"44181540ccea04aa","name":"Adjusted Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.adjusted_kids_wake_up_time","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"adjAlarm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":570,"y":920,"wires":[["0f1c8112efe97a3c"]]},{"id":"55309cb8134b91ec","type":"api-call-service","z":"44181540ccea04aa","name":"Delay Kids Wake-up Auto Off >> Off","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.delay_kids_wake_up_auto_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":1500,"wires":[[]]},{"id":"03cbb8ad0dab4933","type":"api-call-service","z":"44181540ccea04aa","name":"Delay Kids Wake-up >> Off","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.delay_kids_wake_up","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":1440,"wires":[[]]},{"id":"c247a3a6747436de","type":"api-current-state","z":"44181540ccea04aa","name":"Workday Today?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.workday_today","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":550,"y":1160,"wires":[["d0eb2e034631d560"],["1181df040a902c4a"]]},{"id":"4a4073c5b8678d13","type":"api-current-state","z":"44181540ccea04aa","name":"Workday Tomorrow?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.workday_tomorrow","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":560,"y":1240,"wires":[["d0eb2e034631d560"],["1181df040a902c4a"]]},{"id":"0f1c8112efe97a3c","type":"moment","z":"44181540ccea04aa","name":"format time","topic":"","input":"adjAlarm","inputType":"msg","inTz":"America/Chicago","adjAmount":0,"adjType":"days","adjDir":"add","format":"date","locale":"en-US","output":"adjAlarm","outputType":"msg","outTz":"America/Chicago","x":810,"y":920,"wires":[["68d015c35725b1a5"]]},{"id":"eee677ab4511eafa","type":"api-current-state","z":"44181540ccea04aa","name":"Delay Kids Wake-up Auto Off - On?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wake_up_auto_off","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":600,"y":1440,"wires":[["03cbb8ad0dab4933","55309cb8134b91ec"],[]]},{"id":"6f1799ba.17e938","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

In configuration.yaml I have this:

- sensor:
      - name: "Kids Wake-Up Time"
        icon: "hass:clock-outline"
        state: "{{ state_attr('input_datetime.next_wake_up_alarm_kids', 'timestamp') | timestamp_custom('%H:%M', False, 0) }}"

  - sensor:
      - name: "Adjusted Kids Wake-Up Time"
        icon: "hass:clock-end"
        state: "{{ state_attr('input_datetime.adjusted_kids_wake_up_time', 'timestamp') | timestamp_custom('%H:%M', False, 0) }}"

  - sensor:
      - name: "Next Alarm"
        icon: "hass:alarm"
        state: >
          {% if is_state("input_select.next_wake_up_alarm_kids", "Today") %}
            Today
          {%- elif is_state("input_select.next_wake_up_alarm_kids", "Tomorrow") %}
            Tomorrow
          {% else %}
            Undefined
          {% endif %}

and

#Workday integration for today and tomorrow
#https://www.home-assistant.io/integrations/workday/
binary_sensor:
  - platform: workday
    name: workday_today
    country: US
    workdays: [mon, tue, wed, thu, fri]
    excludes: [sat, sun]
    add_holidays:
      - "2021-11-25"
      - "2021-12-24"
      - "2021-12-25"
      - "2021-12-31"
      - "2022-01-01"

  - platform: workday
    name: workday_tomorrow
    days_offset: 1
    country: US
    workdays: [mon, tue, wed, thu, fri]
    excludes: [sat, sun]
    add_holidays:
      - "2021-11-25"
      - "2021-12-24"
      - "2021-12-25"
      - "2021-12-31"
      - "2022-01-01"

This morning I was testing it as last night it was not working. After minor changes it appears to work but I suspect it will break again when dates change. This is the debug output (I have timestamp and human readable just to make it easier to read):

1/14/2021, 9:16:08 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Today", nowTS: 1636902968301, now: "11/14/2021, 09:16:08", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }
11/14/2021, 9:16:08 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Tomorrow", nowTS: 1636902968450, now: "11/14/2021, 09:16:08", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }
11/14/2021, 9:16:08 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Tomorrow", nowTS: 1636902968605, now: "11/14/2021, 09:16:08", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }
11/14/2021, 9:16:09 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Tomorrow", nowTS: 1636902969661, now: "11/14/2021, 09:16:09", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }
11/14/2021, 9:16:09 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Today", nowTS: 1636902969794, now: "11/14/2021, 09:16:09", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }
11/14/2021, 9:16:10 AMnode: 6903a374149c7e92
msg : Object
{ payload: "Today", nowTS: 1636902969955, now: "11/14/2021, 09:16:09", lastMidnightTS: 1636869600000, lastMidnight: "11/14/2021, 24:00:00" … }

The Node Red function that outputs this, and where I believe I have the issue is:

var adjAlarm = msg.adjAlarm
var adjAlarmTS = (new Date(adjAlarm)).getTime();
var Alarm = adjAlarm.toLocaleString('en-US', {hour12: false});

var lastMidnightUTC = new Date();
lastMidnightUTC.setHours(0,0,0,0);
var lastMidnight = lastMidnightUTC.toLocaleString('en-US', {hour12: false});
var lastMidnightTS = lastMidnightUTC.getTime();

var nextMidnightUTC = new Date();
nextMidnightUTC.setHours(24,0,0,0);
var nextMidnight = nextMidnightUTC.toLocaleString('en-US', {hour12: false});
var nextMidnightTS = nextMidnightUTC.getTime();

/*
var testvar = new Date();
var testvar2 = testvar.getTime();
*/

var nowUTC = new Date();
var now = nowUTC.toLocaleString('en-US', {hour12: false});
var nowTS = nowUTC.getTime();


/*
nearest midnight in the past:
var d = new Date();
d.setHours(0,0,0,0); // last midnight

nearest midnight in future:
var d = new Date();
d.setHours(24,0,0,0); // next midnight
*/

/*
var d=new Date();
var currentTime2=d.getTime()

d=new Date();
time2=d.getTime()
*/

if(nowTS >= lastMidnightTS && nowTS <= adjAlarmTS) {
    msg.payload = "Today";
} else {
    msg.payload = "Tomorrow";
}

var debugMSG = {payload: msg.payload, nowTS, now, lastMidnightTS, lastMidnight, nextMidnightTS, nextMidnight, adjAlarmTS, Alarm};

return debugMSG;

A lot of the code above is just part of my testing / attempts and not necessary.

I have been trying to get rid of all dates as I believe my issues are due to having to handle them. Unless my logic is incorrect, all I really care for is to know whether now() is between midnight and alarm time which means that the alarm is “Today” and now() is after alarm time and therefore before the next midnight, then it should reflect “Tomorrow”.

If I sound confused it is because I am :slight_smile: even though it sounds simple in my head…

BONUS: If I can get rid of the time formatting node that converts the time only input.datetime to a timestamp (or whatever I should be using), I would be happier as that way all the time/date handling is in the same place (function node).

Sorry for the super long post. The goal here is not only to make it easier for those willing to help me, but also to help others looking for information on home to do something similar. Once I get this working, I will share. Most of the posts I read only have small portions so trying to copy what they do it very hard…

EDIT: I keep feeling this whole thing would result in a loop given the number of things that affect eachother. I’ll try to give scenarios to clarify.

Scenarios:

Default week alarm: 08:00
Default Weekend alarm: 09:00

now() is 10:00 Sunday

Delay (120m) is OFF
Next Alarm: Tomorrow (current time is after 08:00)
Default Alarm: 08:00 (tomorrow is Monday…)
Adjusted Alarm: 08:00 (Next Alarm is Tomorrow since it is 10:00)

Delay (120m) is ON
Next Alarm: Today
Default Alarm: 09:00 (today is Sunday…)
Adjusted Alarm: 11:00 (Next Alarm is Today since it is 10:00)

I way over complicated this as I had not found, or realized, that I could pass time to the “Time Switch Node”. Once I found that node, it was uber easy to make this work. I would still love to know how it is done in JS but am happy with using the node too given it is available.

Sharing the sequence below in case it can help others :slight_smile:

[{"id":"28923cd8f7c8e9cc","type":"api-current-state","z":"44181540ccea04aa","name":"Delay Kids Wake-up","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wake_up","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"delay","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1300,"y":1160,"wires":[["277c799bcca86f83"]]},{"id":"508d3f260ea7a173","type":"server-state-changed","z":"44181540ccea04aa","name":"Wake Up Delay (min)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.wake_up_delay","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":220,"y":1100,"wires":[["bb061668327dd2f1"]]},{"id":"277c799bcca86f83","type":"api-current-state","z":"44181540ccea04aa","name":"Wake Up Delay (min)","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"num","halt_if_compare":"is","entity_id":"input_select.wake_up_delay","state_type":"num","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1540,"y":1160,"wires":[["40919cf2dffe40cf"]]},{"id":"3b055b430a9bd905","type":"api-call-service","z":"44181540ccea04aa","name":"Adjusted Kids Wake-Up Time","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.adjusted_kids_wake_up_time","data":"{\"time\": payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1560,"y":1080,"wires":[[]]},{"id":"40919cf2dffe40cf","type":"function","z":"44181540ccea04aa","name":"time","func":"const delay = msg.delay == \"on\" ? msg.payload * 60 : 0;\nconst alarm = (msg.alarm + delay) * 1000;\nconst adjusted = new Date(alarm);\n\nmsg.payload = adjusted.toISOString().split('T')[1].split('.')[0];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1730,"y":1160,"wires":[["3b055b430a9bd905"]]},{"id":"d0eb2e034631d560","type":"api-current-state","z":"44181540ccea04aa","name":"Awake Mode Week Start Kids","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.awake_mode_week_start_kids","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"alarm","propertyType":"msg","value":"$entity().attributes.timestamp","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":970,"y":1160,"wires":[["28923cd8f7c8e9cc","67382ca028721bfc"]]},{"id":"1e985f61d47f2c03","type":"server-state-changed","z":"44181540ccea04aa","name":"Awake Mode - Week - Start (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.awake_mode_week_start_kids","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":180,"y":980,"wires":[["bb061668327dd2f1"]]},{"id":"49f885c82e3b9a38","type":"server-state-changed","z":"44181540ccea04aa","name":"Delay Kids Wake-up","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_boolean.delay_kids_wake_up","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":230,"y":1160,"wires":[["bb061668327dd2f1"]]},{"id":"1181df040a902c4a","type":"api-current-state","z":"44181540ccea04aa","name":"Awake Mode Weekend Start Kids","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.awake_mode_weekend_start_kids","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"alarm","propertyType":"msg","value":"$entity().attributes.timestamp","valueType":"jsonata"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":980,"y":1240,"wires":[["28923cd8f7c8e9cc","67382ca028721bfc"]]},{"id":"ad3bcaffebd2fc38","type":"ha-time","z":"44181540ccea04aa","name":"Adjusted Kids Wake-Up Time","server":"6f1799ba.17e938","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityId":"input_datetime.adjusted_kids_wake_up_time","property":"","offset":0,"offsetType":"num","offsetUnits":"minutes","randomOffset":false,"repeatDaily":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"sunday":true,"monday":true,"tuesday":true,"wednesday":true,"thursday":true,"friday":true,"saturday":true,"debugenabled":false,"x":200,"y":1360,"wires":[["0ef95a7847b288db","eee677ab4511eafa","bb061668327dd2f1"]]},{"id":"30e591830692a445","type":"server-state-changed","z":"44181540ccea04aa","name":"Awake Mode - Weekend - Start (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.awake_mode_weekend_start_kids","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[],"x":170,"y":920,"wires":[["bb061668327dd2f1"]]},{"id":"6cf7326c0f33bc2d","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_datetime","service":"set_datetime","entityId":"input_datetime.next_wake_up_alarm_kids","data":"{\"time\": payload}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1460,"y":1240,"wires":[[]]},{"id":"67382ca028721bfc","type":"function","z":"44181540ccea04aa","name":"time","func":"const alarm = msg.alarm * 1000;\nconst adjusted = new Date(alarm);\n\nmsg.payload = adjusted.toISOString().split('T')[1].split('.')[0];\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1250,"y":1240,"wires":[["6cf7326c0f33bc2d"]]},{"id":"0ef95a7847b288db","type":"api-call-service","z":"44181540ccea04aa","name":"Kids Mode - Awake","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.kids_mode","data":"{\"option\":\"Awake\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":550,"y":1360,"wires":[[]]},{"id":"c0cf7572ff286da7","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm Kids - Today","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.next_wake_up_alarm_kids","data":"{\"option\":\"Today\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1000,"y":980,"wires":[["c247a3a6747436de"]]},{"id":"9cf435f4548a6b1f","type":"api-call-service","z":"44181540ccea04aa","name":"Next Wake-Up Alarm Kids - Tomorrow","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.next_wake_up_alarm_kids","data":"{\"option\":\"Tomorrow\"}","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1010,"y":1040,"wires":[["4a4073c5b8678d13"]]},{"id":"405e4133fe0e5843","type":"server-state-changed","z":"44181540ccea04aa","name":"Adjusted Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_datetime.adjusted_kids_wake_up_time","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"true","valueType":"bool"}],"x":190,"y":1040,"wires":[["bb061668327dd2f1"]]},{"id":"7f7284cea7358d6f","type":"inject","z":"44181540ccea04aa","name":"Midnight","props":[{"p":"midnight","v":"true","vt":"bool"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"01 00 * * *","once":false,"onceDelay":0.1,"topic":"","x":260,"y":1220,"wires":[["bb061668327dd2f1"]]},{"id":"bb061668327dd2f1","type":"api-current-state","z":"44181540ccea04aa","name":"Adjusted Wake-Up Alarm (Kids)","server":"6f1799ba.17e938","version":2,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_datetime.adjusted_kids_wake_up_time","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"adjAlarm","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":570,"y":920,"wires":[["665d68f4c45b9c11"]]},{"id":"55309cb8134b91ec","type":"api-call-service","z":"44181540ccea04aa","name":"Delay Kids Wake-up Auto Off >> Off","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.delay_kids_wake_up_auto_off","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":940,"y":1500,"wires":[[]]},{"id":"03cbb8ad0dab4933","type":"api-call-service","z":"44181540ccea04aa","name":"Delay Kids Wake-up >> Off","server":"6f1799ba.17e938","version":3,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.delay_kids_wake_up","data":"","dataType":"jsonata","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":920,"y":1440,"wires":[[]]},{"id":"c247a3a6747436de","type":"api-current-state","z":"44181540ccea04aa","name":"Workday Today?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.workday_today","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":550,"y":1160,"wires":[["d0eb2e034631d560"],["1181df040a902c4a"]]},{"id":"4a4073c5b8678d13","type":"api-current-state","z":"44181540ccea04aa","name":"Workday Tomorrow?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.workday_tomorrow","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":560,"y":1240,"wires":[["d0eb2e034631d560"],["1181df040a902c4a"]]},{"id":"eee677ab4511eafa","type":"api-current-state","z":"44181540ccea04aa","name":"Delay Kids Wake-up Auto Off - On?","server":"6f1799ba.17e938","version":2,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.delay_kids_wake_up_auto_off","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":600,"y":1440,"wires":[["03cbb8ad0dab4933","55309cb8134b91ec"],[]]},{"id":"665d68f4c45b9c11","type":"time-switch","z":"44181540ccea04aa","name":"Between Midnight and adjAlarm","lat":"30.49027","lon":"-97.56828","startTime":"00:00","endTime":"{{msg.adjAlarm}}","startOffset":0,"endOffset":0,"x":570,"y":1000,"wires":[["c0cf7572ff286da7"],["9cf435f4548a6b1f"]]},{"id":"6f1799ba.17e938","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

Next step is to refine what is likely rudimental code…