PIRs activating Security Lights

This is a working flow of my security light system of:

  • 4 x PIRs, each powering a Sonoff
  • 4 x security lights, each powered by a Sonoff

Why the decoupling and not just get 4 combined PIR/security lights? My use case is that I want to...

  1. position each PIR and each security light in their optimum positions - which is not necessarily in the same location
  2. enable using the PIR as a regular motion detector (will use a flow to do this)
  3. enable each PIR to power on/off more than one security light
  4. for both the PIRs and the lights to be able to independently "talk" MQTT.

The delay is set manually in each node (thanks to @Colin for the Trigger node suggestion - my first attempt had 2 extra nodes per PIR/light ughhh) and I'll try and get them all set from a global variable. The state of each PIR is saved in a per-PIR global variable (as is the light state as well, but that's in a different flow).

[{"id":"96352169.055ab","type":"mqtt out","z":"e12bb044.9f8c","name":"security light east","topic":"cmnd/security/light/east/power","qos":"1","retain":"false","broker":"7b5262ba.b63abc","x":670,"y":260,"wires":[]},{"id":"380ead6d.1846e2","type":"mqtt in","z":"e12bb044.9f8c","name":"","topic":"+/security/pir/east/POWER","qos":"1","datatype":"auto","broker":"7b5262ba.b63abc","x":190,"y":260,"wires":[["53234669.028ea8","d29e75be.e0a818"]]},{"id":"7629b72c.2dfa18","type":"mqtt out","z":"e12bb044.9f8c","name":"security light south","topic":"cmnd/security/light/south/power","qos":"1","retain":"false","broker":"7b5262ba.b63abc","x":670,"y":308,"wires":[]},{"id":"fa1a066c.d11e38","type":"mqtt in","z":"e12bb044.9f8c","name":"","topic":"+/security/pir/south/POWER","qos":"1","datatype":"auto","broker":"7b5262ba.b63abc","x":180,"y":308,"wires":[["a09cc49f.811888","d29e75be.e0a818"]]},{"id":"582bb039.24407","type":"mqtt out","z":"e12bb044.9f8c","name":"security light west","topic":"cmnd/security/light/west/power","qos":"1","retain":"false","broker":"7b5262ba.b63abc","x":670,"y":356,"wires":[]},{"id":"c69ee241.ae675","type":"mqtt in","z":"e12bb044.9f8c","name":"","topic":"+/security/pir/west/POWER","qos":"1","datatype":"auto","broker":"7b5262ba.b63abc","x":190,"y":356,"wires":[["ad5b14a7.bae008","d29e75be.e0a818"]]},{"id":"f38e0989.a37308","type":"mqtt out","z":"e12bb044.9f8c","name":"security light north","topic":"cmnd/security/light/north/power","qos":"1","retain":"false","broker":"7b5262ba.b63abc","x":670,"y":405,"wires":[]},{"id":"3af10472.0e075c","type":"mqtt in","z":"e12bb044.9f8c","name":"","topic":"+/security/pir/north/POWER","qos":"1","datatype":"auto","broker":"7b5262ba.b63abc","x":180,"y":405,"wires":[["42577d40.5b7a04","d29e75be.e0a818"]]},{"id":"61b48a46.c63164","type":"comment","z":"e12bb044.9f8c","name":"Automation Logic","info":"## Automation Logic","x":160,"y":200,"wires":[]},{"id":"53234669.028ea8","type":"trigger","z":"e12bb044.9f8c","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":true,"units":"s","reset":"0","bytopic":"all","name":"on, wait 60s, then off","x":440,"y":260,"wires":[["96352169.055ab"]]},{"id":"42577d40.5b7a04","type":"trigger","z":"e12bb044.9f8c","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":true,"units":"s","reset":"0","bytopic":"all","name":"on, wait 60s, then off","x":440,"y":405,"wires":[["f38e0989.a37308"]]},{"id":"ad5b14a7.bae008","type":"trigger","z":"e12bb044.9f8c","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":true,"units":"s","reset":"0","bytopic":"all","name":"on, wait 60s, then off","x":440,"y":356,"wires":[["582bb039.24407"]]},{"id":"a09cc49f.811888","type":"trigger","z":"e12bb044.9f8c","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"60","extend":true,"units":"s","reset":"0","bytopic":"all","name":"on, wait 60s, then off","x":440,"y":308,"wires":[["7629b72c.2dfa18"]]},{"id":"d29e75be.e0a818","type":"function","z":"e12bb044.9f8c","name":"update PIR states","func":"// this takes an incoming mqtt stat command and \n// and uses the data to write out a global variable\n\n// capatilzation function\nfunction capitalizeFirstLetter(string) {\n    return string.charAt(0).toUpperCase() + string.slice(1);\n}\n\n// regex to get quadrant from msg.topic (mqtt topic)\nvar myRe = /.*pir\\/(\\w+)\\/POWER/g;\n\n// set & get quadrant data\nvar rawquadrant = myRe.exec(msg.topic);\nvar quadrant = capitalizeFirstLetter(rawquadrant[1]);\n\n// set quadrant data\nvar quadrantPirState = [];\nquadrantPirState[0] = \"statePir\".concat(quadrant);\nquadrantPirState[1] = msg.payload;\n\n// set global variables\nglobal.set(quadrantPirState[0],quadrantPirState[1]);\n\nreturn msg;","outputs":1,"noerr":0,"x":430,"y":200,"wires":[[]]},{"id":"7b5262ba.b63abc","type":"mqtt-broker","z":"","name":"phoscon","broker":"192.168.1.8","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]
2 Likes