Light switch off timer, reset with PIR, on and manually override

So the shed lights are always being left on. You can't just add a timer, sometimes you are not in the shed for more than 5 minutes, the next you want to be there for 7 hours.

Using a Trigger Node you can input your ON button and a PIR. Either an ON or a PIR will reset the trigger (extend the timer if retriggered; output one set to nothing). And the timer will always turn off your lights.

Small side effect is that an off will be sent for any PIR trigger timeout - which doesn't hurt, you might have missed the original ON.

Unfortunately there are times when we want the power on 24/7 - how to enable/disable the PIR. Using a Function we can record context data which keeps an enabled flag. Now we can override the PIR.

In real life the inputs/outputs of this flow are 433Mhz OOK cheap buttons and power points.

[{"id":"e330129e.461ea","type":"trigger","op1":"1","op2":"off","op1type":"nul","op2type":"val","duration":"3","extend":"true","units":"s","name":"Timeout","x":301,"y":149,"z":"cf2602ad.999d08","wires":[["8a14991b.4af7e"]]},{"id":"3fc43a95.1fa08e","type":"inject","name":"ON","topic":"switch","payload":"on","payloadType":"string","repeat":"","crontab":"","once":false,"x":103,"y":101,"z":"cf2602ad.999d08","wires":[["e330129e.461ea","76ef22e7.2ef744"]]},{"id":"f1d629ee.b7a678","type":"inject","name":"","topic":"PIR","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":107,"y":145,"z":"cf2602ad.999d08","wires":[["e330129e.461ea"]]},{"id":"76ef22e7.2ef744","type":"debug","name":"Light","active":true,"console":"false","complete":"payload","x":567,"y":79,"z":"cf2602ad.999d08","wires":[]},{"id":"6999cbe6.a9e84c","type":"inject","name":"OFF","topic":"switch","payload":"off","payloadType":"string","repeat":"","crontab":"","once":false,"x":102,"y":57,"z":"cf2602ad.999d08","wires":[["76ef22e7.2ef744"]]},{"id":"8a14991b.4af7e","type":"function","name":"Enabled","func":"\nif (msg.topic == \"state\") {\n\tcontext.state = msg.payload;\n\treturn null;\n}\nif (context.state == 1)\n  return msg;\nelse\n  return null;\n ","outputs":1,"x":436,"y":180,"z":"cf2602ad.999d08","wires":[["76ef22e7.2ef744"]]},{"id":"2a7f2e88.cf234a","type":"inject","name":"Disable Timer","topic":"state","payload":"0","payloadType":"string","repeat":"","crontab":"","once":false,"x":135,"y":187,"z":"cf2602ad.999d08","wires":[["8a14991b.4af7e"]]},{"id":"d8156886.93a63","type":"inject","name":"Enable Timer","topic":"state","payload":"1","payloadType":"string","repeat":"","crontab":"","once":false,"x":133,"y":227,"z":"cf2602ad.999d08","wires":[["8a14991b.4af7e"]]}]

Flow Info

Created 10 years ago
Updated 9 years, 4 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • debug (x1)
  • function (x1)
  • inject (x5)
  • trigger (x1)

Tags

  • timer
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option