Change DMX dimmer output by a pushbutton

Hi There, I'm trying to create a dimmer value into a JSON line. This dimmer value needs to be controlled by a pushbutton. When you press once, the light goes on. When you keep the button pressed, the dimmer value goes down , and when it's zero it goes up until you release the button. This is what I got at the moment, but that's without that variable value.

[{"id":"06afa4f2be886b2e","type":"tab","label":"Flow 7","disabled":false,"info":"","env":},{"id":"c220c40b2dc0a40b","type":"group","z":"06afa4f2be886b2e","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["28fd8aaed4e403c8","c5304477870a5d1c","70afc3b684eac84e","1c60f127b5c56e99","110f56d66c768df9"],"x":134,"y":219,"w":772,"h":142},{"id":"c5304477870a5d1c","type":"inject","z":"06afa4f2be886b2e","g":"c220c40b2dc0a40b","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":230,"y":260,"wires":[["70afc3b684eac84e"]]},{"id":"70afc3b684eac84e","type":"change","z":"06afa4f2be886b2e","g":"c220c40b2dc0a40b","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"switch_toggle","tot":"flow"},{"t":"set","p":"payload","pt":"msg","to":"$$.payload = 1 ? 0 : 1","tot":"jsonata"},{"t":"set","p":"switch_toggle","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":260,"wires":[["1c60f127b5c56e99"]]},{"id":"1c60f127b5c56e99","type":"function","z":"06afa4f2be886b2e","g":"c220c40b2dc0a40b","name":"","func":"var x = context.get("counter") || 0;\nif (msg.payload == 0)\n{\n context.set("counter",0);\n msg.payload = {"channel":5, "value":0};\n return msg;\n}\nif (msg.payload == 1)\n{\n context.set("counter",1);\n msg.payload = {"channel":5, "value":100};\n return msg;\n}\n\nif (x === 0)\n{\n msg.payload = {"channel":5, "value":100};\n} else\nif (x === 1)\n{\n msg.payload = {"channel":5, "value":0};\n}\n\nx = (x + 1) % 2;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":,"x":600,"y":260,"wires":[["110f56d66c768df9","28fd8aaed4e403c8"]]},{"id":"110f56d66c768df9","type":"debug","z":"06afa4f2be886b2e","g":"c220c40b2dc0a40b","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":260,"wires":},{"id":"28fd8aaed4e403c8","type":"artnet-command","z":"06afa4f2be886b2e","g":"c220c40b2dc0a40b","name":"DMX Controller","artnetnode":"d4e9c1034ff581f7","x":800,"y":320,"wires":,"inputLabels":["switch"]},{"id":"d4e9c1034ff581f7","type":"artnet-node","host":"192.168.2.37","port":"6454","universe":"0"}]

Your flow is corrupt due to not following posting guidelines

All code needs to be posted between tripple backticks on newlines e.g.
```
code
```

Any way here is an example the flow is set to send the payload every second, the value increments by 1 and when it hits 10 it reduces by 1 till it hit 0, and then increments again.
The routine starts when it receives 1 and stops when it receives 0.

[{"id":"c5304477870a5d1c","type":"inject","z":"06afa4f2be886b2e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":230,"y":180,"wires":[["b5f5886ea2f2d6fc"]]},{"id":"b5f5886ea2f2d6fc","type":"trigger","z":"06afa4f2be886b2e","name":"","op1":"1","op2":"0","op1type":"str","op2type":"str","duration":"-1","extend":false,"overrideDelay":false,"units":"s","reset":"0","bytopic":"all","topic":"topic","outputs":1,"x":420,"y":180,"wires":[["70afc3b684eac84e"]]},{"id":"2e4e413c3d3dbcca","type":"inject","z":"06afa4f2be886b2e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":230,"y":220,"wires":[["b5f5886ea2f2d6fc"]]},{"id":"70afc3b684eac84e","type":"change","z":"06afa4f2be886b2e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$sum([$flowContext(\"dimmer_level\")])","tot":"jsonata"},{"t":"set","p":"plus","pt":"flow","to":"$$.payload >= 10 ? -1 : ($$.payload <= 0 ? 1 : $flowContext(\"plus\"))","tot":"jsonata"},{"t":"set","p":"payload","pt":"msg","to":"$$.payload+$flowContext(\"plus\")","tot":"jsonata"},{"t":"set","p":"dimmer_level","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":180,"wires":[["110f56d66c768df9"]]},{"id":"110f56d66c768df9","type":"debug","z":"06afa4f2be886b2e","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":790,"y":240,"wires":[]}]

Edit trigger to change timing and change not to set to levels and increments you require.

Great super, that works.
Thanks :slight_smile:

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