I'll get back to you shortly.
How's this?
I tested it and it seems to work.
The trap is not to watch too closely the direction
value.
Sorry I couldn't make it say UP
and DOWN
.
But if you watch it, it seems to work.
[{"id":"abff1141.b21bf8","type":"trigger","z":"8bb4de19.f72c88","name":"","op1":"START","op2":"STOP","op1type":"str","op2type":"str","duration":"20","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":3250,"y":2060,"wires":[["97a7ed4c.3efb88","351a954b.03123a"]]},{"id":"97a7ed4c.3efb88","type":"change","z":"8bb4de19.f72c88","name":"Get direction.","rules":[{"t":"set","p":"direction","pt":"msg","to":"DIRECTION","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":3430,"y":2060,"wires":[["18065360.3e56d5"]]},{"id":"cd0f9550.345fa8","type":"inject","z":"8bb4de19.f72c88","name":"Button","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"BUTTON","payload":"PRESSED","payloadType":"str","x":3070,"y":2020,"wires":[["abff1141.b21bf8","f382d08d.cf66f8"]]},{"id":"351a954b.03123a","type":"switch","z":"8bb4de19.f72c88","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"STOP","vt":"str"},{"t":"eq","v":"START","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":3410,"y":2120,"wires":[["92408e16.10e55"],["1d6432c0.1b9ccd"]]},{"id":"da97a79a.044ea","type":"change","z":"8bb4de19.f72c88","name":"Reset","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":3070,"y":2120,"wires":[["abff1141.b21bf8","c9f39f28.7295a8"]]},{"id":"18065360.3e56d5","type":"debug","z":"8bb4de19.f72c88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":3610,"y":2060,"wires":[]},{"id":"c9f39f28.7295a8","type":"change","z":"8bb4de19.f72c88","name":"STOP","rules":[{"t":"set","p":"payload","pt":"msg","to":"STOP","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":3270,"y":2120,"wires":[["97a7ed4c.3efb88","351a954b.03123a"]]},{"id":"f382d08d.cf66f8","type":"switch","z":"8bb4de19.f72c88","name":"Active?","property":"ACTIVE","propertyType":"flow","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":3060,"y":2070,"wires":[["da97a79a.044ea"]]},{"id":"1d6432c0.1b9ccd","type":"change","z":"8bb4de19.f72c88","name":"","rules":[{"t":"set","p":"ACTIVE","pt":"flow","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":3570,"y":2140,"wires":[["50770a55.fd22fc"]]},{"id":"92408e16.10e55","type":"change","z":"8bb4de19.f72c88","name":"","rules":[{"t":"set","p":"ACTIVE","pt":"flow","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":3570,"y":2100,"wires":[[]]},{"id":"50770a55.fd22fc","type":"function","z":"8bb4de19.f72c88","name":"Toggle direction","func":"// `direction` `0` = UP `1` = DOWN.\nvar direction = flow.get(\"DIRECTION\") || 0;\n\n// Button pressed.\ndirection = (direction + 1) % 2;\n\nif (direction == 0)\n{\n flow.set(\"DIRECTION\",direction);\n} else\n{\n flow.set(\"DIRECTION\",direction);\n}\n\nnode.status({text:direction});\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":3770,"y":2140,"wires":[[]]}]
Ok, after thought:
START
needs the direction
part set.
STOP
doesn't care.
So when you see the STOP
message and the direction
has changed, don't worry.
That is used at the next invocation of the message.
So further down the flow (your part) you will have to separate the STOP/GO and direction and handle them individually.