Door opener control

ok feed in the temps to the function , add your api where debug is.
In the service input of your api add {{payload}}

that should make it work.

[{"id":"fef50959.daeb68","type":"inject","z":"bd180d69.a493b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"19.7","payloadType":"num","x":90,"y":400,"wires":[["d234bce1.ec271"]]},{"id":"d234bce1.ec271","type":"function","z":"bd180d69.a493b","name":"","func":"const position = [28,26,24,20,19];\nlet current = flow.get(\"current.position\") || 19;\nfor(var val of position){\n    if(msg.payload>=val) break;\n}\nmsg.delay = Math.abs(position.indexOf(current) - position.indexOf(val)) * 12000\nlet timestamp = new Date().valueOf();\nif(timestamp - flow.get(\"current.time\") < msg.delay+250) return null;\nif(val < current){\n    msg.payload =\"close_cover\";\n}else if(val > current){\n    msg.payload = \"open_cover\";\n}else{\n    return null;\n}\nflow.set(\"current\", {position:val,time:timestamp})\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":330,"y":480,"wires":[["4a8bad3c.433184"]]},{"id":"4a8bad3c.433184","type":"trigger","z":"bd180d69.a493b","name":"","op1":"","op2":"Stop_cover","op1type":"pay","op2type":"str","duration":"250","extend":false,"overrideDelay":true,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":540,"y":400,"wires":[["acffd1fa.c3207"]]},{"id":"ab0b5913.ba2d8","type":"inject","z":"bd180d69.a493b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"20","payloadType":"num","x":96.33332824707031,"y":443,"wires":[["d234bce1.ec271"]]},{"id":"f49802ca.795e4","type":"inject","z":"bd180d69.a493b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"24.2","payloadType":"num","x":100,"y":480,"wires":[["d234bce1.ec271"]]},{"id":"b238b1c3.76073","type":"inject","z":"bd180d69.a493b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"27.5","payloadType":"num","x":100,"y":520,"wires":[["d234bce1.ec271"]]},{"id":"41c8be81.6f73f8","type":"inject","z":"bd180d69.a493b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"28","payloadType":"num","x":107.33332824707031,"y":562,"wires":[["d234bce1.ec271"]]},{"id":"acffd1fa.c3207","type":"debug","z":"bd180d69.a493b","name":"your api goes here","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"delay","statusType":"msg","x":610,"y":480,"wires":[]}]

[edit change first line of function to start from 0 degrees]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.