Hi - I'm realatively new to Node Red but i have a PLC based automation background. I neededed to write a flow to control the opening and closing of my garage doors via a raspberry pi. The doors use two simple linear actuator that takes about 10 second to fully open. The main aim of the project was to prevent the actuators from being energised past the point that the doors are fully open or closed to prevent damage to the motors. This meant coming up with a means of tracking how far open or closed the doors currently are.
I'm really happy with the timer/integrator i came up with, I feel that its simple and easy to follow and easy to adapt of configure for other applications. In my research I came a cross a number of requests for something like this and I didn't see many user friendly solutions. As a side effect i can open or close to any position I want.
I know that using limit switches etc would be beneficial and relying on running a motor for a set period to achieve a position without feedback isn't the prefered way to do things but I'm just happy to have the basics up and running
Looking forward to comments and feedback.
[{"id":"2226cb6.f9ad9b4","type":"delay","z":"a9f3d7b2.b4a7","name":"","pauseType":"delay","timeout":"0.1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":430,"y":520,"wires":[["5a57e016.aa322"]]},{"id":"7738d502.10b7e4","type":"switch","z":"a9f3d7b2.b4a7","name":"stop check","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"stop","vt":"str"},{"t":"nnull"}],"checkall":"false","repair":false,"outputs":2,"x":630,"y":440,"wires":[[],["2226cb6.f9ad9b4"]]},{"id":"614dff1.a978b","type":"ui_slider","z":"a9f3d7b2.b4a7","name":"Door A","label":"Door A","tooltip":"","group":"14f07d2d.ac771b","order":6,"width":0,"height":0,"passthru":true,"outs":"end","topic":"desired","min":"0","max":"100","step":"5","x":460,"y":320,"wires":[["c9d34317.7aa22"]]},{"id":"22159203.8ec4f6","type":"rpi-gpio out","z":"a9f3d7b2.b4a7","name":"Aclose","pin":"31","set":true,"level":"0","freq":"","out":"out","x":1090,"y":520,"wires":[]},{"id":"f5007e2.e76a6","type":"ui_text","z":"a9f3d7b2.b4a7","group":"14f07d2d.ac771b","order":2,"width":"3","height":"1","name":"Status A","label":"","format":"{{msg.payload}}","layout":"row-spread","x":1100,"y":600,"wires":[]},{"id":"288ae475.dff184","type":"ui_template","z":"a9f3d7b2.b4a7","group":"af6587ae.e4be48","name":"Inch A CL","order":1,"width":"3","height":"2","format":"<md-button\n ng-mousedown=\"send({payload: true})\"\n ng-mouseup=\"send({payload: false})\"\n > \n A close\n </md-button>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":980,"y":480,"wires":[["22159203.8ec4f6"]]},{"id":"407c432e.0f2fe4","type":"ui_switch","z":"a9f3d7b2.b4a7","name":"Door A","label":"Door A","tooltip":"","group":"14f07d2d.ac771b","order":1,"width":"3","height":"1","passthru":true,"decouple":"false","topic":"","style":"","onvalue":"Open","onvalueType":"str","onicon":"","oncolor":"","offvalue":"Close","offvalueType":"str","officon":"","offcolor":"","x":140,"y":320,"wires":[["9823d3d1.c57ea"]]},{"id":"9823d3d1.c57ea","type":"change","z":"a9f3d7b2.b4a7","name":"percent set","rules":[{"t":"change","p":"payload","pt":"msg","from":"Open","fromt":"str","to":"100","tot":"num"},{"t":"change","p":"payload","pt":"msg","from":"Close","fromt":"str","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":290,"y":320,"wires":[["614dff1.a978b"]]},{"id":"ee734c74.91d888","type":"rpi-gpio out","z":"a9f3d7b2.b4a7","name":"Aopen","pin":"37","set":true,"level":"0","freq":"","out":"out","x":1110,"y":400,"wires":[]},{"id":"5172e4e5.b73334","type":"change","z":"a9f3d7b2.b4a7","name":"OTest","rules":[{"t":"change","p":"payload","pt":"msg","from":"increment","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"decrement","fromt":"str","to":"false","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"stop","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":990,"y":420,"wires":[["ee734c74.91d888"]]},{"id":"a5da0f67.696ae8","type":"ui_template","z":"a9f3d7b2.b4a7","group":"af6587ae.e4be48","name":"Inch A OP","order":1,"width":"3","height":"2","format":"<md-button\n ng-mousedown=\"send({payload: true})\"\n ng-mouseup=\"send({payload: false})\"\n > \n A open\n </md-button>","storeOutMessages":false,"fwdInMessages":false,"templateScope":"local","x":980,"y":360,"wires":[["ee734c74.91d888"]]},{"id":"164f9a68.32e7e6","type":"change","z":"a9f3d7b2.b4a7","name":"set topic","rules":[{"t":"change","p":"payload","pt":"msg","from":"payload","fromt":"msg","to":"topic","tot":"msg"},{"t":"change","p":"payload","pt":"msg","from":"","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":820,"y":440,"wires":[["5172e4e5.b73334","f00d202.d16f86","247fa381.55ab44"]]},{"id":"f00d202.d16f86","type":"change","z":"a9f3d7b2.b4a7","name":"CTest","rules":[{"t":"change","p":"payload","pt":"msg","from":"increment","fromt":"str","to":"false","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"decrement","fromt":"str","to":"true","tot":"bool"},{"t":"change","p":"payload","pt":"msg","from":"stop","fromt":"str","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":970,"y":520,"wires":[["22159203.8ec4f6"]]},{"id":"247fa381.55ab44","type":"change","z":"a9f3d7b2.b4a7","name":"Display","rules":[{"t":"change","p":"payload","pt":"msg","from":"increment","fromt":"str","to":"Opening","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"decrement","fromt":"str","to":"Closing","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"stop","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":960,"y":600,"wires":[["f5007e2.e76a6"]]},{"id":"6d3b1e6a.7921a","type":"ui_gauge","z":"a9f3d7b2.b4a7","name":"Gauge A","group":"14f07d2d.ac771b","order":9,"width":"3","height":"3","gtype":"compass","title":"","label":"units","format":"{{value}}","min":"100","max":"-300","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":820,"y":400,"wires":[]},{"id":"9bbd020d.993c6","type":"inject","z":"a9f3d7b2.b4a7","name":"","topic":"","payload":"20","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":240,"wires":[["614dff1.a978b"]]},{"id":"71fd9f0f.742be","type":"inject","z":"a9f3d7b2.b4a7","name":"","topic":"","payload":"0","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":200,"wires":[["614dff1.a978b"]]},{"id":"dfcd2948.119a","type":"inject","z":"a9f3d7b2.b4a7","name":"","topic":"","payload":"40","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":290,"y":280,"wires":[["614dff1.a978b"]]},{"id":"c9d34317.7aa22","type":"function","z":"a9f3d7b2.b4a7","name":"Set Target","func":"flow.set(\"abstarget\", msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":320,"wires":[["5a57e016.aa322"]]},{"id":"5a57e016.aa322","type":"function","z":"a9f3d7b2.b4a7","name":"Set direction","func":"var current = flow.get(\"current\")||0;\nvar abstarget = flow.get(\"abstarget\")||0;\nvar dif = abstarget - current\nflow.set(\"dif\",dif);\nif (dif > 0){msg.topic=\"increment\";}\nelse if (dif < 0){msg.topic=\"decrement\";}\nelse if (dif === 0){msg.topic=\"stop\";}\nreturn msg;","outputs":1,"noerr":0,"x":630,"y":360,"wires":[["9b17aa66.07ff68"]]},{"id":"3e2cdc96.8cd124","type":"function","z":"a9f3d7b2.b4a7","name":"Reset","func":"var current = msg.payload\nflow.set(\"current\",current);\nflow.set (\"dif\",0)\nreturn msg;","outputs":1,"noerr":0,"x":450,"y":360,"wires":[["5a57e016.aa322"]]},{"id":"9b17aa66.07ff68","type":"function","z":"a9f3d7b2.b4a7","name":"counter","func":"var current = flow.get(\"current\")||0;\nvar abstarget = flow.get(\"abstarget\")||0;\nvar dif = flow.get(\"dif\")||0;\nif (dif > 0){current++} \nelse if (dif < 0){current--}\nflow.set(\"current\", current);\nmsg.payload = current\nreturn msg;","outputs":1,"noerr":0,"x":620,"y":400,"wires":[["7738d502.10b7e4","164f9a68.32e7e6","6d3b1e6a.7921a"]]},{"id":"14f07d2d.ac771b","type":"ui_group","z":"","name":"Default","tab":"73820455.509a74","disp":false,"width":"6","collapse":false},{"id":"af6587ae.e4be48","type":"ui_group","z":"","name":"Testing","tab":"9d50d0d1.78f058","disp":true,"width":"6","collapse":true},{"id":"73820455.509a74","type":"ui_tab","z":"","name":"Home","icon":"dashboard","disabled":false,"hidden":false},{"id":"9d50d0d1.78f058","type":"ui_tab","z":"","name":"Testing","icon":"dashboard","disabled":false,"hidden":false}]