I'm new to node-red. I'm trying to create a flow where my hue sensor activates a scene, and after x seconds it reverts back to the previous state. But now every message gets through the whole flow. So every time the motion sensor detects motion, it triggers the flow. That's ok, but I want to stop the current message and continue with the new message.
I tried several things with variables, switches etcetera. But I can't get it to work properly.
Can somebody help me out?
[{"id":"b7ac12ab.7e528","type":"tab","label":"Hue keuken","disabled":false,"info":""},{"id":"1524c811.d2fc68","type":"switch","z":"b7ac12ab.7e528","name":"","property":"data.attributes.brightness","propertyType":"msg","rules":[{"t":"lt","v":"254","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1050,"y":140,"wires":[["52a10aa8.2dbd14"]]},{"id":"77eb2e45.90f64","type":"hue-group","z":"b7ac12ab.7e528","name":"KeukenState","bridge":"caaebba0.2dfe58","groupid":"2","colornamer":true,"skipevents":false,"x":1030,"y":260,"wires":[["83152845.b30018"]]},{"id":"52a10aa8.2dbd14","type":"hue-scene","z":"b7ac12ab.7e528","name":"Helder keuken","bridge":"caaebba0.2dfe58","sceneid":"3kY5XJ9gXJ5YN1k","skipevents":false,"x":1240,"y":140,"wires":[["794162e4.a95c1c"]]},{"id":"d8c980b8.1085","type":"function","z":"b7ac12ab.7e528","name":"previous state","func":" var brightness=flow.get('brightness') \n return {\n payload: {\n on: true,\n brightness: brightness\n }\n }\n","outputs":1,"noerr":0,"x":780,"y":260,"wires":[["77eb2e45.90f64"]]},{"id":"f1f134af.a65878","type":"api-current-state","z":"b7ac12ab.7e528","name":"","server":"824131a9.869e6","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.keuken_1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":620,"y":140,"wires":[["e3257eef.cc8f5"]]},{"id":"e3257eef.cc8f5","type":"function","z":"b7ac12ab.7e528","name":"previous state","func":"flow.set('brightness', (msg.data.attributes.brightness/2.54));\n return msg;","outputs":1,"noerr":0,"x":880,"y":140,"wires":[["1524c811.d2fc68"]]},{"id":"d3b645bf.069128","type":"inject","z":"b7ac12ab.7e528","name":"","topic":"","payload":"{\"active\":true,\"motion\":true,\"updated\":\"2020-01-11T01:10:01+00:00\"}","payloadType":"json","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":90,"y":180,"wires":[["fc1775ef.2c6a48"]]},{"id":"3d0bf175.1d620e","type":"delay","z":"b7ac12ab.7e528","name":"Delay","pauseType":"delayv","timeout":"1","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":570,"y":260,"wires":[["d8c980b8.1085"]]},{"id":"794162e4.a95c1c","type":"function","z":"b7ac12ab.7e528","name":"set motion true","func":"flow.set('motion_keuken', true);\nmsg.delay = 5000;\nreturn msg;","outputs":1,"noerr":0,"x":380,"y":260,"wires":[["3d0bf175.1d620e"]]},{"id":"83152845.b30018","type":"function","z":"b7ac12ab.7e528","name":"set motion false","func":"flow.set('motion_keuken', false);\nreturn msg;","outputs":1,"noerr":0,"x":1220,"y":260,"wires":[[]]},{"id":"fc1775ef.2c6a48","type":"switch","z":"b7ac12ab.7e528","name":"Check motion true / false","property":"motion_keuken","propertyType":"flow","rules":[{"t":"false"},{"t":"true"}],"checkall":"true","repair":true,"outputs":2,"x":330,"y":140,"wires":[["f1f134af.a65878"],["794162e4.a95c1c"]]},{"id":"caaebba0.2dfe58","type":"hue-bridge","z":"","name":"Philips hue","bridge":"192.168.0.108","key":"YDSZNb8M1YWitGciLD3c-9LBx869YAhTadN0XfNk","interval":"750","disableupdates":false},{"id":"824131a9.869e6","type":"server","z":"","name":"Home Assistant"}]