Detecting Sleep States – Switch Not Providing Output

Hi all,

I’m in the process of moving my automations from Home Assistant Automations to Node-RED and I’m working on one that checks whether specific conditions are met to determine if someone is sleeping.

The conditions I’m checking are:

• Phone is at home
• Phone is charging
• Phone is on silent

If all three conditions are true, it indicates the person is sleeping. I’m doing this for two phones (Mr and Mrs), and I want the automation to have three possible outputs:

  1. Both people are sleeping
  2. One person is sleeping
  3. Neither is sleeping

However, I’m running into an issue where the switch isn’t giving any output. Below is the flow structure I’ve set up and the exported code.

Could anyone help identify why the switch isn’t providing any output and how I can fix the node configurations? Also, is there any way to streamline this flow to make it more efficient?

Thanks in advance for your help!

[{"id":"ba9fdde779b44998","type":"tab","label":"Flow 5","disabled":false,"info":"","env":[]},{"id":"31f9a5de436dff62","type":"junction","z":"ba9fdde779b44998","x":320,"y":260,"wires":[["908a188c753387a5","ec9e9465c28b7a10","a0b3d83ca59994bd","5d95a570e4019349","7f9546ca7fdae603","9edc8523b3881144"]]},{"id":"daa4356a5afe015b","type":"junction","z":"ba9fdde779b44998","x":940,"y":260,"wires":[["df334ef1aadba2f3","e2304e9da0d57e3b"]]},{"id":"908a188c753387a5","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mr at Home","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","entity_id":"person.rpc","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"home","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":80,"wires":[["b32ea532f98a260d","1c41698ff379104a"],[]]},{"id":"ec9e9465c28b7a10","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mr charging ","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.the_mr_is_charging","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"charging","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":140,"wires":[["7c1ece4d1b470355","1c41698ff379104a"],[]]},{"id":"2bd2a6b3a782be96","type":"function","z":"ba9fdde779b44998","name":"Is the Mr Sleeping","func":"// Ensure the joined payload contains the correct topics\nlet atHomeState = msg.payload.home || \"\"; // Access 'home' value\nlet chargingState = msg.payload.charging || \"\"; // Access 'charging' value\nlet silentState = msg.payload.silent || \"\"; // Access 'silent' value\n\n// Log the cleaned-up values for verification\nnode.warn(\"atHomeState: \" + atHomeState);\nnode.warn(\"chargingState: \" + chargingState);\nnode.warn(\"silentState: \" + silentState);\n\n// Check if all three conditions are met\nif (atHomeState === \"home\" && chargingState === \"on\" && silentState === \"silent\") {\n msg.payload = { \"Mr\": \"true\" }; // Mr is sleeping\n} else {\n msg.payload = { \"Mr\": \"false\" }; // Mr is not sleeping\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":140,"wires":[["d0a1522378dd12d4","daa4356a5afe015b"]]},{"id":"b32ea532f98a260d","type":"debug","z":"ba9fdde779b44998","name":"Mr Home","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":60,"wires":[]},{"id":"7c1ece4d1b470355","type":"debug","z":"ba9fdde779b44998","name":"Mr Charging","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":100,"wires":[]},{"id":"d0a1522378dd12d4","type":"debug","z":"ba9fdde779b44998","name":"Mr is sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":80,"wires":[]},{"id":"1c41698ff379104a","type":"join","z":"ba9fdde779b44998","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":140,"wires":[["2bd2a6b3a782be96","dde38d4141093b53"]]},{"id":"dde38d4141093b53","type":"debug","z":"ba9fdde779b44998","name":"Mr join debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":840,"y":180,"wires":[]},{"id":"a0b3d83ca59994bd","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mr on Silent","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"silent","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.the_mr_ringer_mode","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"silent","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":470,"y":200,"wires":[["c6b60d5a7bc9e764","1c41698ff379104a"],[]]},{"id":"c6b60d5a7bc9e764","type":"debug","z":"ba9fdde779b44998","name":"Mr Silent","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":680,"y":220,"wires":[]},{"id":"7f9546ca7fdae603","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mrs charging ","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.the_mrs_is_charging","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"charging","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":450,"y":400,"wires":[["087c6389e0419ed7","3b8ed8169cb3b87a"],[]]},{"id":"5d95a570e4019349","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mrs at Home","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"home","halt_if_type":"str","halt_if_compare":"is","entity_id":"person.the_mrs","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"home","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":450,"y":340,"wires":[["206ce60acb5c6983","087c6389e0419ed7"],[]]},{"id":"a86048a7ae55c5bc","type":"function","z":"ba9fdde779b44998","name":"Is the Mrs Sleeping","func":"// Ensure the joined payload contains the correct topics\nlet atHomeState = msg.payload.home || \"\"; // Access 'home' value\nlet chargingState = msg.payload.charging || \"\"; // Access 'charging' value\nlet silentState = msg.payload.silent || \"\"; // Access 'silent' value\n\n// Log the cleaned-up values for verification\nnode.warn(\"atHomeState: \" + atHomeState);\nnode.warn(\"chargingState: \" + chargingState);\nnode.warn(\"silentState: \" + silentState);\n\n// Check if all three conditions are met\nif (atHomeState === \"home\" && chargingState === \"on\" && silentState === \"silent\") {\n msg.payload = { \"Mrs\": \"true\" }; // Mrs is sleeping\n} else {\n msg.payload = { \"Mrs\": \"false\" }; // Mrs is not sleeping\n}\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":870,"y":360,"wires":[["cefbfa6cf1a67c93","daa4356a5afe015b"]]},{"id":"206ce60acb5c6983","type":"debug","z":"ba9fdde779b44998","name":"Mrs Home","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":280,"wires":[]},{"id":"3b8ed8169cb3b87a","type":"debug","z":"ba9fdde779b44998","name":"Mrs Charge","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":670,"y":320,"wires":[]},{"id":"cefbfa6cf1a67c93","type":"debug","z":"ba9fdde779b44998","name":"Mrs is sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":880,"y":420,"wires":[]},{"id":"087c6389e0419ed7","type":"join","z":"ba9fdde779b44998","name":"","mode":"custom","build":"object","property":"payload","propertyType":"msg","key":"topic","joiner":"\\n","joinerType":"str","useparts":false,"accumulate":true,"timeout":"","count":"3","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":670,"y":380,"wires":[["a86048a7ae55c5bc","be19e113bd84558b"]]},{"id":"be19e113bd84558b","type":"debug","z":"ba9fdde779b44998","name":"Mrs join debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":860,"y":460,"wires":[]},{"id":"9edc8523b3881144","type":"api-current-state","z":"ba9fdde779b44998","name":"Is the Mrs on Silent","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"silent","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.the_mrs_ringer_mode","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"topic","propertyType":"msg","value":"silent","valueType":"str"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":450,"y":460,"wires":[["9bd63c3521cf8df7","087c6389e0419ed7"],[]]},{"id":"9bd63c3521cf8df7","type":"debug","z":"ba9fdde779b44998","name":"Mrs Silent","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":660,"y":440,"wires":[]},{"id":"8b478b3fbcf39552","type":"inject","z":"ba9fdde779b44998","name":"Start","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":310,"y":20,"wires":[["31f9a5de436dff62"]]},{"id":"e2304e9da0d57e3b","type":"debug","z":"ba9fdde779b44998","name":"debug before switch","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1140,"y":100,"wires":[]},{"id":"df334ef1aadba2f3","type":"switch","z":"ba9fdde779b44998","name":"Anyone sleeping","property":"msg.payload","propertyType":"jsonata","rules":[{"t":"jsonata_exp","v":"payload.Mr = \"true\" and payload.Mrs = \"true\"","vt":"jsonata"},{"t":"jsonata_exp","v":"(payload.Mr = \"true\" and payload.Mrs = \"false\") or (payload.Mr = \"false\" and payload.Mrs = \"true\")","vt":"jsonata"},{"t":"jsonata_exp","v":"payload.Mr = \"false\" and payload.Mrs = \"false\"","vt":"jsonata"}],"checkall":"true","repair":false,"outputs":3,"x":1080,"y":260,"wires":[["e2b8e4e411f6d0e6"],["ce35d50d91ef2ef0"],["8b34c2af1e7ce2e1"]],"outputLabels":["Both are sleeping","One sleeping, other not","Neither is sleeping"]},{"id":"e2b8e4e411f6d0e6","type":"debug","z":"ba9fdde779b44998","name":"Both are sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1170,"y":200,"wires":[]},{"id":"ce35d50d91ef2ef0","type":"debug","z":"ba9fdde779b44998","name":"One sleeping, other not","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1290,"y":260,"wires":[]},{"id":"8b34c2af1e7ce2e1","type":"debug","z":"ba9fdde779b44998","name":"Neither is sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1150,"y":320,"wires":[]},{"id":"2690468.2ea7fba","type":"server","name":"Home Assistant","addon":true}]

Thanks in advance for your help!

[{"id":"32d23ed970cdf150","type":"trigger-state","z":"23af1834a13a4629","name":"Mr","server":"","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["sensor.mr_home","sensor.mr_charging","sensor.mr_silent"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"entity_id","targetValue":"sensor.mr_home","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"sensor.mr_charging","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"sensor.mr_silent","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":190,"y":352,"wires":[["a61c1b4d255433f3"],["e3bb03165610e6f4"]]},{"id":"794efa6d92c9f99d","type":"trigger-state","z":"23af1834a13a4629","name":"Mrs","server":"","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["sensor.mrs_home","sensor.mrs_charging","sensor.mrs_silent"],"substring":[],"regex":[]},"debugEnabled":false,"constraints":[{"targetType":"entity_id","targetValue":"sensor.mrs_home","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"sensor.mrs_charging","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"sensor.mrs_silent","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":190,"y":448,"wires":[["f1f3f54306bf4e19"],["a0fe1bde2d744a3e"]]},{"id":"a61c1b4d255433f3","type":"change","z":"23af1834a13a4629","name":"mr sleeping","rules":[{"t":"set","p":"mr_sleeping","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":358,"y":352,"wires":[["4491edf3d090cbd7"]]},{"id":"e3bb03165610e6f4","type":"change","z":"23af1834a13a4629","name":"mr not sleeping","rules":[{"t":"set","p":"mr_sleeping","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":368,"y":400,"wires":[["4491edf3d090cbd7"]]},{"id":"f1f3f54306bf4e19","type":"change","z":"23af1834a13a4629","name":"mrs sleeping","rules":[{"t":"set","p":"mrs_sleeping","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":358,"y":448,"wires":[["4491edf3d090cbd7"]]},{"id":"a0fe1bde2d744a3e","type":"change","z":"23af1834a13a4629","name":"mrs not sleeping","rules":[{"t":"set","p":"mrs_sleeping","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":378,"y":496,"wires":[["4491edf3d090cbd7"]]},{"id":"4491edf3d090cbd7","type":"switch","z":"23af1834a13a4629","name":"mr sleeping?","property":"mr_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":602,"y":400,"wires":[["112d8ba98e8639b1"],["6762ca845a143c23"]]},{"id":"112d8ba98e8639b1","type":"switch","z":"23af1834a13a4629","name":"mrs sleeping?","property":"mrs_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":784,"y":400,"wires":[["2537f1d658d408f9"],["58b34ec3ab5acab9"]]},{"id":"2537f1d658d408f9","type":"debug","z":"23af1834a13a4629","name":"both sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":992,"y":400,"wires":[]},{"id":"6762ca845a143c23","type":"switch","z":"23af1834a13a4629","name":"mrs sleeping?","property":"mrs_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":784,"y":448,"wires":[["58b34ec3ab5acab9"],["1fd33fb75036563f"]]},{"id":"58b34ec3ab5acab9","type":"debug","z":"23af1834a13a4629","name":"one sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":986,"y":448,"wires":[]},{"id":"1fd33fb75036563f","type":"debug","z":"23af1834a13a4629","name":"neither sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":996,"y":496,"wires":[]}]

Hi Kermit,

Thank you for streamlining the process. In my original flow, I included an input because I want to use this flow to trigger other automations. For example, I have one that checks if anyone is asleep when a window opens or closes, and based on that, it triggers a light.

How can this be accomplished with the flow you’ve created, given that the trigger state currently has no input?

Thanks

I would leave it as kermit posted but have it turn a helper on/off. The helper can then be used as a condition for additional flows. You can also use the helper to trigger other flows.

You can also create a group of the sleeping helpers, require that helper to have all entities on before turning on. The group will indicate when everyone is asleep.

Ah, of course! Keep it simple. I was trying to over-engineer it. Thanks everyone for the advise.

I’m still familiarizing myself with Node-RED as I transition my complex automations from Home Assistant. So far, I’ve set up helpers and integrated them into the flow, enabling them to toggle on or off as needed.

[{"id":"9227586a8c18bf78","type":"tab","label":"Sleeping","disabled":false,"locked":true,"info":"","env":[]},{"id":"32d23ed970cdf150","type":"trigger-state","z":"9227586a8c18bf78","name":"Mr","server":"2690468.2ea7fba","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entityId":["person.rpc","sensor.the_mr_ringer_mode","binary_sensor.the_mr_is_charging"],"entityIdType":"list","debugEnabled":false,"constraints":[{"targetType":"entity_id","targetValue":"person.rpc","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"},{"targetType":"entity_id","targetValue":"sensor.the_mr_ringer_mode","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"silent"},{"targetType":"entity_id","targetValue":"binary_sensor.the_mr_is_charging","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":90,"y":120,"wires":[["a61c1b4d255433f3"],["e3bb03165610e6f4"]]},{"id":"a61c1b4d255433f3","type":"change","z":"9227586a8c18bf78","name":"Mr Sleeping","rules":[{"t":"set","p":"mr_sleeping","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":100,"wires":[["4491edf3d090cbd7"]]},{"id":"e3bb03165610e6f4","type":"change","z":"9227586a8c18bf78","name":"Mr not sleeping","rules":[{"t":"set","p":"mr_sleeping","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":300,"y":140,"wires":[["4491edf3d090cbd7","cd439b639560735c"]]},{"id":"f1f3f54306bf4e19","type":"change","z":"9227586a8c18bf78","name":"Mrs sleeping","rules":[{"t":"set","p":"mrs_sleeping","pt":"flow","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":270,"y":200,"wires":[["4491edf3d090cbd7"]]},{"id":"a0fe1bde2d744a3e","type":"change","z":"9227586a8c18bf78","name":"Mrs not sleeping","rules":[{"t":"set","p":"mrs_sleeping","pt":"flow","to":"false","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":240,"wires":[["4491edf3d090cbd7","c04895965d6e3f07"]]},{"id":"4491edf3d090cbd7","type":"switch","z":"9227586a8c18bf78","name":"mr sleeping?","property":"mr_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":510,"y":200,"wires":[["112d8ba98e8639b1"],["6762ca845a143c23"]]},{"id":"112d8ba98e8639b1","type":"switch","z":"9227586a8c18bf78","name":"mrs sleeping?","property":"mrs_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":680,"y":120,"wires":[["2537f1d658d408f9","4043ebfa4438bead"],["58b34ec3ab5acab9","885bbe2553314bfb"]]},{"id":"2537f1d658d408f9","type":"debug","z":"9227586a8c18bf78","name":"Both Sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":40,"wires":[]},{"id":"6762ca845a143c23","type":"switch","z":"9227586a8c18bf78","name":"mrs sleeping?","property":"mrs_sleeping","propertyType":"flow","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":false,"outputs":2,"x":680,"y":260,"wires":[["58b34ec3ab5acab9","56c060a8513358a5"],["1fd33fb75036563f","be10c5ae09ad2925"]]},{"id":"58b34ec3ab5acab9","type":"debug","z":"9227586a8c18bf78","name":"One Sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":200,"wires":[]},{"id":"1fd33fb75036563f","type":"debug","z":"9227586a8c18bf78","name":"None Sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":360,"wires":[]},{"id":"367587ccf3e4f12d","type":"trigger-state","z":"9227586a8c18bf78","name":"Mrs","server":"2690468.2ea7fba","version":5,"inputs":0,"outputs":2,"exposeAsEntityConfig":"","entityId":["person.the_mrs","sensor.the_mrs_ringer_mode","binary_sensor.the_mrs_is_charging"],"entityIdType":"list","debugEnabled":false,"constraints":[{"targetType":"entity_id","targetValue":"person.rpc","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"home"},{"targetType":"entity_id","targetValue":"sensor.the_mrs_ringer_mode","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"silent"},{"targetType":"entity_id","targetValue":"binary_sensor.the_mrs_is_charging","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"customOutputs":[],"outputInitially":false,"stateType":"str","enableInput":false,"x":90,"y":200,"wires":[["f1f3f54306bf4e19"],["a0fe1bde2d744a3e"]]},{"id":"4043ebfa4438bead","type":"api-call-service","z":"9227586a8c18bf78","name":"Both sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.mr_sleeping","input_boolean.mrs_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":80,"wires":[[]]},{"id":"be10c5ae09ad2925","type":"api-call-service","z":"9227586a8c18bf78","name":"None sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.mr_sleeping","input_boolean.mrs_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":300,"wires":[[]]},{"id":"885bbe2553314bfb","type":"api-call-service","z":"9227586a8c18bf78","name":"Mr sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.mr_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":140,"wires":[[]]},{"id":"56c060a8513358a5","type":"api-call-service","z":"9227586a8c18bf78","name":"Mrs sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.mrs_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":890,"y":240,"wires":[[]]},{"id":"cd439b639560735c","type":"api-call-service","z":"9227586a8c18bf78","name":"Mr not sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.mr_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":520,"y":60,"wires":[[]]},{"id":"c04895965d6e3f07","type":"api-call-service","z":"9227586a8c18bf78","name":"Mrs not sleeping","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"input_boolean","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.mrs_sleeping"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":510,"y":320,"wires":[[]]},{"id":"2690468.2ea7fba","type":"server","name":"Home Assistant","addon":true}]

Now I’m working on combining these two automation in node-red:

alias: The Mr Bathroom Open
description: ""
trigger:
  - type: opened
    platform: device
    device_id: 1db844742d6d8b1769842cc5f59338cf
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_2
    domain: binary_sensor
condition: []
action:
  - if:
      - alias: Anyone sleeping?
        condition: or
        conditions:
          - condition: state
            entity_id: input_boolean.mr_sleeping
            state: "on"
          - condition: state
            entity_id: input_boolean.mrs_sleeping
            state: "on"
    then:
      - target:
          entity_id: scene.landing_the_mr_night
        metadata: {}
        action: scene.turn_on
    else:
      - target:
          entity_id: scene.landing_the_mr_bathroom
        metadata: {}
        action: scene.turn_on
mode: single

and

alias: The Mr Bathroom Window Closing
description: ""
trigger:
  - type: not_opened
    platform: device
    device_id: 1db844742d6d8b1769842cc5f59338cf
    entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_2
    domain: binary_sensor
    alias: "The Mr Window contact closed "
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: binary_sensor.ensuite_1_window
            state: "on"
        sequence:
          - target:
              entity_id: scene.landing_ensuite_1_window_open
            metadata: {}
            action: scene.turn_on
      - conditions:
          - condition: state
            entity_id: binary_sensor.lumi_lumi_sensor_magnet_aq2_opening_3
            state: "on"
        sequence:
          - if:
              - condition: or
                conditions:
                  - condition: and
                    conditions:
                      - condition: state
                        entity_id: sensor.the_mr_ringer_mode
                        state: silent
                      - condition: state
                        entity_id: binary_sensor.the_mr_is_charging
                        state: "on"
                      - condition: zone
                        entity_id: person.rpc
                        zone: zone.home
                    alias: The Mr Sleeping
                  - condition: and
                    conditions:
                      - condition: state
                        entity_id: sensor.the_mrs_ringer_mode
                        state: silent
                        enabled: false
                      - condition: or
                        conditions:
                          - condition: state
                            entity_id: sensor.the_mrs_ringer_mode
                            state: silent
                          - condition: state
                            entity_id: sensor.the_mrs_ringer_mode
                            state: vibrate
                        alias: The Mrs Phone is on Silent or vibrate
                      - condition: state
                        entity_id: binary_sensor.the_mrs_is_charging
                        state: "on"
                      - condition: zone
                        entity_id: person.the_mrs
                        zone: zone.home
                    alias: The Mrs Sleeping
                alias: Anyone sleeping?
            then:
              - target:
                  entity_id: scene.landing_the_mrs_bathroom_window_niggt
                metadata: {}
                action: scene.turn_on
            else:
              - target:
                  entity_id: scene.landing_the_mrs_bathroom
                metadata: {}
                action: scene.turn_on
      - conditions: []
        sequence:
          - if:
              - condition: sun
                before: sunset
                after: sunrise
            then:
              - data: {}
                target:
                  entity_id: light.landing
                action: light.turn_off
            else:
              - if:
                  - alias: Anyone sleeping?
                    condition: or
                    conditions:
                      - condition: state
                        entity_id: input_boolean.mr_sleeping
                        state: "on"
                      - condition: state
                        entity_id: input_boolean.mrs_sleeping
                        state: "on"
                then:
                  - target:
                      entity_id: scene.landing_nightlight_purple
                    metadata: {}
                    action: scene.turn_on
                else:
                  - target:
                      entity_id: scene.landing_driveway_purple
                    metadata: {}
                    action: scene.turn_on
mode: single

The problem is, I’m stumped when it comes to building the flow that checks the input boolean from the ‘Sleeping’ flow that @Kermit kindly helped me with.

I’ve been holding off on posting this—mainly because I wanted to figure it out on my own, but also because I wasn’t exactly eager to admit that the Mrs. and I have, uh, separate bathrooms…plus an ensuite. It’s like a plumbing version of Tetris in my house, and somehow I’m still losing! But now that my bathroom empire is out in the open, I’m hoping one of you Node-RED ninjas can help me crack this mystery before I end up adding a fourth bathroom just to avoid confusion!

This is how far I’ve got but it’s doing my nut in.

[{"id":"d26701f00fe69bc3","type":"tab","label":"Windows","disabled":false,"info":"","env":[]},{"id":"bab98a47b966ccce","type":"api-call-service","z":"d26701f00fe69bc3","name":"Ensuite 1 Window Open","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"hue","service":"activate_scene","areaId":[],"deviceId":[],"entityId":["scene.landing_ensuite_1_window_open"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":970,"y":160,"wires":[[]]},{"id":"ef1e0a35e1c8e101","type":"api-call-service","z":"d26701f00fe69bc3","name":"Ensuite 1 Window Open Night","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"hue","service":"activate_scene","areaId":[],"deviceId":[],"entityId":["scene.landing_ensuite_night"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":990,"y":100,"wires":[[]]},{"id":"efa123e83c9fd9c0","type":"server-state-changed","z":"d26701f00fe69bc3","name":"Ensuite 1 window","server":"2690468.2ea7fba","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.ensuite_1_window","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":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":80,"y":220,"wires":[["e9c0ef7cf3754683"],["e9c0ef7cf3754683"]]},{"id":"2695ea72177e97a9","type":"api-call-service","z":"d26701f00fe69bc3","name":"Landing turn off","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.landing"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":800,"y":340,"wires":[[]]},{"id":"4a40fc512fb297f5","type":"debug","z":"d26701f00fe69bc3","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":560,"y":280,"wires":[]},{"id":"a4d18ef50fdf4460","type":"debug","z":"d26701f00fe69bc3","name":"None Sleeping","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":900,"y":620,"wires":[]},{"id":"fe3aaf4a364bce72","type":"debug","z":"d26701f00fe69bc3","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":540,"y":40,"wires":[]},{"id":"7d1bbb2e870b9ac7","type":"api-call-service","z":"d26701f00fe69bc3","name":"Landing Evening","server":"2690468.2ea7fba","version":5,"debugenabled":false,"domain":"hue","service":"activate_scene","areaId":[],"deviceId":[],"entityId":["scene.landing_driveway_purple"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":810,"y":280,"wires":[[]]},{"id":"e9c0ef7cf3754683","type":"switch","z":"d26701f00fe69bc3","name":"Ensuite 1 Window Status","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":330,"y":220,"wires":[["fe3aaf4a364bce72","4f7d00a98d329154"],["a1a6bb699b1a6f17","4a40fc512fb297f5"]]},{"id":"f8fcf13ce2fd8222","type":"switch","z":"d26701f00fe69bc3","name":"Is Anyone Sleeping?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"true","vt":"bool"},{"t":"eq","v":"false","vt":"bool"}],"checkall":"true","repair":false,"outputs":2,"x":700,"y":140,"wires":[["ef1e0a35e1c8e101","7c67902ca60afd24"],["bab98a47b966ccce","12affefb158e2b7a"]]},{"id":"a1a6bb699b1a6f17","type":"api-current-state","z":"d26701f00fe69bc3","name":"Check if Sun Has Set","server":"2690468.2ea7fba","version":3,"outputs":2,"halt_if":"below_horizon","halt_if_type":"str","halt_if_compare":"is","entity_id":"sun.sun","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"}],"for":0,"forType":"num","forUnits":"minutes","x":560,"y":320,"wires":[["7d1bbb2e870b9ac7"],["2695ea72177e97a9"]]},{"id":"7c67902ca60afd24","type":"debug","z":"d26701f00fe69bc3","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":940,"y":40,"wires":[]},{"id":"12affefb158e2b7a","type":"debug","z":"d26701f00fe69bc3","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":200,"wires":[]},{"id":"4f7d00a98d329154","type":"function","z":"d26701f00fe69bc3","name":"function 1","func":"let mrSleeping = flow.get('mr_sleeping') || false;\nlet mrsSleeping = flow.get('mrs_sleeping') || false;\n\nif (mrSleeping || mrsSleeping) {\n    msg.payload = 'sleeping';\n} else {\n    msg.payload = 'awake';\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":200,"wires":[["f8fcf13ce2fd8222"]]},{"id":"2690468.2ea7fba","type":"server","name":"Home Assistant","addon":true}]

Any advice would be grateful.