Toggle Switch Subflow
Toggle Switch Subflow
Any input trigger the output which alternates between true and false. The current status is displayed with on / off
[{"id":"e070e01b.5d6ff","type":"subflow","name":"toggle","info":"","category":"","in":[{"x":80,"y":80,"wires":[{"id":"ddaa4d32.8a0658"}]}],"out":[{"x":340,"y":40,"wires":[{"id":"ddaa4d32.8a0658","port":0}]}],"env":[],"color":"#DDAA99","icon":"font-awesome/fa-toggle-on","status":{"x":340,"y":120,"wires":[{"id":"ddaa4d32.8a0658","port":1}]}},{"id":"ddaa4d32.8a0658","type":"function","z":"e070e01b.5d6ff","name":"toggle script","func":"var toggle = flow.get(\"toggle\") || false;\nvar status = {};\n\nif (toggle === true) {\n msg.payload = false;\n flow.set(\"toggle\", false);\n status.payload = {fill:\"red\",shape:\"dot\",text:\"off\"};\n} else {\n msg.payload = true;\n flow.set(\"toggle\", true);\n status.payload = {fill:\"green\",shape:\"dot\",text:\"on\"};\n}\n\nreturn [msg,status];","outputs":2,"noerr":0,"x":210,"y":80,"wires":[[],[]]}]