Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"75cf2565e7110740","type":"trigger-state","z":"3ad1e0957e6ec22e","name":"","server":"7ab5c227.a3ce8c","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"^binary_sensor\\.(?!.*?bedroom.*?)(?!.*?closet.*?)sensor_.*_occupancy$","entityidfiltertype":"regex","debugenabled":false,"constraints":[{"targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":310,"y":2160,"wires":[["ff0f60a09e8cd06c","f7d8b78bf7c2858a"],[]]},{"id":"ff0f60a09e8cd06c","type":"function","z":"3ad1e0957e6ec22e","name":"Extract room from motion sensor entity an extract off lights to regex","func":"var motion_entity_id = msg.data.event.new_state.entity_id; // binary_sensor.sensor_bedroom_motion_occupancy\nvar motion_entity_id_split = motion_entity_id.split(\".\");// split on the dot to separate domain and entity\nvar motion_entity_id_wihtout_binary = motion_entity_id_split[1].replace(\"sensor_\", \"\").replace(\"_motion\", \"\").replace(\"_fp1\", \"\").replace(\"fp2_\", \"\").replace(\"_presence\", \"\").replace(\"_occupancy\", \"\").replace(\"_entry\", \"\").replace(\"_exit\", \"\");// remove sensor_ and more substrings\nvar regex = \"^light\\\\.(?!.*?group.*?)(?!.*?notification.*?)(?!.*?lights.*?).*\" + motion_entity_id_wihtout_binary + \".*\"; \nconst rules_object = [{ 'property': 'entity_id' , 'logic': 'is' , 'value': regex , 'valueType': 're' },{ 'property': 'state' , 'logic': 'is_not' , 'value': \"on\" , 'valueType': 'str' }];// arranges the array \n\nvar msg = {\n \"payload\":{ \"rules\": rules_object},\"room\": motion_entity_id_wihtout_binary\n\n}\nreturn msg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":960,"y":2160,"wires":[["5a3dbf03d377b43a","5a81833454441841"]]},{"id":"5a3dbf03d377b43a","type":"ha-get-entities","z":"3ad1e0957e6ec22e","name":"Get entities","server":"7ab5c227.a3ce8c","version":0,"rules":[],"output_type":"split","output_empty_results":false,"output_location_type":"msg","output_location":"payload.results","output_results_count":1,"x":1330,"y":2160,"wires":[["d2ae1f1089a02614","d9a971625dab2d8b"]]},{"id":"8419c0f01e0cf559","type":"api-call-service","z":"3ad1e0957e6ec22e","name":"","server":"7ab5c227.a3ce8c","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":3530,"y":2180,"wires":[[]]},{"id":"d2ae1f1089a02614","type":"change","z":"3ad1e0957e6ec22e","name":"rules","rules":[{"t":"move","p":"payload","pt":"msg","to":"entity","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1570,"y":2160,"wires":[["a3d8e274aee82b8a"]]},{"id":"f34e20c2334ccf4c","type":"comment","z":"3ad1e0957e6ec22e","name":"Detect motion across ocupancy sensors","info":"","x":170,"y":2120,"wires":[]},{"id":"29c20247a612b7c8","type":"comment","z":"3ad1e0957e6ec22e","name":"(Ignores \"Closet\", \"Bedroom\" sensors)","info":"","x":490,"y":2120,"wires":[]},{"id":"95a4c5dd36cd88b2","type":"comment","z":"3ad1e0957e6ec22e","name":"Generate the regex for get entity node","info":"","x":1050,"y":2120,"wires":[]},{"id":"a32f9f37badef6fe","type":"comment","z":"3ad1e0957e6ec22e","name":"Get off light entities","info":"","x":1330,"y":2120,"wires":[]},{"id":"7b91e7430afd08ea","type":"comment","z":"3ad1e0957e6ec22e","name":"Move payload to entity","info":"","x":1560,"y":2120,"wires":[]},{"id":"b9f088c7a0898053","type":"comment","z":"3ad1e0957e6ec22e","name":"Select color, brightness and set entity_id","info":"","x":3360,"y":2220,"wires":[]},{"id":"5c924378f03832ef","type":"comment","z":"3ad1e0957e6ec22e","name":"Turn the lights on","info":"","x":3520,"y":2140,"wires":[]},{"id":"6e0313cad534393b","type":"function","z":"3ad1e0957e6ec22e","name":"Brightness selector","func":"var d = new Date();\nvar h = d.getHours();\n\nif (h > 22){\n var brightness_percentage = \"45\";\n}\nelse if (h >= 0 && h <= 2 ){\n var brightness_percentage = \"40\";\n}\nelse if (h > 2 && h<8){\n var brightness_percentage = \"25\";\n}\nelse if (h >= 8 && h<9){\n var brightness_percentage = \"35\";\n}\nelse{\n var brightness_percentage = \"50\";\n}\nmsg=\n{\n \"payload\":{\n \"data\": {\n \"entity_id\": msg.payload.entity.entity_id,\n \"brightness_pct\": brightness_percentage,\n \"color_name\": \"white\"\n }\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3290,"y":2180,"wires":[["8419c0f01e0cf559"]]},{"id":"5fee30b61a27e6e5","type":"api-current-state","z":"3ad1e0957e6ec22e","name":"Acid time","server":"7ab5c227.a3ce8c","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"input_boolean.acid_time","state_type":"str","blockInputOverrides":true,"outputProperties":[],"for":0,"forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":3020,"y":2160,"wires":[["88b1d87eacc8b8e0"],["c78ba01e2c786587"]]},{"id":"e0dea2b09c9b5232","type":"debug","z":"3ad1e0957e6ec22e","name":"debug 294","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2190,"y":2200,"wires":[]},{"id":"f7d8b78bf7c2858a","type":"debug","z":"3ad1e0957e6ec22e","name":"debug 295","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":790,"y":2120,"wires":[]},{"id":"5a81833454441841","type":"debug","z":"3ad1e0957e6ec22e","name":"debug 296","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1330,"y":2200,"wires":[]},{"id":"a3d8e274aee82b8a","type":"api-current-state","z":"3ad1e0957e6ec22e","name":"","server":"7ab5c227.a3ce8c","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"sensor.active_sleeper_rooms","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"room_sleepers","propertyType":"msg","value":"","valueType":"entityState"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":1870,"y":2160,"wires":[["e0dea2b09c9b5232","51dbd35861e70217"]]},{"id":"d9a971625dab2d8b","type":"debug","z":"3ad1e0957e6ec22e","name":"debug 297","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1590,"y":2200,"wires":[]},{"id":"777b0400e36fa32b","type":"inject","z":"3ad1e0957e6ec22e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"data","v":"{\"event_type\":\"state_changed\",\"entity_id\":\"binary_sensor.sensor_hallway_motion_occupancy\",\"event\":{\"entity_id\":\"binary_sensor.sensor_hallway_motion_occupancy\",\"old_state\":{\"entity_id\":\"binary_sensor.sensor_hallway_motion_occupancy\",\"state\":\"off\",\"attributes\":{\"battery\":100,\"device\":{\"applicationVersion\":11,\"dateCode\":\"20160524\",\"friendlyName\":\"sensor_hallway_motion\",\"hardwareVersion\":2,\"ieeeAddr\":\"0x00158d0002275fd4\",\"manufacturerID\":4151,\"manufacturerName\":\"LUMI\",\"model\":\"RTCGQ01LM\",\"networkAddress\":36327,\"powerSource\":\"Battery\",\"softwareBuildID\":\"3000-0001\",\"stackVersion\":2,\"type\":\"EndDevice\",\"zclVersion\":1},\"linkquality\":29,\"occupancy\":false,\"power_outage_count\":23115,\"voltage\":3035,\"device_class\":\"motion\",\"friendly_name\":\"Hallway Motion_occupancy\"},\"last_changed\":\"2023-08-02T15:45:12.640577+00:00\",\"last_updated\":\"2023-08-02T15:45:12.640577+00:00\",\"context\":{\"id\":\"01H6VESCE0WYF8ZX13SQC5N487\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"off\"},\"new_state\":{\"entity_id\":\"binary_sensor.sensor_hallway_motion_occupancy\",\"state\":\"on\",\"attributes\":{\"battery\":100,\"device\":{\"applicationVersion\":11,\"dateCode\":\"20160524\",\"friendlyName\":\"sensor_hallway_motion\",\"hardwareVersion\":2,\"ieeeAddr\":\"0x00158d0002275fd4\",\"manufacturerID\":4151,\"manufacturerName\":\"LUMI\",\"model\":\"RTCGQ01LM\",\"networkAddress\":36327,\"powerSource\":\"Battery\",\"softwareBuildID\":\"3000-0001\",\"stackVersion\":2,\"type\":\"EndDevice\",\"zclVersion\":1},\"linkquality\":29,\"occupancy\":false,\"power_outage_count\":23115,\"voltage\":3035,\"device_class\":\"motion\",\"friendly_name\":\"Hallway Motion_occupancy\"},\"last_changed\":\"2023-08-02T15:50:28.404423+00:00\",\"last_updated\":\"2023-08-02T15:50:28.404423+00:00\",\"context\":{\"id\":\"01H6VF30SMTSYD1N217CFJ7GQT\",\"parent_id\":null,\"user_id\":\"7f1de31122574f6fa2215e519d6083ea\"},\"original_state\":\"on\",\"timeSinceChangedMs\":5}},\"origin\":\"LOCAL\",\"time_fired\":\"2023-08-02T15:50:28.404423+00:00\",\"context\":{\"id\":\"01H6VF30SMTSYD1N217CFJ7GQT\",\"parent_id\":null,\"user_id\":\"7f1de31122574f6fa2215e519d6083ea\"}}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"binary_sensor.sensor_hallway_motion_occupancy","payload":"on","payloadType":"str","x":1330,"y":2080,"wires":[["d2ae1f1089a02614"]]},{"id":"d0599e2fa55de2b9","type":"switch","z":"3ad1e0957e6ec22e","name":"Is \"active_sleeper_present\" 0?","property":"payload.active_sleeper_present","propertyType":"msg","rules":[{"t":"eq","v":"0","vt":"num"}],"checkall":"false","repair":false,"outputs":1,"x":2650,"y":2160,"wires":[["5fee30b61a27e6e5"]]},{"id":"5dfa51babbba06ed","type":"comment","z":"3ad1e0957e6ec22e","name":"Check that \"active_sleeper_present\" is off","info":" - ","x":2660,"y":2120,"wires":[]},{"id":"e596935b261be053","type":"inject","z":"3ad1e0957e6ec22e","name":"office motion","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"data","v":"{\"event_type\":\"state_changed\",\"entity_id\":\"binary_sensor.sensor_office_motion_occupancy\",\"event\":{\"entity_id\":\"binary_sensor.sensor_office_motion_occupancy\",\"old_state\":{\"entity_id\":\"binary_sensor.sensor_office_motion_occupancy\",\"state\":\"off\",\"attributes\":{\"battery\":100,\"device\":{\"applicationVersion\":11,\"friendlyName\":\"sensor_office_motion\",\"ieeeAddr\":\"0x00158d0002281294\",\"manufacturerID\":4151,\"manufacturerName\":\"LUMI\",\"model\":\"RTCGQ01LM\",\"networkAddress\":28396,\"powerSource\":\"Battery\",\"type\":\"EndDevice\"},\"linkquality\":87,\"occupancy\":false,\"power_outage_count\":77,\"voltage\":3075,\"device_class\":\"motion\",\"friendly_name\":\"Hotbox Down Motion_occupancy\"},\"last_changed\":\"2023-08-03T13:07:10.739670+00:00\",\"last_updated\":\"2023-08-03T13:07:10.739670+00:00\",\"context\":{\"id\":\"01H6XR4QRKMSW2KB245H9T6KFT\",\"parent_id\":null,\"user_id\":null},\"original_state\":\"off\"},\"new_state\":{\"entity_id\":\"binary_sensor.sensor_office_motion_occupancy\",\"state\":\"on\",\"attributes\":{\"battery\":100,\"device\":{\"applicationVersion\":11,\"friendlyName\":\"sensor_office_motion\",\"ieeeAddr\":\"0x00158d0002281294\",\"manufacturerID\":4151,\"manufacturerName\":\"LUMI\",\"model\":\"RTCGQ01LM\",\"networkAddress\":28396,\"powerSource\":\"Battery\",\"type\":\"EndDevice\"},\"linkquality\":87,\"occupancy\":false,\"power_outage_count\":77,\"voltage\":3075,\"device_class\":\"motion\",\"friendly_name\":\"Hotbox Down Motion_occupancy\"},\"last_changed\":\"2023-08-03T13:28:46.214518+00:00\",\"last_updated\":\"2023-08-03T13:28:46.214518+00:00\",\"context\":{\"id\":\"01H6XSC8W6W0RJ9N7G6RVXA89K\",\"parent_id\":null,\"user_id\":\"7f1de31122574f6fa2215e519d6083ea\"},\"original_state\":\"on\",\"timeSinceChangedMs\":4}},\"origin\":\"LOCAL\",\"time_fired\":\"2023-08-03T13:28:46.214518+00:00\",\"context\":{\"id\":\"01H6XSC8W6W0RJ9N7G6RVXA89K\",\"parent_id\":null,\"user_id\":\"7f1de31122574f6fa2215e519d6083ea\"}}","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"binary_sensor.sensor_office_motion_occupancy","payload":"on","payloadType":"str","x":530,"y":2200,"wires":[["ff0f60a09e8cd06c"]]},{"id":"51dbd35861e70217","type":"function","z":"3ad1e0957e6ec22e","name":"Check if any sleeper is in the triggered room","func":"\n\nvar room = msg.room.replace('_down', '').replace('_exit', '').replace('_top', '');\nvar room_sleepers = msg.room_sleepers;\nvar active = 0;\n\nvar active = compareArrayToString(room_sleepers, room);\n\n\nvar msg = {\n \"payload\": {\n \"room\": room,\n \"room_sleepers\": room_sleepers,\n \"entity\": msg.entity,\n \"active_sleeper_present\": active,\n \"data\": msg.data\n },\n \"entity_id\": msg.entity.entity_id\n\n}\nreturn msg;\n\n\nfunction compareArrayToString(array, string) {\n var array_string = String(array)\n\n\n if (array_string.includes(string)) {\n // return 1 if found\n return 1;\n }\n\n\n // return off if none found\n return 0;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2290,"y":2160,"wires":[["d0599e2fa55de2b9","9c11a0a5f77492b5"]]},{"id":"9c11a0a5f77492b5","type":"debug","z":"3ad1e0957e6ec22e","name":"debug 300","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2590,"y":2200,"wires":[]},{"id":"ab99a49d19ea27a0","type":"comment","z":"3ad1e0957e6ec22e","name":"Check if a trip is ongoing","info":" - ","x":3010,"y":2120,"wires":[]},{"id":"e45b3c1d18695954","type":"function","z":"3ad1e0957e6ec22e","name":"Entity Setter","func":"msg=\n{\n \"payload\":{\n \"data\": {\n \"entity_id\": msg.payload.entity.entity_id\n }\n }\n}\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":3270,"y":2140,"wires":[["8419c0f01e0cf559"]]},{"id":"5388180a1b1a9d95","type":"comment","z":"3ad1e0957e6ec22e","name":"Set the entity_id","info":"","x":3280,"y":2100,"wires":[]},{"id":"c78ba01e2c786587","type":"junction","z":"3ad1e0957e6ec22e","x":3120,"y":2180,"wires":[["6e0313cad534393b"]]},{"id":"88b1d87eacc8b8e0","type":"junction","z":"3ad1e0957e6ec22e","x":3120,"y":2140,"wires":[["e45b3c1d18695954"]]},{"id":"7ab5c227.a3ce8c","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
Advertisement
Add Comment
Please, Sign In to add comment