So I almost have this completed but have two bugs I need to work through. The setup is a light which is controlled automatically with a motion sensor but if anyone uses the light switch then it ignores the motion sensor for 1 hour. This happens but has 2 issues.
- The logic to determine when a user presses the physical light switch takes 2 - 3 seconds to run and within this time the motion sensor is wildly switching the light fighting the user.
- On startup the motion sensor is disabled for the first hour as it needs some kind of logic to fix this issue.
Thoughts?
[{"id":"ac1eb4010d4cc237","type":"comment","z":"8969d5b7eebadbd4","name":"Laundry Room","info":"","x":120,"y":160,"wires":[]},{"id":"3fe68e9aaaf65181","type":"server-state-changed","z":"8969d5b7eebadbd4","name":"Laundry Room Motion Sensor","server":"ad6038b2.acf9a8","version":6,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["binary_sensor.linknlink_e04b4100811d0000000000007bac0000_m"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"0","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":200,"wires":[["f3ca2225c9975dee"],[]]},{"id":"8b98be0f64526a27","type":"api-call-service","z":"8969d5b7eebadbd4","name":"","server":"ad6038b2.acf9a8","version":7,"debugenabled":false,"action":"switch.turn_on","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.laundry_room_light"],"labelId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"switch","service":"turn_on","x":780,"y":200,"wires":[[]]},{"id":"65c48213fccc69eb","type":"api-call-service","z":"8969d5b7eebadbd4","name":"","server":"ad6038b2.acf9a8","version":7,"debugenabled":false,"action":"switch.turn_off","floorId":[],"areaId":[],"deviceId":[],"entityId":["switch.laundry_room_light"],"labelId":[],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","blockInputOverrides":true,"domain":"switch","service":"turn_off","x":780,"y":280,"wires":[[]]},{"id":"b9542a1d.b26468","type":"comment","z":"8969d5b7eebadbd4","name":"Manually Control or Automatic Control","info":"","x":190,"y":340,"wires":[]},{"id":"27d9c640.ae21fa","type":"switch","z":"8969d5b7eebadbd4","name":"Manual press?","property":"data.new_state.context.user_id","propertyType":"msg","rules":[{"t":"null"},{"t":"nnull"}],"checkall":"true","repair":false,"outputs":2,"x":140,"y":480,"wires":[["cfeca38.8b8296"],["cf796b57.9e3938"]]},{"id":"cfeca38.8b8296","type":"change","z":"8969d5b7eebadbd4","name":"Set \"LaundryRoomManualControl\" to time","rules":[{"t":"set","p":"LaundryRoomManualControl","pt":"flow","to":"","tot":"date"}],"action":"","property":"","from":"","to":"","reg":false,"x":460,"y":460,"wires":[["db6ea4bae1137394"]]},{"id":"cf796b57.9e3938","type":"change","z":"8969d5b7eebadbd4","name":"Set \"Automated\" to Automated","rules":[{"t":"set","p":"Automated","pt":"flow","to":"Automated","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":430,"y":500,"wires":[["f62aca7d69778090"]]},{"id":"9d428e35300ce818","type":"server-state-changed","z":"8969d5b7eebadbd4","name":"Laundry Room Motion Sensor","server":"ad6038b2.acf9a8","version":6,"outputs":2,"exposeAsEntityConfig":"","entities":{"entity":["binary_sensor.linknlink_e04b4100811d0000000000007bac0000_m"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"off","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"10","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":160,"y":260,"wires":[["d88e8e0d784640a9"],[]]},{"id":"3f3da6a8e0fdc035","type":"server-state-changed","z":"8969d5b7eebadbd4","name":"Laundry Room Light turns on/off?","server":"ad6038b2.acf9a8","version":6,"outputs":1,"exposeAsEntityConfig":"","entities":{"entity":["switch.laundry_room_light"],"substring":[],"regex":[]},"outputInitially":false,"stateType":"str","ifState":"","ifStateType":"str","ifStateOperator":"is_not","outputOnlyOnStateChange":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":190,"y":400,"wires":[["27d9c640.ae21fa"]]},{"id":"f3ca2225c9975dee","type":"function","z":"8969d5b7eebadbd4","name":"Set \"currentTime\"","func":"var d = new Date();\n msg.currentTime = d.getTime() - global.get(\"MotionSensorDelay\");\n //msg.oldtime = flow.manualcontrol;\n//return msg;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":160,"wires":[["4c3f0bbd12e0f2bc"]]},{"id":"4c3f0bbd12e0f2bc","type":"switch","z":"8969d5b7eebadbd4","name":"Is Light Manually Controled?","property":"currentTime","propertyType":"msg","rules":[{"t":"lt","v":"LaundryRoomManualControl","vt":"flow"},{"t":"gte","v":"LaundryRoomManualControl","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":200,"wires":[[],["8b98be0f64526a27"]]},{"id":"d88e8e0d784640a9","type":"function","z":"8969d5b7eebadbd4","name":"Set \"currentTime\"","func":"var d = new Date();\n msg.currentTime = d.getTime() - global.get(\"MotionSensorDelay\");\n //msg.oldtime = flow.manualcontrol;\n//return msg;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":240,"wires":[["d7df2ca055899242"]]},{"id":"d7df2ca055899242","type":"switch","z":"8969d5b7eebadbd4","name":"Is Light Manually Controled?","property":"currentTime","propertyType":"msg","rules":[{"t":"lt","v":"LaundryRoomManualControl","vt":"flow"},{"t":"gte","v":"LaundryRoomManualControl","vt":"flow"}],"checkall":"true","repair":false,"outputs":2,"x":540,"y":280,"wires":[[],["65c48213fccc69eb"]]},{"id":"db6ea4bae1137394","type":"debug","z":"8969d5b7eebadbd4","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Manual Control\"","targetType":"jsonata","statusVal":"","statusType":"auto","x":700,"y":460,"wires":[]},{"id":"f62aca7d69778090","type":"debug","z":"8969d5b7eebadbd4","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"Automatic Control\"","targetType":"jsonata","statusVal":"","statusType":"auto","x":700,"y":500,"wires":[]},{"id":"ad6038b2.acf9a8","type":"server","name":"Home Assistant","addon":true}]```