I'm trying to create something, but I'm stuck
I use MQTT as input, where I get ON/OFF msgs. What I want to do is:
- When ON received - Start looping max 10 times with delay of 1.5ms (user msg.delay so that first msg will go trough instantly)
- When counter gets to 10 - Stop looping
- When OFF received during counter - stop looping
The latest I got now attached below. When I inject OFF I got stuck because it has different _msg.id therefore looping from the beginning. Tried moving the counter to flow level but its not looping for me for some reason.
Please advice.
[{"id":"62fcd628.1262d8","type":"comment","z":"9bdbbdcf.846e7","name":"Camera Notify Back Camera","info":"","x":160,"y":600,"wires":[]},{"id":"a453c3bc.a5059","type":"mqtt in","z":"9bdbbdcf.846e7","name":"MQTT BackCam","topic":"Blueiris/backcam/state","qos":"2","datatype":"auto","broker":"25efe206.cae69e","x":100,"y":660,"wires":[["413c2242.e7888c","4990a5f.c766a5c"]]},{"id":"413c2242.e7888c","type":"debug","z":"9bdbbdcf.846e7","name":"MQTT In","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":420,"y":580,"wires":[]},{"id":"98251528.73f168","type":"debug","z":"9bdbbdcf.846e7","name":"Validity Out - And will be used for HTTP API","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":890,"y":800,"wires":[]},{"id":"4990a5f.c766a5c","type":"counter-loop","z":"9bdbbdcf.846e7","name":"Counter 20","counter":"il4990a5fc766a5c","counterType":"msg","reset":false,"resetValue":"value-null","initial":0,"initialType":"num","operator":"lt","termination":"10","terminationType":"num","increment":1,"incrementType":"num","x":390,"y":680,"wires":[["a77f426.c351cc"],["b246c24d.f5139","416f23.c06740dc"]]},{"id":"e9fc2e60.735f4","type":"function","z":"9bdbbdcf.846e7","name":"Check Validity","func":"if(msg.payload === \"ON\" ){\n msg.delay = 1500\n return msg;\n}\nif(msg.payload === \"OFF\" ){\n msg.il4990a5fc766a5c = 100\n return msg;\n} else {\n return null;\n}","outputs":1,"noerr":0,"initialize":"","finalize":"","x":480,"y":760,"wires":[["98251528.73f168","4990a5f.c766a5c"]]},{"id":"b246c24d.f5139","type":"delay","z":"9bdbbdcf.846e7","name":"Delay 1.5s","pauseType":"delayv","timeout":"0","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":590,"y":680,"wires":[["e9fc2e60.735f4","e0efdb74.c2aa78"]]},{"id":"e0efdb74.c2aa78","type":"debug","z":"9bdbbdcf.846e7","name":"Timer Out","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":880,"wires":[]},{"id":"a77f426.c351cc","type":"debug","z":"9bdbbdcf.846e7","name":"Counter Out Up","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":540,"wires":[]},{"id":"416f23.c06740dc","type":"debug","z":"9bdbbdcf.846e7","name":"Counter Out Down","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":580,"wires":[]},{"id":"63abf8c9.cd5a58","type":"inject","z":"9bdbbdcf.846e7","name":"ON","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"ON","payloadType":"str","x":180,"y":500,"wires":[["413c2242.e7888c","e9fc2e60.735f4"]]},{"id":"71ee1f1e.5a666","type":"inject","z":"9bdbbdcf.846e7","name":"OFF","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"OFF","payloadType":"str","x":170,"y":540,"wires":[["413c2242.e7888c","e9fc2e60.735f4"]]},{"id":"25efe206.cae69e","type":"mqtt-broker","name":"Local","broker":"172.17.0.1","port":"1883","clientid":"NodeRed","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]