Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [{"id":"cb5e3d06.d585c","type":"inject","z":"5bab023.8e83afc","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":120,"wires":[["e0dc28ff.643d98"]]},{"id":"f21ef7a8.cdff38","type":"inject","z":"5bab023.8e83afc","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":160,"wires":[["e0dc28ff.643d98"]]},{"id":"a94f473b.84d898","type":"inject","z":"5bab023.8e83afc","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":220,"wires":[["a2f733e3.87412"]]},{"id":"fd9939c6.fb1bd8","type":"inject","z":"5bab023.8e83afc","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":260,"wires":[["a2f733e3.87412"]]},{"id":"5a480aa9.a17284","type":"function","z":"5bab023.8e83afc","name":"lux && pir","func":"let newMsg = {};\n\n//Using functionnodes internal context memory to store data\n//If context variable doesnt exist is created with de ddefault value off\nif (!context.lux_state){context.lux_state = \"off\";}\nif (!context.pir_state){context.pir_state = \"off\";} \n\nswitch (msg.topic){\n case \"lux\":\n context.lux_state = msg.payload;\n break;\n \n case \"pir\":\n context.pir_state = msg.payload;\n break;\n}\n//Wrote Node status\nnode.status({text: \"LUX = \" + context.lux_state + \", PIR = \" + context.pir_state})\n\n//Evaluate condition\nif ((context.lux_state === \"on\") & (context.pir_state === \"on\"))\n newMsg.payload = \"on\";\nelse\n newMsg.payload = \"off\";\n \nreturn newMsg;","outputs":1,"noerr":0,"x":520,"y":180,"wires":[["d899ec0e.091d"]]},{"id":"d899ec0e.091d","type":"debug","z":"5bab023.8e83afc","name":"dbg Result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":710,"y":180,"wires":[]},{"id":"ad3b3984.96dd48","type":"comment","z":"5bab023.8e83afc","name":"Sensor simulation","info":"","x":210,"y":80,"wires":[]},{"id":"f6f8c303.cc518","type":"debug","z":"5bab023.8e83afc","name":"dbg Sensor info","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":540,"y":240,"wires":[]},{"id":"e0dc28ff.643d98","type":"function","z":"5bab023.8e83afc","name":"LUX 'sensor'","func":"const TOPIC = \"lux\";\n\nlet newMsg = {};\n\nnewMsg.payload = msg.payload;\nnewMsg.topic = TOPIC;\n\nnode.status({text: \"LUX = \" + msg.payload});\n\nreturn newMsg;","outputs":1,"noerr":0,"x":290,"y":140,"wires":[["f6f8c303.cc518","5a480aa9.a17284"]]},{"id":"a2f733e3.87412","type":"function","z":"5bab023.8e83afc","name":"PIR 'sensor'","func":"const TOPIC = \"pir\";\n\nlet newMsg = {};\n\nnewMsg.payload = msg.payload;\nnewMsg.topic = TOPIC;\n\nnode.status({text: \"PIR = \" + msg.payload});\nreturn newMsg;","outputs":1,"noerr":0,"x":290,"y":240,"wires":[["5a480aa9.a17284","f6f8c303.cc518"]]}]
Advertisement
Add Comment
Please, Sign In to add comment