Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"5288cc7c.ab3fc4","type":"tab","label":"Presence test","disabled":false,"info":"https://gergo.io/comprehensive-room-presence-detection/"},{"id":"a0188e23.ffe63","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Bedroom Pres.","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.bedroom_presence","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":270,"y":240,"wires":[[]]},{"id":"ea43c45.7a0fdb8","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Living Room Pres.","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.living_room_presence","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":280,"y":280,"wires":[[]]},{"id":"7d82c509.510c04","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Kitchen Pres.","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.kitchen_presence","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":270,"y":360,"wires":[[]]},{"id":"516cc48b.10b83c","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set House Pres.","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.house_presence","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":260,"y":200,"wires":[[]]},{"id":"51938d6c.fa7ad4","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Glenn Loc.","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.glenn_location","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":660,"y":200,"wires":[[]]},{"id":"3e24cc0d.0f65cc","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set P2 Loc.","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.p2_location","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":650,"y":240,"wires":[[]]},{"id":"c31166c1.d9fec","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Person Loc.","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":660,"y":280,"wires":[[]]},{"id":"7eed218c.896028","type":"link in","z":"5288cc7c.ab3fc4","name":"Set House Presence","links":["53b8eae3.842e14","fb0dad4a.1a525","8beb9e18.166a3"],"x":135,"y":200,"wires":[["516cc48b.10b83c"]]},{"id":"5d84b3d6.bfa3fc","type":"link in","z":"5288cc7c.ab3fc4","name":"Set LR Presence","links":["174bb3be.61bf3c","1beff2e3.5c52dd","6242a51d.fd28b4","918ad969.a56cd8"],"x":135,"y":280,"wires":[[]]},{"id":"a182e7fd.612e8","type":"link in","z":"5288cc7c.ab3fc4","name":"Set BR Presence","links":["762545d5.94270c","b27c5fec.4dd478","35ea5fad.ddbe1","84fc07ed.8a51e"],"x":135,"y":240,"wires":[["a0188e23.ffe63"]]},{"id":"9a4bb64a.5d689","type":"link in","z":"5288cc7c.ab3fc4","name":"Set Kitchen Presence","links":["a72e7d8c.da481","318b9cc6.ef1c4c","48e1662e.5bd418"],"x":135,"y":360,"wires":[[]]},{"id":"f89473bf.620c7","type":"link in","z":"5288cc7c.ab3fc4","name":"Set P1 Loc.","links":["c4690954.00841","7c39ff5a.e9255"],"x":535,"y":200,"wires":[["51938d6c.fa7ad4"]]},{"id":"2ccd200e.d2df58","type":"link in","z":"5288cc7c.ab3fc4","name":"Set P2 Loc.","links":["e87f75b8.1042d"],"x":535,"y":240,"wires":[[]]},{"id":"5664ddce.8a908c","type":"link in","z":"5288cc7c.ab3fc4","name":"Set Person Loc.","links":["dbbc59b.8460ea8","1d60e010.ed1928"],"x":535,"y":280,"wires":[["c31166c1.d9fec"]]},{"id":"20fd02d8.0aab9e","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Startup","server":"fc33606a.00a2c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.uptime_hours","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"bcwmp09vmlo","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"0.05"},{"id":"hd6y2obe0a","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"0.05"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":100,"y":80,"wires":[["92d5e1a7.ac0a48"],[]]},{"id":"22ec2adf.3b7c1e","type":"link in","z":"5288cc7c.ab3fc4","name":"Startup IN","links":["344c407d.43aba8"],"x":115,"y":580,"wires":[["3e2695ba.3610ea"]]},{"id":"f01bc9ee.99f4f","type":"comment","z":"5288cc7c.ab3fc4","name":"1.1 - At Startup, Set P1/P2 to Home/Away","info":"Triggered whenever HomeAssistant starts (uptime reaches a certain value).\n\nIt checks the Home/Away status for everyone and sets their input_select.*person*_location entities.","x":200,"y":520,"wires":[]},{"id":"3e2695ba.3610ea","type":"delay","z":"5288cc7c.ab3fc4","name":"5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":210,"y":580,"wires":[["45e969a4.d51778","c2895ea1.8ed4e"]]},{"id":"45e969a4.d51778","type":"function","z":"5288cc7c.ab3fc4","name":"Glenn Home/Away?","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst p1_home_or_away = ha.states[\"person.glenn\"].state;\nconst p1_loc = ha.states[\"input_select.glenn_location\"].state;\n\nnewmsg = {};\n\nif(p1_loc != \"Extended Away\"){\n if(p1_home_or_away == \"home\"){\n newmsg.payload = { data: { \"option\": \"Home\"} }; \n }\n else{\n newmsg.payload = { data: { \"option\": \"Away\"} }; \n }\n return newmsg;\n}\n\n//This flow returns an option to set a person's input_select.p1_location to.\n//It only returns a value if it is not already set to extended away\n//If not extended away, it will return home when the person.p1 is home or\n//away if it is away.\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":370,"y":560,"wires":[["c4690954.00841","90a19bdc.9bb0c"]]},{"id":"344c407d.43aba8","type":"link out","z":"5288cc7c.ab3fc4","name":"Startup","links":["22ec2adf.3b7c1e","e63f8431.b73da8"],"x":295,"y":80,"wires":[]},{"id":"c4690954.00841","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["f89473bf.620c7"],"x":495,"y":560,"wires":[]},{"id":"d16bac2a.51b8f","type":"comment","z":"5288cc7c.ab3fc4","name":"+ Extra People","info":"","x":380,"y":640,"wires":[]},{"id":"c2895ea1.8ed4e","type":"function","z":"5288cc7c.ab3fc4","name":"P2 Home/Away?","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst p2_home_or_away = ha.states[\"person.p2\"].state;\nconst p2_loc = ha.states[\"input_select.p2_location\"].state;\n\nnewmsg = {};\n\nif(p2_loc != \"Extended Away\"){\n if(p2_home_or_away == \"home\"){\n newmsg.payload = { data: { \"option\": \"Home\"} }; \n }\n else{\n newmsg.payload = { data: { \"option\": \"Away\"} }; \n }\n return newmsg;\n}\n\n//This flow returns an option to set a person's input_select.p2_location to.\n//It only returns a value if it is not already set to extended away\n//If not extended away, it will return home when the person.p2 is home or\n//away if it is away.\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":600,"wires":[["e87f75b8.1042d"]]},{"id":"e87f75b8.1042d","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["2ccd200e.d2df58"],"x":495,"y":600,"wires":[]},{"id":"17177cb8.e73b63","type":"switch","z":"5288cc7c.ab3fc4","name":"Home?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"home","vt":"str"},{"t":"eq","v":"not_home","vt":"str"}],"checkall":"false","repair":false,"outputs":2,"x":420,"y":880,"wires":[["48209464.51c8b4","55f3ee78.f09ea","de8fd0ca.26cdd"],["4bde899a.ac6a1","90ed4cf4.29aa1"]]},{"id":"48209464.51c8b4","type":"trigger","z":"5288cc7c.ab3fc4","name":"1m","op1":"","op2":"{\"payload\":{\"data\":{\"option\":\"\"}}}","op1type":"nul","op2type":"json","duration":"1","extend":false,"units":"min","reset":"home","bytopic":"topic","topic":"topic","outputs":1,"x":830,"y":900,"wires":[["a766106a.2eb288"]]},{"id":"55f3ee78.f09ea","type":"trigger","z":"5288cc7c.ab3fc4","name":"24hr","op1":"","op2":"{\"payload\":{\"data\":{\"option\":\"\"}}}","op1type":"nul","op2type":"json","duration":"24","extend":false,"units":"hr","reset":"home","bytopic":"topic","topic":"topic","outputs":1,"x":1070,"y":880,"wires":[["56b687fc.90186"]]},{"id":"de8fd0ca.26cdd","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Status?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"Just Left","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"input_select.{{topic}}","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":560,"y":840,"wires":[["e9744049.ff313"],["9316aef6.0214c"]]},{"id":"4bde899a.ac6a1","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Status?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"[\"Just Left\", \"Away\", \"Extended Away\"]","halt_if_type":"jsonata","halt_if_compare":"does_not_include","override_topic":false,"entity_id":"input_select.{{topic}}","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":560,"y":920,"wires":[["7f4861d7.9da1f"],[]]},{"id":"90ed4cf4.29aa1","type":"trigger","z":"5288cc7c.ab3fc4","name":"1m","op1":"","op2":"{\"payload\":{\"data\":{\"option\":\"\"}}}","op1type":"nul","op2type":"json","duration":"1","extend":false,"units":"min","reset":"not_home","bytopic":"topic","topic":"topic","outputs":1,"x":990,"y":820,"wires":[["9316aef6.0214c"]]},{"id":"99f7727e.c2839","type":"rbe","z":"5288cc7c.ab3fc4","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":325,"y":880,"wires":[["17177cb8.e73b63"]],"l":false},{"id":"7f4861d7.9da1f","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Just Left","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"{\"entity_id\":\"input_select.{{topic}}\",\"option\":\"Just Left\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":700,"y":920,"wires":[["48209464.51c8b4"]]},{"id":"a766106a.2eb288","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Away","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"{\"entity_id\":\"input_select.{{topic}}\",\"option\":\"Away\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":900,"wires":[["55f3ee78.f09ea"]]},{"id":"56b687fc.90186","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Extended Away","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"{\"entity_id\":\"input_select.{{topic}}\",\"option\":\"Extended Away\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1200,"y":880,"wires":[[]]},{"id":"e9744049.ff313","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Status?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"Bedroom, Living Room, Bathroom, Kitchen","halt_if_type":"str","halt_if_compare":"does_not_include","override_topic":false,"entity_id":"input_select.{{topic}}","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":700,"y":800,"wires":[["7e77cebc.af6fd"],[]]},{"id":"9316aef6.0214c","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Home","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"{\"entity_id\":\"input_select.{{topic}}\",\"option\":\"Home\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1110,"y":840,"wires":[[]]},{"id":"7e77cebc.af6fd","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Just Arrived","server":"fc33606a.00a2c","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"","data":"{\"entity_id\":\"input_select.{{topic}}\",\"option\":\"Just Arrived\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":850,"y":800,"wires":[["90ed4cf4.29aa1"]]},{"id":"71fe0305.b53dac","type":"change","z":"5288cc7c.ab3fc4","name":"Change","rules":[{"t":"change","p":"topic","pt":"msg","from":"person.","fromt":"str","to":"","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"glenn","fromt":"str","to":"glenn_location","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"p2","fromt":"str","to":"p2_location","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"payload = \"home\" ? \"home\" : \"not_home\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":275,"y":880,"wires":[["99f7727e.c2839"]],"l":false},{"id":"ad03e8d5.421a48","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Person","server":"fc33606a.00a2c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"^person\\..*$","entityidfiltertype":"regex","debugenabled":false,"constraints":[{"id":"ntik6826mzb","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"prevEntity","comparatorValue":"state"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":180,"y":880,"wires":[["71fe0305.b53dac"],[]]},{"id":"ba8d5082.fbac58","type":"comment","z":"5288cc7c.ab3fc4","name":"1.2 - Set P1/P2.. Just Arrived/Home/Just Left/Away/Extended Away?","info":"https://bonani.tech/making-home-assistants-presence-detection-not-so-binary-node-red-version/\n\nThis flow is modified from the example at the link above. It sets people's input_select.*person*_location to either \"Just Arrived\", \"Home\", \"Just Left\", \"Away\" or \"Extended Away\".\n\nWith modifications to change node (2nd)\nPerson is removed and topic is set to p1_location and p2_location to match the input selects for their locations. Added extra status node with a comment too.","x":280,"y":720,"wires":[]},{"id":"71eede4f.aea3f","type":"comment","z":"5288cc7c.ab3fc4","name":"Added Extra Status Node","info":"The Status? Node top left now filters to check that input_select.*person*_location is not in:\nJust Left,\nLiving Room,\nBedroom,\nBathroom,\nKitchen\n\nThese extra rooms ensure that Just Arrived is not set when the person has just arrived but BLE locations have already set a room. The second one is used so that the original function of setting location back to home when person.*person* goes to home while input_select.*person*_location is set to Just Left. ","x":750,"y":760,"wires":[]},{"id":"763045eb.b4078c","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"P1 Ext. Away?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"Extended Away","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.p1_location","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":1300,"wires":[["ea83d4d0.b6a5f"],[]]},{"id":"ea83d4d0.b6a5f","type":"function","z":"5288cc7c.ab3fc4","name":"Extended Away","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Extended Away\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":560,"y":1280,"wires":[["fb0dad4a.1a525"]]},{"id":"9b2015b6.07a8b8","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P2 to Ext. Away","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.p2_location","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"Extended Away","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":200,"y":1300,"wires":[["763045eb.b4078c"],[]]},{"id":"9ee2afe.009ec5","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"P2 Ext. Away?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"Extended Away","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.p2_location","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":380,"y":1260,"wires":[[],[]]},{"id":"86963ae4.356ce8","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"Glenn to Ext. Away","server":"fc33606a.00a2c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.glenn_location","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"Extended Away","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":190,"y":1260,"wires":[["ea83d4d0.b6a5f"],[]]},{"id":"fb0dad4a.1a525","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["7eed218c.896028"],"x":655,"y":1280,"wires":[]},{"id":"25d62900.237a18","type":"comment","z":"5288cc7c.ab3fc4","name":"1.4 - Set House Presence to \"Extended Away\" if everyone is \"Extended Away\"","info":"This flow is triggered by someones input_select.*person*_location going to \"Extended Away\".\n\nThen it checks if everyone else is \"Extended Away\" too. If so, input_select.house_presence is also set to \"Extended Away\"","x":310,"y":1200,"wires":[]},{"id":"4e4e2c21.3db31c","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"Glenn to Home","server":"fc33606a.00a2c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"person.glenn","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"home","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":180,"y":1060,"wires":[["e0605987.b9cfd8"],["e0605987.b9cfd8"]]},{"id":"aa1a773e.8baed8","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P2 to Home","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"person.p2","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"home","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":190,"y":1100,"wires":[["e0605987.b9cfd8"],["e0605987.b9cfd8"]]},{"id":"e0605987.b9cfd8","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Guests?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.guests","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":1080,"wires":[["e6510cee.e66ed"],["75a6971b.8451e"]]},{"id":"75a6971b.8451e","type":"function","z":"5288cc7c.ab3fc4","name":"Guests","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Guests\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":600,"y":1100,"wires":[["53b8eae3.842e14"]]},{"id":"d77fa09a.65cca8","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Guests?","server":"fc33606a.00a2c","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_boolean.guests","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"vljoqai0x9","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"wak85yaj5kb","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":420,"y":1120,"wires":[["75a6971b.8451e"],[]]},{"id":"e6510cee.e66ed","type":"function","z":"5288cc7c.ab3fc4","name":"Set House Pres.","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst groupEntity = ha.states['group.person_home_away'];\n\nlet occupants = [];\n\ngroupEntity.attributes.entity_id.forEach(i => {\n if(ha.states[i].state === 'home') {\n occupants.push(ha.states[i].attributes.friendly_name);\n //The push bit adds the friendly name of any persons location input select which matches the state (ie home)\n //In this case, the frienly_name of each person.*person* entity is simply that person's initials\n //So this bit returns the initials of all people who are home.\n }\n});\n\n//the join function creates '+' separated string from the array.\noccupants = occupants.join(' + ');\n\n//If no BLE occupation is detected but the motion sensor is on, set the room to Someone\n//Otherwise with no BLE or motion set to Empty \nif (occupants === '') {\n occupants = \"Empty\";\n}\n\nmsg.payload = { data: { \"option\": occupants} };\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":580,"y":1060,"wires":[["53b8eae3.842e14","f00b7b5c.e7f2b"]]},{"id":"53b8eae3.842e14","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["7eed218c.896028"],"x":695,"y":1080,"wires":[]},{"id":"e4c55f94.959ff","type":"comment","z":"5288cc7c.ab3fc4","name":"1.3 - Set House Presence","info":"Keep input_select.house_presence updated with current occupation. \n\nThe input \"events:state\" nodes can also be used to trigger home/away notifications/logging for people.","x":150,"y":1000,"wires":[]},{"id":"1ef6083f.fcddd","type":"comment","z":"5288cc7c.ab3fc4","name":"1 - HOME/AWAY PRESENCE","info":"","x":120,"y":460,"wires":[]},{"id":"319d7f08.108488","type":"comment","z":"5288cc7c.ab3fc4","name":"2 - GENERIC ROOM PRESENCE DETECTION","info":"Generic Room Presence adds an extra layer on top of House Presence. It relies just on motion sensors and can be modified to include other sorts of indications of room presence (TV/bed presence etc.).\n\nGeneric Room Presence can set a room to \"Someone\" if motion is detected.\n\nOnce motion is cleared, and the room presence is still \"Someone\", the room is set to \"Empty\" after a short delay.","x":180,"y":1420,"wires":[]},{"id":"3444f90e.6a12f6","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"LR Motion?","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.living_room_motion","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":190,"y":1720,"wires":[["15bc1370.01b7dd"],["bf69bc5d.9fb558"]]},{"id":"879ec152.7954c","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"BR Motion?","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bedroom_motion","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":190,"y":1600,"wires":[["e8398e5a.604ff8"],["46757de4.99bab4"]]},{"id":"d758cb58.28cc38","type":"comment","z":"5288cc7c.ab3fc4","name":"2.1 - Motion/Other Presence Indicators","info":"Input triggers that start flows are listed at the top of this section and wired in to a link node so that it's easy to trace which section is prompted by what trigger.\n\nHere examples are given on how motion sensors or other presence detection like bed presence or even a humidity rise in the bathroom would update a room's input_select.*room*_presence to \"Someone\".\n\nOther triggers such as a TV turning on could also be added here. The key is to sepearate what suggests occupation and no occupation and wire them to the appropriate paths.","x":190,"y":1480,"wires":[]},{"id":"e8398e5a.604ff8","type":"link out","z":"5288cc7c.ab3fc4","name":"BR Motion","links":["47e231bf.39008","bd14274.f9a6ed8","9adbb9e7.9ecbb"],"x":315,"y":1580,"wires":[]},{"id":"46757de4.99bab4","type":"link out","z":"5288cc7c.ab3fc4","name":"BR Motion Cleared","links":["5d67dde4.73d3f4","cc7c96cb.354d6"],"x":315,"y":1620,"wires":[]},{"id":"15bc1370.01b7dd","type":"link out","z":"5288cc7c.ab3fc4","name":"LR Motion","links":["5405b57b.cfb0dc","24fc300c.090018","eb23d0bb.8cacb8"],"x":315,"y":1700,"wires":[]},{"id":"bf69bc5d.9fb558","type":"link out","z":"5288cc7c.ab3fc4","name":"LR Motion Cleared","links":["bb1b8aa6.ff4138","173dfbef.27b44c","687a1ad3.732314"],"x":315,"y":1740,"wires":[]},{"id":"5d5b5231.6cab34","type":"change","z":"5288cc7c.ab3fc4","name":"Save Last Room Used","rules":[{"t":"move","p":"room","pt":"msg","to":"last_used_room","tot":"global"},{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":700,"y":2040,"wires":[["c9ef8347.f2d868"]]},{"id":"c9ef8347.f2d868","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":815,"y":2040,"wires":[["acac3ea7.ec37d8"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"663cfc46.3345e4","type":"comment","z":"5288cc7c.ab3fc4","name":"2.2 - Set rooms to \"Someone\"","info":"When there is motion in either the Bedroom or Living Room, the room where motion is detected is saved to a global variable so it can quickly be checked in later nodes too.\n\nRooms will only be set when the House is occupied (can help for alarm statuses)\n\nIf only one person is home, then their input_select.*person*_location will be changed to the last room used.\n\nOtherwise is there are 2 or more people home, the input_select.*room*_presence of the last used room will be set to \"Someone\".","x":160,"y":1940,"wires":[]},{"id":"47e231bf.39008","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["e8398e5a.604ff8"],"x":635,"y":1580,"wires":[["88d59fb0.da0cb"]]},{"id":"cc7c96cb.354d6","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["46757de4.99bab4"],"x":635,"y":1620,"wires":[["542dfc04.782c7c"]]},{"id":"24fc300c.090018","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["15bc1370.01b7dd"],"x":635,"y":1700,"wires":[["e77860dc.7dbab"]]},{"id":"bb1b8aa6.ff4138","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["bf69bc5d.9fb558"],"x":635,"y":1740,"wires":[["6d39f2bc.f6f62c"]]},{"id":"9adbb9e7.9ecbb","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["e8398e5a.604ff8"],"x":375,"y":2000,"wires":[["6099c5a3.df991c"]]},{"id":"5405b57b.cfb0dc","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["15bc1370.01b7dd"],"x":375,"y":2040,"wires":[["96c55e13.7b6a58"]]},{"id":"acac3ea7.ec37d8","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"House Pres.?","version":1,"outputs":2,"halt_if":"Unknown, Empty, Someone, Guests, Extended Away","halt_if_type":"str","halt_if_compare":"does_not_include","override_topic":true,"entity_id":"input_select.house_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":940,"y":2040,"wires":[["14504d12.014a5b"],[]]},{"id":"14504d12.014a5b","type":"switch","z":"5288cc7c.ab3fc4","name":"P1/P2/Otherwise?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"P1","vt":"str"},{"t":"eq","v":"P2","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":1130,"y":2040,"wires":[["bd7b5aac.b2a388"],["30238536.d7add2"],["bdc27654.87718"]]},{"id":"bd7b5aac.b2a388","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set P1 Loc","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.p1_location","data":"{\"option\":\"{{global.last_used_room}}\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1310,"y":2000,"wires":[[]]},{"id":"30238536.d7add2","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set P2 Loc","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.p2_location","data":"{\"option\":\"{{global.last_used_room}}\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1310,"y":2040,"wires":[[]]},{"id":"bdc27654.87718","type":"switch","z":"5288cc7c.ab3fc4","name":"BR/LR/Bath?","property":"last_used_room","propertyType":"global","rules":[{"t":"eq","v":"Bedroom","vt":"str"},{"t":"eq","v":"Living Room","vt":"str"},{"t":"eq","v":"Bathroom","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":1310,"y":2100,"wires":[["7679b9f7.60cbe"],["d3e02686.feaf7"],["4dfe533e.92ee1c"]]},{"id":"7679b9f7.60cbe","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Asleep?","version":1,"outputs":2,"halt_if":"[\"Going to Sleep\", \"Sleeping\", \"Waking Up\"]","halt_if_type":"jsonata","halt_if_compare":"includes","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1415,"y":2060,"wires":[[],["aba2407f.56353"]],"icon":"font-awesome/fa-moon-o","l":false},{"id":"a08a4350.f9321","type":"function","z":"5288cc7c.ab3fc4","name":"Someone","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Someone\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1660,"y":2100,"wires":[["1beff2e3.5c52dd"]]},{"id":"2bf82c0b.b40c7c","type":"function","z":"5288cc7c.ab3fc4","name":"Someone","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Someone\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1660,"y":2060,"wires":[["b27c5fec.4dd478"]]},{"id":"d3e02686.feaf7","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.living_room_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1520,"y":2100,"wires":[["a08a4350.f9321"],[]]},{"id":"aba2407f.56353","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1520,"y":2060,"wires":[["2bf82c0b.b40c7c"],[]]},{"id":"1beff2e3.5c52dd","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5d84b3d6.bfa3fc","eb23d0bb.8cacb8"],"x":1735,"y":2100,"wires":[]},{"id":"b27c5fec.4dd478","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["a182e7fd.612e8","bd14274.f9a6ed8"],"x":1735,"y":2060,"wires":[]},{"id":"c5a0b7d8.5b3a4","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bedroom Presence","info":"","x":1860,"y":2060,"wires":[]},{"id":"a8c38dc5.52f65","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Living Room Presence","info":"","x":1870,"y":2100,"wires":[]},{"id":"c9c9219b.750c88","type":"trigger","z":"5288cc7c.ab3fc4","name":"15s","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"15","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":790,"y":2440,"wires":[["bd97498b.6e4748"]]},{"id":"bd97498b.6e4748","type":"function","z":"5288cc7c.ab3fc4","name":"Empty","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Empty\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1270,"y":2440,"wires":[["918ad969.a56cd8"]]},{"id":"b07cac7f.a2d008","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"LR Someone?","version":1,"outputs":2,"halt_if":"Someone","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.living_room_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":560,"y":2440,"wires":[["c9c9219b.750c88"],[]]},{"id":"b1146810.086c1","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"LR !Someone","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_select.living_room_presence","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ypl0z16l48","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"Someone"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":560,"y":2480,"wires":[["40841c6c.cfb6f4"],[]]},{"id":"40841c6c.cfb6f4","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":695,"y":2480,"wires":[["c9c9219b.750c88"]],"icon":"node-red/timer.svg","l":false},{"id":"86f8bd51.5ed2a8","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":435,"y":2440,"wires":[["b07cac7f.a2d008"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"68e6f5.8ba8710c","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"BR Someone?","version":1,"outputs":2,"halt_if":"Someone","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":560,"y":2280,"wires":[["ce5d0d69.939cb"],[]]},{"id":"ce5d0d69.939cb","type":"trigger","z":"5288cc7c.ab3fc4","name":"15s","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"15","extend":true,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":790,"y":2280,"wires":[["34577c93.622ed4"]]},{"id":"4ab6127c.632c2c","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":435,"y":2280,"wires":[["68e6f5.8ba8710c"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"39b9d53b.55f2da","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":695,"y":2320,"wires":[["ce5d0d69.939cb"]],"icon":"node-red/timer.svg","l":false},{"id":"34577c93.622ed4","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Asleep?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"[\"Going to Sleep\", \"Sleeping\", \"Waking Up\"]","halt_if_type":"jsonata","halt_if_compare":"includes","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":855,"y":2280,"wires":[[],["f357737b.3e16e8"]],"icon":"font-awesome/fa-moon-o","l":false},{"id":"d7529246.1f6dd","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"BR !Someone","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_select.bedroom_presence","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ypl0z16l48","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"Someone"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":560,"y":2320,"wires":[["39b9d53b.55f2da"],[]]},{"id":"eb934d23.7832","type":"comment","z":"5288cc7c.ab3fc4","name":"Reset","info":"This yellow timer node resets the timer that it's linked too. In this case, no message will be passed through.\n\nIt's useful in cases where something is scheduled but should no longer happen. ie. the Bedroom is about to be set to \"Empty\" but then there is new motion in there.","x":730,"y":2360,"wires":[]},{"id":"f357737b.3e16e8","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"P1 in Bed?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.bed_presence_p1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":970,"y":2280,"wires":[["9854607e.c219b"],["76fc9acd.a10f74"]]},{"id":"76fc9acd.a10f74","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"P2 in Bed?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.bed_presence_p2","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1130,"y":2280,"wires":[["101fd4d8.fa06c3"],["b85c288f.570488"]]},{"id":"b85c288f.570488","type":"function","z":"5288cc7c.ab3fc4","name":"Empty","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Empty\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"x":1270,"y":2280,"wires":[["35ea5fad.ddbe1"]]},{"id":"dcd9c750.2dee1","type":"comment","z":"5288cc7c.ab3fc4","name":"Restart","info":"If the bedroom is about to be reset because there's no longer any motion, but someone is in bed, then the timers to set the bedroom to empty should be restarted.\n\nThe timer will keep getting restarted until there is no-one in bed or if the timer is reset by new motion.","x":1150,"y":2240,"wires":[]},{"id":"5d67dde4.73d3f4","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["9854607e.c219b","101fd4d8.fa06c3","46757de4.99bab4"],"x":375,"y":2280,"wires":[["4ab6127c.632c2c"]]},{"id":"173dfbef.27b44c","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["bf69bc5d.9fb558"],"x":375,"y":2440,"wires":[["86f8bd51.5ed2a8"]]},{"id":"bd14274.f9a6ed8","type":"link in","z":"5288cc7c.ab3fc4","name":"Reset BR to Empty Timer","links":["b27c5fec.4dd478","e8398e5a.604ff8"],"x":615,"y":2360,"wires":[["39b9d53b.55f2da"]]},{"id":"eb23d0bb.8cacb8","type":"link in","z":"5288cc7c.ab3fc4","name":"Reset LR to Empty Timer","links":["1beff2e3.5c52dd","15bc1370.01b7dd"],"x":615,"y":2520,"wires":[["40841c6c.cfb6f4"]]},{"id":"9854607e.c219b","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5d67dde4.73d3f4"],"x":1075,"y":2240,"wires":[]},{"id":"101fd4d8.fa06c3","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5d67dde4.73d3f4"],"x":1235,"y":2240,"wires":[]},{"id":"35ea5fad.ddbe1","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["a182e7fd.612e8"],"x":1335,"y":2280,"wires":[]},{"id":"918ad969.a56cd8","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5d84b3d6.bfa3fc"],"x":1335,"y":2440,"wires":[]},{"id":"854551e0.1da7f8","type":"comment","z":"5288cc7c.ab3fc4","name":"3 - BLE ROOM PRESENCE","info":"","x":120,"y":2740,"wires":[]},{"id":"383a34d6.f3a994","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P1 BLE Room","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.p1_esp32_mqtt_room","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"not_home","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":false,"x":190,"y":2880,"wires":[["88b3d4ab.b9e668"],[]]},{"id":"6387557a.5447dc","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["168943e7.750404"],"x":135,"y":3220,"wires":[["8e964f03.a621f"]]},{"id":"168943e7.750404","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["6387557a.5447dc"],"x":1215,"y":2900,"wires":[]},{"id":"e7f3d57d.f0ab48","type":"function","z":"5288cc7c.ab3fc4","name":"Set Room","func":"newmsg = {};\nconst person_location_entity = msg.person_location_data.entity_id;\nconst new_room_to_set = msg.new_room_to_set;\nnewmsg.payload = { data: {\"entity_id\": person_location_entity, \"option\": new_room_to_set} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1560,"y":3200,"wires":[["1d60e010.ed1928"]]},{"id":"dcbcc503.1cfe18","type":"change","z":"5288cc7c.ab3fc4","name":"Set Bathroom","rules":[{"t":"set","p":"new_room_to_set","pt":"msg","to":"Bathroom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":3260,"wires":[["e7f3d57d.f0ab48"]]},{"id":"b579f899.8d04b8","type":"change","z":"5288cc7c.ab3fc4","name":"Set Living Room","rules":[{"t":"set","p":"new_room_to_set","pt":"msg","to":"Living Room","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":3120,"wires":[["e7f3d57d.f0ab48"]]},{"id":"57ec2d63.83185c","type":"change","z":"5288cc7c.ab3fc4","name":"Set Bedroom","rules":[{"t":"set","p":"new_room_to_set","pt":"msg","to":"Bedroom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1310,"y":3040,"wires":[["e7f3d57d.f0ab48"]]},{"id":"8527b8f0.b27108","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >10s?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"10000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1120,"y":3240,"wires":[["dcbcc503.1cfe18"],[]]},{"id":"58ebe28f.1a6b84","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >40s?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"40000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1120,"y":3280,"wires":[["dcbcc503.1cfe18"],[]]},{"id":"58a131c3.b60d8","type":"switch","z":"5288cc7c.ab3fc4","name":"LR Motion event <5mins ago?","property":"lr_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"300000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3120,"wires":[["b579f899.8d04b8"],["32f6c636.0e4b5a"]]},{"id":"32f6c636.0e4b5a","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >2mins?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"120000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1110,"y":3140,"wires":[["b579f899.8d04b8"],[]]},{"id":"f9b7c622.36197","type":"switch","z":"5288cc7c.ab3fc4","name":"BR Motion event <5mins ago?","property":"br_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"300000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3040,"wires":[["57ec2d63.83185c"],["98fba376.32ac2"]]},{"id":"98fba376.32ac2","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >2mins?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"120000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1110,"y":3060,"wires":[["57ec2d63.83185c"],[]]},{"id":"8beb558e.c6559","type":"switch","z":"5288cc7c.ab3fc4","name":"BR Motion event <3mins ago?","property":"br_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"180000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3220,"wires":[["8527b8f0.b27108"],["58ebe28f.1a6b84"]]},{"id":"9ecb8f97.1d3d","type":"switch","z":"5288cc7c.ab3fc4","name":"LR Motion event <3mins ago?","property":"lr_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"180000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3260,"wires":[["8527b8f0.b27108"],["58ebe28f.1a6b84"]]},{"id":"4cdbed18.928c7c","type":"switch","z":"5288cc7c.ab3fc4","name":"!In Bed?","property":"bed_presence","propertyType":"msg","rules":[{"t":"eq","v":"off/not automated","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":3140,"wires":[["58a131c3.b60d8"],["32f6c636.0e4b5a"]]},{"id":"b8bd143e.0afcd8","type":"switch","z":"5288cc7c.ab3fc4","name":"BR !Set?","property":"person_location","propertyType":"msg","rules":[{"t":"neq","v":"Bedroom","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":3060,"wires":[["f9b7c622.36197"]]},{"id":"5ffd5293.322114","type":"switch","z":"5288cc7c.ab3fc4","name":"!In Bed?","property":"bed_presence","propertyType":"msg","rules":[{"t":"eq","v":"off/not automated","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":3280,"wires":[["8beb558e.c6559","9ecb8f97.1d3d"],["58ebe28f.1a6b84"]]},{"id":"c815ef2e.a47ff","type":"switch","z":"5288cc7c.ab3fc4","name":"LR !Set?","property":"person_location","propertyType":"msg","rules":[{"t":"neq","v":"Living Room","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":460,"y":3140,"wires":[["4cdbed18.928c7c"]]},{"id":"8e964f03.a621f","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Room?","property":"ble_room","propertyType":"msg","rules":[{"t":"eq","v":"bedroom","vt":"str"},{"t":"eq","v":"living_room","vt":"str"},{"t":"eq","v":"bathroom","vt":"str"},{"t":"eq","v":"kitchen","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":250,"y":3220,"wires":[["b8bd143e.0afcd8"],["c815ef2e.a47ff"],["723a5e7a.705be8","da4ba178.958dd"],[]]},{"id":"723a5e7a.705be8","type":"switch","z":"5288cc7c.ab3fc4","name":"Bath !Set?","property":"person_location","propertyType":"msg","rules":[{"t":"neq","v":"Bathroom","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":3280,"wires":[["5ffd5293.322114"]]},{"id":"61ae8220.f124dc","type":"function","z":"5288cc7c.ab3fc4","name":"Bed Presence","func":"const globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant; //Generic bits to get HA states\nperson = msg.person; //Create constant for the relevant person\nbed_presence_entity = \"binary_sensor.bed_presence_\" + person; //Create string for the bed presence of the relevant person\nbed_presence_state = ha.states[bed_presence_entity].state; //Get Bed Presence State for the relevant person\n\nconst automate_bed_presence = ha.states['input_boolean.automations_presence_bed'].state; //Check if bed presence automations are on\n\n\nlet bed_presence = [];\n\nif (automate_bed_presence == 'on') {\n if (bed_presence_state == 'on') {\n bed_presence = \"on\";\n } else {\n bed_presence = \"off/not automated\";\n }\n}\nelse {\n bed_presence = \"off/not automated\";\n}\n\nmsg.bed_presence = bed_presence;\nreturn msg;\n\n//This code sets msg.bed_presence to either on of off/not automated\n//It sets to on if bed presence automations are on and bed presence is detected.\n//Otherwise it sets it to off/not automated","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1120,"y":2900,"wires":[["168943e7.750404"]]},{"id":"fac5d847.b76e58","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Person Loc?","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.{{person}}_location","state_type":"str","state_location":"person_location","override_payload":"msg","entity_location":"person_location_data","override_data":"msg","blockInputOverrides":false,"x":970,"y":2900,"wires":[["61ae8220.f124dc"]]},{"id":"87ec5ac2.02b1a8","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"LR Motion?","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.living_room_motion","state_type":"str","state_location":"lr_motion","override_payload":"msg","entity_location":"lr_motion_data","override_data":"msg","blockInputOverrides":false,"x":830,"y":2900,"wires":[["fac5d847.b76e58"]]},{"id":"b8790301.97ed68","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"BR Motion?","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.bedroom_motion","state_type":"str","state_location":"br_motion","override_payload":"msg","entity_location":"br_motion_data","override_data":"msg","blockInputOverrides":false,"x":690,"y":2900,"wires":[["87ec5ac2.02b1a8"]]},{"id":"5064c681.79c2b","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence_ble","state_type":"str","state_location":"","override_payload":"msg","entity_location":"","override_data":"msg","blockInputOverrides":true,"x":575,"y":2900,"wires":[["b8790301.97ed68"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"17dd26dd.b3ab51","type":"change","z":"5288cc7c.ab3fc4","name":"Save BLE Room","rules":[{"t":"move","p":"payload","pt":"msg","to":"ble_room","tot":"msg"},{"t":"move","p":"data","pt":"msg","to":"ble_room_data","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":450,"y":2900,"wires":[["5064c681.79c2b"]]},{"id":"88b3d4ab.b9e668","type":"change","z":"5288cc7c.ab3fc4","name":"Change","rules":[{"t":"change","p":"topic","pt":"msg","from":"sensor.","fromt":"str","to":"","tot":"str"},{"t":"change","p":"topic","pt":"msg","from":"_esp32_mqtt_room","fromt":"str","to":"","tot":"str"},{"t":"set","p":"person","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":315,"y":2900,"wires":[["17dd26dd.b3ab51"]],"l":false},{"id":"ff9d6625.fbb798","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P2 BLE Room","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"sensor.p2_esp32_mqtt_room","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"not_home","halt_if_type":"str","halt_if_compare":"is_not","outputs":2,"output_only_on_state_change":false,"x":190,"y":2920,"wires":[["88b3d4ab.b9e668"],[]]},{"id":"1d60e010.ed1928","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5664ddce.8a908c"],"x":1635,"y":3200,"wires":[]},{"id":"a9ff3b3.6c6d3c8","type":"comment","z":"5288cc7c.ab3fc4","name":"4 - UPDATE ROOM PRESENCE","info":"This flow is triggered by a change in a person's \"input_select.person_location\".\nIt can also be manually triggered via the link node.","x":130,"y":3500,"wires":[]},{"id":"e42b448c.ef17b8","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P1 Loc Change?","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.p1_location","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":200,"y":3640,"wires":[["c9425ce8.66df28"]]},{"id":"f20aef61.629898","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P2 Loc Change?","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_select.p2_location","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":200,"y":3680,"wires":[["c9425ce8.66df28"]]},{"id":"c9425ce8.66df28","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":335,"y":3660,"wires":[["2794feb5.0243a2","ba4ed46a.62d7d","8550ade5.5a2da8","46da1e12.f4dcb8"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"2794feb5.0243a2","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Sleeping?","version":1,"outputs":2,"halt_if":"[\"Going to Sleep\", \"Sleeping\", \"Waking Up\"]","halt_if_type":"jsonata","halt_if_compare":"includes","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":415,"y":3580,"wires":[[],["d120bac5.382f88"]],"icon":"font-awesome/fa-moon-o","l":false},{"id":"ba4ed46a.62d7d","type":"function","z":"5288cc7c.ab3fc4","name":"Kitchen Pres.","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst groupEntity = ha.states['group.person_locations'];\nlet occupants = [];\n\n//*******Just change the room below to whichever room the flow is for*******\n\nroom = \"Kitchen\"; //Room should be whatever input_select.*room*_presence would be set to\n //eg Bedroom or Living Room (capitalised and with a space if required)\n\ngroupEntity.attributes.entity_id.forEach(i => {\n if(ha.states[i].state === room) {\n occupants.push(ha.states[i].attributes.friendly_name.replace(\" Location\", \"\"));\n //The push bit adds the friendly name of any persons location input select which matches the state (ie Living Room)\n //The replace bit clears the Location part from the friendly name leaving just the initials. \n }\n});\n\n//the join function creates '+' separated string from the array.\noccupants = occupants.join(' + ');\n\nif (occupants === '') {\n //If no occupation is detected, set the room to Empty\n occupants = \"Empty\";\n}\n\nmsg.payload = { data: { \"option\": occupants} };\n\n//Output to top channel by default but to bottom channel if room will be set to Empty\nif (occupants == \"Empty\") {\n return [ null, msg ];\n} else {\n return [ msg, null ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":550,"y":3820,"wires":[["ea484fff.dcf4c8"],["593ce45e.65b414"]]},{"id":"ea484fff.dcf4c8","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":655,"y":3800,"wires":[["45faae8e.c5e6c","318b9cc6.ef1c4c"]],"icon":"node-red/timer.svg","l":false},{"id":"45faae8e.c5e6c","type":"trigger","z":"5288cc7c.ab3fc4","name":"1m","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"60","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":855,"y":3820,"wires":[["318b9cc6.ef1c4c"]],"l":false},{"id":"593ce45e.65b414","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Kitchen !Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"input_select.kitchen_presence","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":720,"y":3840,"wires":[["45faae8e.c5e6c"],[]]},{"id":"dc93395a.575348","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":655,"y":3560,"wires":[["13d7989a.2a71c7","84fc07ed.8a51e"]],"icon":"node-red/timer.svg","l":false},{"id":"13d7989a.2a71c7","type":"trigger","z":"5288cc7c.ab3fc4","name":"2m","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":855,"y":3580,"wires":[["84fc07ed.8a51e"]],"l":false},{"id":"e10000fb.aff688","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"BR !Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"input_select.bedroom_presence","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":710,"y":3600,"wires":[["13d7989a.2a71c7"],[]]},{"id":"78b380c3.3c33a8","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":655,"y":3640,"wires":[["16575ad8.35555d","6242a51d.fd28b4"]],"icon":"node-red/timer.svg","l":false},{"id":"16575ad8.35555d","type":"trigger","z":"5288cc7c.ab3fc4","name":"2m","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"30","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":855,"y":3660,"wires":[["6242a51d.fd28b4"]],"l":false},{"id":"f72237b1.cadfd","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"LR !Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"input_select.living_room_presence","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":710,"y":3680,"wires":[["16575ad8.35555d"],[]]},{"id":"6242a51d.fd28b4","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["5d84b3d6.bfa3fc"],"x":915,"y":3640,"wires":[]},{"id":"84fc07ed.8a51e","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["a182e7fd.612e8"],"x":915,"y":3560,"wires":[]},{"id":"318b9cc6.ef1c4c","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["9a4bb64a.5d689"],"x":915,"y":3800,"wires":[]},{"id":"92d5e1a7.ac0a48","type":"delay","z":"5288cc7c.ab3fc4","name":"5s","pauseType":"delay","timeout":"5","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":230,"y":80,"wires":[["344c407d.43aba8"]]},{"id":"b585e5e0.c9ccb","type":"comment","z":"5288cc7c.ab3fc4","name":"Frequently Used Nodes","info":"These nodes are gathered in one place so it's easy to tell which flows can set what.","x":100,"y":140,"wires":[]},{"id":"ddf9bba2.982f7","type":"comment","z":"5288cc7c.ab3fc4","name":"2.3 - Set rooms to \"Empty\"","info":"","x":150,"y":2220,"wires":[]},{"id":"f7d4eed1.80fa28","type":"comment","z":"5288cc7c.ab3fc4","name":"Bedroom Occupied","info":"","x":450,"y":1580,"wires":[]},{"id":"6721caf2.3a2d4c","type":"comment","z":"5288cc7c.ab3fc4","name":"Bedroom Not Occupied","info":"","x":460,"y":1620,"wires":[]},{"id":"58305a61.c8dd74","type":"comment","z":"5288cc7c.ab3fc4","name":"Living Room Occupied","info":"","x":460,"y":1700,"wires":[]},{"id":"6adec942.5fb9c8","type":"comment","z":"5288cc7c.ab3fc4","name":"Living Room Not Occupied","info":"","x":470,"y":1740,"wires":[]},{"id":"6099c5a3.df991c","type":"change","z":"5288cc7c.ab3fc4","name":"Bedroom","rules":[{"t":"set","p":"room","pt":"msg","to":"Bedroom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2000,"wires":[["5d5b5231.6cab34"]]},{"id":"96c55e13.7b6a58","type":"change","z":"5288cc7c.ab3fc4","name":"Living Room","rules":[{"t":"set","p":"room","pt":"msg","to":"Living Room","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":2040,"wires":[["5d5b5231.6cab34"]]},{"id":"68fefd59.b05844","type":"comment","z":"5288cc7c.ab3fc4","name":"Set House Presence","info":"","x":790,"y":1280,"wires":[]},{"id":"d97068da.4e90c8","type":"comment","z":"5288cc7c.ab3fc4","name":"Set House Presence","info":"","x":830,"y":1080,"wires":[]},{"id":"519999d.74903e8","type":"comment","z":"5288cc7c.ab3fc4","name":"P1 Loc.","info":"","x":590,"y":560,"wires":[]},{"id":"bee4ccf0.3d61b","type":"comment","z":"5288cc7c.ab3fc4","name":"P2 Loc.","info":"","x":590,"y":600,"wires":[]},{"id":"8824297c.071d6","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bedroom Presence","info":"","x":1480,"y":2280,"wires":[]},{"id":"63284611.d7e238","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Living Room Presence","info":"","x":1490,"y":2440,"wires":[]},{"id":"7ad94858.b67b98","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Person Location","info":"","x":1770,"y":3200,"wires":[]},{"id":"1d787705.297769","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bedroom Presence","info":"","x":1060,"y":3560,"wires":[]},{"id":"cfc742de.3f0718","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Living Room Presence","info":"","x":1070,"y":3640,"wires":[]},{"id":"35f4aaf0.930bee","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Kitchen Presence","info":"","x":1060,"y":3800,"wires":[]},{"id":"75a16494.dc25a4","type":"comment","z":"5288cc7c.ab3fc4","name":"3.1 - BLE Inputs and Checking other States","info":"","x":200,"y":2800,"wires":[]},{"id":"b9bc98a9.92f45","type":"comment","z":"5288cc7c.ab3fc4","name":"3.2 - Set Room Presence","info":"","x":150,"y":3000,"wires":[]},{"id":"ed7d57df.d86e1","type":"comment","z":"5288cc7c.ab3fc4","name":"Note","info":"It's important to leave these as person.p1 rather than input_select.p1_location.\n\nSince the person entity can be slow to update, it's possible that BLE kicks in before person.p1 goes to home so a room would be assigned and input_select.p1_location would never actually go to \"Just Arrived\" or \"Home\"","x":210,"y":1140,"wires":[]},{"id":"88b3e2ad.58aa6","type":"comment","z":"5288cc7c.ab3fc4","name":"Note","info":"This way of checking is a little lazy but works just fine for only 2 people. I will update this to work for any number of people at some point.","x":530,"y":1240,"wires":[]},{"id":"cdac170b.139388","type":"comment","z":"5288cc7c.ab3fc4","name":"?","info":"A question mark icon indicates a place where a type of automation can be stopped.\n\nIn this case, this flow to set room presence will only continue if input_select.automations_presence is set to on.\n\nThis makes it easy to stop certain types of automations from the frontend.","x":850,"y":2000,"wires":[]},{"id":"8dcdc4e8.f00c08","type":"comment","z":"5288cc7c.ab3fc4","name":"Moon","info":"A moon icon indicates a place where input_select.bedroom_presence is checked. If the presence is set to any type of sleeping, then this should not be overwritten (unless an alarm is stopped it's manually overridden). This check makes sure that flows don't overwrite bedroom presence when someone is sleeping.","x":1450,"y":2020,"wires":[]},{"id":"37610f59.944c18","type":"comment","z":"5288cc7c.ab3fc4","name":"Reset","info":"This yellow timer node resets the timer that it's linked too. In this case, no message will be passed through.\n\nIt's useful in cases where something is scheduled but should no longer happen. ie. the Bedroom is about to be set to \"Empty\" but then there is new motion in there.","x":730,"y":2520,"wires":[]},{"id":"34f5a485.462404","type":"comment","z":"5288cc7c.ab3fc4","name":"Restart","info":"If the bedroom is about to be reset because there's no longer any motion, but someone is in bed, then the timers to set the bedroom to empty should be restarted.\n\nThe timer will keep getting restarted until there is no-one in bed or if the timer is reset by new motion.","x":1310,"y":2240,"wires":[]},{"id":"c3a690df.a63bd","type":"api-call-service","z":"5288cc7c.ab3fc4","name":"Set Bathroom Pres.","version":1,"debugenabled":false,"service_domain":"input_select","service":"select_option","entityId":"input_select.bathroom_presence","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":270,"y":320,"wires":[[]]},{"id":"d0112c21.ab7008","type":"link in","z":"5288cc7c.ab3fc4","name":"Set Bathroom Presence","links":["9bb63db4.f95e5","41b0f288.f43a7c","43e007d8.dd1968","48e1662e.5bd418"],"x":135,"y":320,"wires":[[]]},{"id":"392f3e3c.c6c752","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Shower Start","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.bathroom_humidity","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"yg7f83ti0n","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":">=","comparatorValueDatatype":"str","comparatorValue":"75"},{"id":"zff0ihn6oz","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"<","comparatorValueDatatype":"str","comparatorValue":"75"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":190,"y":1820,"wires":[["5d064029.14b678"],[]]},{"id":"7a68bb22.80ddc4","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Shower End","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"sensor.bathroom_humidity","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"13eor7lru8f","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":">","comparatorValueDatatype":"str","comparatorValue":"75"},{"id":"s4ta339albe","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"<=","comparatorValueDatatype":"str","comparatorValue":"75"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":190,"y":1860,"wires":[["425a5a7b.9f5a1c"],[]]},{"id":"5d064029.14b678","type":"link out","z":"5288cc7c.ab3fc4","name":"LR Motion Cleared","links":["717f79aa.3b3848","d63e4c73.b2948","506765ac.271304"],"x":315,"y":1820,"wires":[]},{"id":"717f79aa.3b3848","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["5d064029.14b678"],"x":635,"y":1820,"wires":[["9fbaa152.f7b428"]]},{"id":"426e6909.a52ee8","type":"comment","z":"5288cc7c.ab3fc4","name":"Bathroom Occupied","info":"","x":450,"y":1820,"wires":[]},{"id":"fe2e8e29.da5c1","type":"comment","z":"5288cc7c.ab3fc4","name":"Bathroom Not Occupied","info":"","x":460,"y":1860,"wires":[]},{"id":"425a5a7b.9f5a1c","type":"link out","z":"5288cc7c.ab3fc4","name":"LR Motion Cleared","links":["324775a4.48a972"],"x":315,"y":1860,"wires":[]},{"id":"324775a4.48a972","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["425a5a7b.9f5a1c"],"x":635,"y":1860,"wires":[["49b93735.b55718"]]},{"id":"35a85883.841b7","type":"change","z":"5288cc7c.ab3fc4","name":"Bathroom","rules":[{"t":"set","p":"room","pt":"msg","to":"Bathroom","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":2080,"wires":[["5d5b5231.6cab34"]]},{"id":"d63e4c73.b2948","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["5d064029.14b678"],"x":375,"y":2080,"wires":[["35a85883.841b7"]]},{"id":"e262c63d.008188","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P1 in Bed","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bed_presence_p1","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,"x":180,"y":1520,"wires":[["e8398e5a.604ff8"],[]]},{"id":"5368d354.094b0c","type":"server-state-changed","z":"5288cc7c.ab3fc4","name":"P2 in Bed","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.bed_presence_p2","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,"x":180,"y":1560,"wires":[["e8398e5a.604ff8"],[]]},{"id":"af1f6839.47cd7","type":"trigger","z":"5288cc7c.ab3fc4","name":"15s","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"15","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":790,"y":2600,"wires":[["f6d4530b.e719f8"]]},{"id":"f6d4530b.e719f8","type":"function","z":"5288cc7c.ab3fc4","name":"Empty","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Empty\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1270,"y":2600,"wires":[["41b0f288.f43a7c"]]},{"id":"621e7e36.4914d","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Bath Someone?","version":1,"outputs":2,"halt_if":"Someone","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bathroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":560,"y":2600,"wires":[["af1f6839.47cd7"],[]]},{"id":"27e8b920.cb8cae","type":"trigger-state","z":"5288cc7c.ab3fc4","name":"Bath !Someone","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"input_select.bathroom_presence","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"ypl0z16l48","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"Someone"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":true,"state_type":"str","x":560,"y":2640,"wires":[["e119d7c0.71396"],[]]},{"id":"e119d7c0.71396","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"},{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":695,"y":2640,"wires":[["af1f6839.47cd7"]],"icon":"node-red/timer.svg","l":false},{"id":"2b5909a4.3721ee","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":435,"y":2600,"wires":[["621e7e36.4914d"],[]],"icon":"font-awesome/fa-question","l":false},{"id":"687a1ad3.732314","type":"link in","z":"5288cc7c.ab3fc4","name":"","links":["bf69bc5d.9fb558"],"x":375,"y":2600,"wires":[["2b5909a4.3721ee"]]},{"id":"506765ac.271304","type":"link in","z":"5288cc7c.ab3fc4","name":"Reset LR to Empty Timer","links":["43e007d8.dd1968","5d064029.14b678"],"x":615,"y":2680,"wires":[["e119d7c0.71396"]]},{"id":"41b0f288.f43a7c","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["d0112c21.ab7008"],"x":1335,"y":2600,"wires":[]},{"id":"9d38e3bb.671ee8","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bathroom Presence","info":"","x":1480,"y":2600,"wires":[]},{"id":"a1a4a933.5c247","type":"comment","z":"5288cc7c.ab3fc4","name":"Reset","info":"This yellow timer node resets the timer that it's linked too. In this case, no message will be passed through.\n\nIt's useful in cases where something is scheduled but should no longer happen. ie. the Bedroom is about to be set to \"Empty\" but then there is new motion in there.","x":730,"y":2680,"wires":[]},{"id":"e579565a.c990f","type":"comment","z":"5288cc7c.ab3fc4","name":"Note","info":"Add conditions here that must be satisfied for a room to be set to empty (eg the TV is off) - these conditions should be wired in to restart the timer looking to set the room presence to Empty like in the bed presence example above.","x":950,"y":2420,"wires":[]},{"id":"61ec7b10.c699fc","type":"function","z":"5288cc7c.ab3fc4","name":"Someone","func":"newmsg = {};\nnewmsg.payload = { data: { \"option\": \"Someone\"} }; \nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1660,"y":2140,"wires":[["43e007d8.dd1968"]]},{"id":"4dfe533e.92ee1c","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.bathroom_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1520,"y":2140,"wires":[["61ec7b10.c699fc"],[]]},{"id":"43e007d8.dd1968","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["d0112c21.ab7008","506765ac.271304"],"x":1735,"y":2140,"wires":[]},{"id":"532a8c02.c11bfc","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bathroom Presence","info":"","x":1860,"y":2140,"wires":[]},{"id":"7af6152f.7205fc","type":"change","z":"5288cc7c.ab3fc4","name":"Set Bathroom","rules":[{"t":"set","p":"new_room_to_set","pt":"msg","to":"Kitchen","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1320,"y":3380,"wires":[["e7f3d57d.f0ab48"]]},{"id":"1c1324eb.da25d3","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >10s?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"10000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1120,"y":3360,"wires":[["7af6152f.7205fc"],[]]},{"id":"cb6be652.f8a89","type":"switch","z":"5288cc7c.ab3fc4","name":"BLE Same for >40s?","property":"ble_room_data.new_state.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"40000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1120,"y":3400,"wires":[["7af6152f.7205fc"],[]]},{"id":"38c4ff5e.35d2c8","type":"switch","z":"5288cc7c.ab3fc4","name":"BR Motion event <3mins ago?","property":"br_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"180000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3340,"wires":[["1c1324eb.da25d3"],["cb6be652.f8a89"]]},{"id":"9864a1c0.271428","type":"switch","z":"5288cc7c.ab3fc4","name":"LR Motion event <3mins ago?","property":"lr_motion_data.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"180000","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":3380,"wires":[["1c1324eb.da25d3"],["cb6be652.f8a89"]]},{"id":"d5472e42.9a6b88","type":"switch","z":"5288cc7c.ab3fc4","name":"!In Bed?","property":"bed_presence","propertyType":"msg","rules":[{"t":"eq","v":"off/not automated","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":3400,"wires":[["38c4ff5e.35d2c8","9864a1c0.271428"],["cb6be652.f8a89"]]},{"id":"da4ba178.958dd","type":"switch","z":"5288cc7c.ab3fc4","name":"Kitchen !Set?","property":"person_location","propertyType":"msg","rules":[{"t":"neq","v":"Kitchen","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":3400,"wires":[["d5472e42.9a6b88"]]},{"id":"2c0f64d9.118e2c","type":"comment","z":"5288cc7c.ab3fc4","name":"Startup","info":"This short section is triggered when Home Assistant restarts. I have an sensor.uptime_hours which keeps track of how long Home Assistant has been running.\n\nWhen uptime reaches a certain time, the flows that run on startup are all triggered.","x":50,"y":20,"wires":[]},{"id":"c60ba24.44afe6","type":"comment","z":"5288cc7c.ab3fc4","name":"Bedroom Occupied","info":"","x":210,"y":2000,"wires":[]},{"id":"4aca60a0.dd8fe8","type":"comment","z":"5288cc7c.ab3fc4","name":"Living Room Occupied","info":"","x":220,"y":2040,"wires":[]},{"id":"53afc584.5d34b4","type":"comment","z":"5288cc7c.ab3fc4","name":"Bathroom Occupied","info":"","x":210,"y":2080,"wires":[]},{"id":"57ab9642.3afa38","type":"comment","z":"5288cc7c.ab3fc4","name":"Bedroom Not Occupied","info":"","x":220,"y":2280,"wires":[]},{"id":"c43ee413.56de78","type":"comment","z":"5288cc7c.ab3fc4","name":"Living Room Not Occupied","info":"","x":230,"y":2440,"wires":[]},{"id":"cb0efb1a.73dc58","type":"comment","z":"5288cc7c.ab3fc4","name":"Bathroom Not Occupied","info":"","x":220,"y":2600,"wires":[]},{"id":"5ff53ecb.ca177","type":"change","z":"5288cc7c.ab3fc4","name":"RESET","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":655,"y":3720,"wires":[["4831bc39.67c164","48e1662e.5bd418"]],"icon":"node-red/timer.svg","l":false},{"id":"4831bc39.67c164","type":"trigger","z":"5288cc7c.ab3fc4","name":"1m","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"60","extend":true,"units":"s","reset":"stop","bytopic":"all","topic":"topic","outputs":1,"x":855,"y":3740,"wires":[["48e1662e.5bd418"]],"l":false},{"id":"6e776070.b0418","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Bathroom !Empty?","version":1,"outputs":2,"halt_if":"Empty","halt_if_type":"str","halt_if_compare":"is_not","override_topic":false,"entity_id":"input_select.bathroom_presence","state_type":"str","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":730,"y":3760,"wires":[["4831bc39.67c164"],[]]},{"id":"48e1662e.5bd418","type":"link out","z":"5288cc7c.ab3fc4","name":"","links":["9a4bb64a.5d689","d0112c21.ab7008"],"x":915,"y":3720,"wires":[]},{"id":"d0fed4ac.7b686","type":"comment","z":"5288cc7c.ab3fc4","name":"Set Bathroom Presence","info":"","x":1060,"y":3720,"wires":[]},{"id":"928e0615.f54368","type":"comment","z":"5288cc7c.ab3fc4","name":"Generic Pres. Considered","info":"The bedroom and living room have motion sensors so the function node accounts for those too in the setting of room presence.\n\nA list '+' seperated list of room occupants is created. \n - the room's input_select.*room*_presence is updated with this list of occupants.\n\nIf the list is empty (ie no people are detected in the room by BLE):\n There is a check for motion in the room\n If there is motion:\n - the room's input_select.*room*_presence is set to \"Someone\".\n This is a bit like reverting back to generic room presence (and is helpful in case BLE incorrectly causes someone to move to a difference room briefly).\n - also any timer about to the set the room to \"Empty\" is cancelled.\n If there is no motion:\n - the room's input_select.*room*_presence is set to \"Empty\" after a short delay.\n ","x":510,"y":3540,"wires":[]},{"id":"858571ec.8a124","type":"comment","z":"5288cc7c.ab3fc4","name":"Generic Pres. !Considered","info":"The bathroom and kitchen do not have motion sensors so the function node doesn't account for motion in the setting of room presence here.\n\nA list '+' seperated list of room occupants is created. \n - the room's input_select.*room*_presence is updated with this list of occupants.\n\nIf the list is empty (ie no people are detected in the room by BLE):\n - the room's input_select.*room*_presence is set to \"Empty\" after a short delay.\n - also any timer about to the set the room to \"Empty\" is cancelled.","x":510,"y":3860,"wires":[]},{"id":"fb322e4c.ae8fe","type":"comment","z":"5288cc7c.ab3fc4","name":"30s Delay","info":"","x":860,"y":3520,"wires":[]},{"id":"88d59fb0.da0cb","type":"change","z":"5288cc7c.ab3fc4","name":"Bedroom Generic Presence to TRUE","rules":[{"t":"set","p":"Bedroom_generic_presence","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":1580,"wires":[[]]},{"id":"542dfc04.782c7c","type":"change","z":"5288cc7c.ab3fc4","name":"Bedroom Generic Presence to FALSE","rules":[{"t":"set","p":"Bedroom_generic_presence","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":1620,"wires":[[]]},{"id":"e77860dc.7dbab","type":"change","z":"5288cc7c.ab3fc4","name":"Living Room Generic Presence to TRUE","rules":[{"t":"set","p":"Living_Room_generic_presence","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":1700,"wires":[[]]},{"id":"9fbaa152.f7b428","type":"change","z":"5288cc7c.ab3fc4","name":"Bathroom Generic Presence to TRUE","rules":[{"t":"set","p":"Bathroom_generic_presence","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":1820,"wires":[[]]},{"id":"49b93735.b55718","type":"change","z":"5288cc7c.ab3fc4","name":"Bathroom Generic Presence to FALSE","rules":[{"t":"set","p":"Bathroom_generic_presence","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":830,"y":1860,"wires":[[]]},{"id":"6d39f2bc.f6f62c","type":"change","z":"5288cc7c.ab3fc4","name":"Living Room Generic Presence to FALSE","rules":[{"t":"set","p":"Living_Room_generic_presence","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":840,"y":1740,"wires":[[]]},{"id":"d120bac5.382f88","type":"function","z":"5288cc7c.ab3fc4","name":"Bedroom Pres.","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst groupEntity = ha.states['group.person_locations'];\nlet occupants = [];\n\n//*******Just change the room below to whichever room the flow is for*******\n\nroom = \"Bedroom\"; //Room should be whatever input_select.*room*_presence would be set to\n //eg Bedroom or Living Room (capitalised and with a space if required)\n//Next, set up the variable that is the flow variable indicating generic room presence - this is checked further down\ngeneric_room_presence = room.replace(\" \", \"_\") + \"_generic_presence\";\n\ngroupEntity.attributes.entity_id.forEach(i => {\n if(ha.states[i].state === room) {\n occupants.push(ha.states[i].attributes.friendly_name.replace(\" Location\", \"\"));\n //The push bit adds the friendly name of any persons location input select which matches the state (ie Living Room)\n //The replace bit clears the Location part from the friendly name leaving just the initials. \n }\n});\n\n//the join function creates '+' separated string from the array.\noccupants = occupants.join(' + ');\n\n//If no BLE occupation is detected but Generic Room Presence is detected (motion/bed/TV etc.), set the room to Someone\n//Otherwise with no BLE or Generic Presence, set to Empty \nif (occupants === '') {\n if (flow.get(generic_room_presence) === true) {\n occupants = \"Someone\";\n } else {\n occupants = \"Empty\";\n }\n}\n\nmsg.payload = { data: { \"option\": occupants} };\n\n//Output to top channel by default but to bottom channel if room will be set to Empty\nif (occupants == \"Empty\") {\n return [ null, msg ];\n} else {\n return [ msg, null ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":540,"y":3580,"wires":[["dc93395a.575348"],["e10000fb.aff688"]]},{"id":"8550ade5.5a2da8","type":"function","z":"5288cc7c.ab3fc4","name":"Living Room Pres.","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst groupEntity = ha.states['group.person_locations'];\nlet occupants = [];\n\n//*******Just change the room below to whichever room the flow is for*******\n\nroom = \"Living Room\"; //Room should be whatever input_select.*room*_presence would be set to\n //eg Bedroom or Living Room (capitalised and with a space if required)\n//Next, set up the variable that is the flow variable indicating generic room presence - this is checked further down\ngeneric_room_presence = room.replace(\" \", \"_\") + \"_generic_presence\";\n\ngroupEntity.attributes.entity_id.forEach(i => {\n if(ha.states[i].state === room) {\n occupants.push(ha.states[i].attributes.friendly_name.replace(\" Location\", \"\"));\n //The push bit adds the friendly name of any persons location input select which matches the state (ie Living Room)\n //The replace bit clears the Location part from the friendly name leaving just the initials. \n }\n});\n\n//the join function creates '+' separated string from the array.\noccupants = occupants.join(' + ');\n\n//If no BLE occupation is detected but Generic Room Presence is detected (motion/bed/TV etc.), set the room to Someone\n//Otherwise with no BLE or Generic Presence, set to Empty \nif (occupants === '') {\n if (flow.get(generic_room_presence) === true) {\n occupants = \"Someone\";\n } else {\n occupants = \"Empty\";\n }\n}\n\nmsg.payload = { data: { \"option\": occupants} };\n\n//Output to top channel by default but to bottom channel if room will be set to Empty\nif (occupants == \"Empty\") {\n return [ null, msg ];\n} else {\n return [ msg, null ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":530,"y":3660,"wires":[["78b380c3.3c33a8"],["f72237b1.cadfd"]]},{"id":"46da1e12.f4dcb8","type":"function","z":"5288cc7c.ab3fc4","name":"Bathroom Pres.","func":"//code modified from: https://community.home-assistant.io/t/examples-for-using-the-new-get-entities-node/85777/4\nconst globalHomeAssistant = global.get('homeassistant');\nconst ha = globalHomeAssistant.homeAssistant;\nconst groupEntity = ha.states['group.person_locations'];\nlet occupants = [];\n\n//*******Just change the room below to whichever room the flow is for*******\n\nroom = \"Bathroom\"; //Room should be whatever input_select.*room*_presence would be set to\n //eg Bedroom or Living Room (capitalised and with a space if required)\n//Next, set up the variable that is the flow variable indicating generic room presence - this is checked further down\ngeneric_room_presence = room.replace(\" \", \"_\") + \"_generic_presence\";\n\ngroupEntity.attributes.entity_id.forEach(i => {\n if(ha.states[i].state === room) {\n occupants.push(ha.states[i].attributes.friendly_name.replace(\" Location\", \"\"));\n //The push bit adds the friendly name of any persons location input select which matches the state (ie Living Room)\n //The replace bit clears the Location part from the friendly name leaving just the initials. \n }\n});\n\n//the join function creates '+' separated string from the array.\noccupants = occupants.join(' + ');\n\n//If no BLE occupation is detected but Generic Room Presence is detected (motion/bed/TV etc.), set the room to Someone\n//Otherwise with no BLE or Generic Presence, set to Empty \nif (occupants === '') {\n if (flow.get(generic_room_presence) === true) {\n occupants = \"Someone\";\n } else {\n occupants = \"Empty\";\n }\n}\n\nmsg.payload = { data: { \"option\": occupants} };\n\n//Output to top channel by default but to bottom channel if room will be set to Empty\nif (occupants == \"Empty\") {\n return [ null, msg ];\n} else {\n return [ msg, null ];\n}","outputs":2,"noerr":0,"initialize":"","finalize":"","x":540,"y":3740,"wires":[["5ff53ecb.ca177"],["6e776070.b0418"]]},{"id":"3fcf7ffc.085798","type":"comment","z":"5288cc7c.ab3fc4","name":"Note","info":"These flow variable keep track of whether Generic Room Presence is observed in a room. They are used later in Step 4 to set the presence in each individual room.\n\nThe naming convention should be followed carefully.\nThe variable should start with:\n\nThe name of the room (including capitals) and underscore separated if required (eg \"Bedroom\" or \"Living_Room\"). \nThis should be followed by \"_generic_presence\"\n\nSo for the bedroom the flow variable would be \"Bedroom_generic_presence\"\nFor the Living Room the flow variable would be \"Living_Room_generic_presence\"","x":730,"y":1540,"wires":[]},{"id":"ec32b0cf.4666e","type":"comment","z":"5288cc7c.ab3fc4","name":"Note","info":"The sensors that report BLE room presence that I use are named sensor.*person*_esp32_mqtt_room.\neg: sensor.p1_esp32_mqtt_room\n\nThis is important since it is used to set the msg.person variable in the following change node. The \"sensor.\" and \"_esp32_mqtt_room\" parts are stripped from the incoming entity name allowing msg.person just to be set to the initials of the relevant person.\n\nThese initials should also match the corresponding input select (eg input_select.p1_location) for the person.","x":170,"y":2840,"wires":[]},{"id":"c0268126.2dc59","type":"comment","z":"5288cc7c.ab3fc4","name":"https://gergo.io/comprehensive-room-presence-detection/","info":"","x":1080,"y":60,"wires":[]},{"id":"ccb1149a.656c5","type":"api-current-state","z":"5288cc7c.ab3fc4","name":"Cont.?","server":"fc33606a.00a2c","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"input_boolean.automations_presence","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":315,"y":1020,"wires":[[],[]],"icon":"font-awesome/fa-question","l":false},{"id":"90a19bdc.9bb0c","type":"debug","z":"5288cc7c.ab3fc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":450,"y":520,"wires":[]},{"id":"9f1f5524.83b1d8","type":"inject","z":"5288cc7c.ab3fc4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":320,"y":520,"wires":[["45e969a4.d51778"]]},{"id":"51bd98d6.4ff3d","type":"inject","z":"5288cc7c.ab3fc4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":500,"y":1020,"wires":[["e6510cee.e66ed"]]},{"id":"f00b7b5c.e7f2b","type":"debug","z":"5288cc7c.ab3fc4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":630,"y":1020,"wires":[]},{"id":"fc33606a.00a2c","type":"server","z":"","name":"Home Assistant Glenn","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement