Basic Timer / Intergrator for Doors Shutters or Drapes

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}]
1 Like

If running the motor against the end stop is liable to damage the motor then you really should have limit switches directly wired into the motor circuit. Otherwise at some time your Pi (or whatever the processor is) will at some point crash or fail in some way that will leave your motor powered up. Even more important if the motor or wiring could overheat and possibly cause a fire.

I'm using cheap 12V actuators from Ebay - I suspect they have integrated limit switches but theres no documentation, so I need to run them to find out. The power supply is rated well below the current capacity of the cabling so I don't have any fire concerns. I do recommend limit switches but I don't think they're an absolute requirement in every application.

No, in this case - where you operate garage doors or any heavy object - this is completely wrong and dangerous!

People died cause of malfunctioning / non existing limit switches - there is even a video from a chinese women who died by a fence door...

For all heavier equipment you must have a hardware component which prevents harm!

The time someone gets trapped by your door or your power supply catches fire, and so on - you will regret it!

1 Like

You rightly point out an issue which is not quite the same as preventing harm to the motor. I agree that it is vital that if the drive is powerful enough to harm someone (a toddler for example) that gets trapped by it then it also needs load detection hardware that stops it if something gets in the way.

1 Like

OK - lets just pretend its for blinds or drapes, because I'm here to chat about the merits of the software I've written. I encourage everyone to be safe and responsible with their hardware but this isn't really why I came here.

Even blinds and drapes should fail safely…

Another tipp:
Use a shelly 2.5 in shutter mode. Take a look at all the features (position calibration ,obstacle detection and max power protection). There is all in it :wink:
And it would even work if your raspi is not working or crashing at that moment etc...

Then you should not give advice like "limit switches aren't needed" or use a software only process when you talk about garage doors - why not even use it for elevators?

Your flow only works in the few cases where the required force to open and close something is always the same...usually one needs a compensation factor to adjust the time for the open or close process.

eg vertical chicken door - it takes longer to open the door (against gravity) than to close it.

Also, without any feedback, recalibration or zero point, all devices will drift over time.

1 Like

Sorry, but I too have to say, although part of that is correct, you are forgetting that the supply could overheat and catch fire.

I get that you don't want people repeating things which aren't (at this point) of interest to you.
I do - get it.

But seriously, don't underestimate how quickly things can go pear shaped and things get nasty very quickly.

@superwinni2
I have a few tasks like opening/closing blinds on the go.
What is shelly 2.5?

Shelly 2.5

I never said that. I said they're advised but I'm currently not using them in my application.

I'm using a nice professional power supply with a continous rating about 2x my peak requirement. I've fused the individual actuator supplies down to just greater than their required current. My main risk is stripping a cog not some kind of massive conflagration.

OK - when i eventually found the Shelly I'd have to admit it's probably a good off the shelf solution.

I have two side opening / bifolding doors that need to be synchonised to avoid collisions (flow was to big to post in its entirity) so I had to come up with a custom solution anyway and it's been a good learning exercise