Skip to content

Instantly share code, notes, and snippets.

@pinguinpfleger
Last active January 19, 2020 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pinguinpfleger/15c17f3445639d90139f4b05113f4a8d to your computer and use it in GitHub Desktop.
Save pinguinpfleger/15c17f3445639d90139f4b05113f4a8d to your computer and use it in GitHub Desktop.
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": [
[],
[]
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment