Muse Automator Toggle Example
Question:
How can I create a toggle in Muse Automator?
Answer:
Import the code snippet below into Muse Automator to see 2 examples of toggle flows.
The first group in the example toggles relay 1 on a Muse controller between on and off and shows the change in debug.
The second group in the example toggles the object flow.mute between TRUE and FALSE and shows the change in debug.
[
{
"id": "1439a15d8cb392ab",
"type": "tab",
"label": "Toggle Example",
"disabled": false,
"info": "",
"env": []
},
{
"id": "406e7ef770706f7c",
"type": "group",
"z": "1439a15d8cb392ab",
"name": "Check State of Variable flow.mute and Toggle State",
"style": {
"label": true
},
"nodes": [
"bd324b6874bb9a24",
"59f67a7b8e124af2",
"e5c5b2a88ada3379",
"23905b44c7d55824",
"b5e8a1e33c414684",
"6a5e2d335fe2e4bb",
"ec9e386f9e6dc9c9",
"681cd57cbd6b9342",
"d12665575f7b0579"
],
"x": 28,
"y": 299,
"w": 1058,
"h": 348
},
{
"id": "590d989c208859bd",
"type": "group",
"z": "1439a15d8cb392ab",
"name": "Check State of iDevice Relay 1 and Toggle State",
"style": {
"label": true
},
"nodes": [
"e3ca9a10111b97f8",
"f1d9723c9d47f2e5",
"5c444e29686dbdf6",
"6df40d236c040862",
"2a6bf1f87286ec80",
"0e01aad07d0dfbe6",
"714be65b64ba0b52"
],
"x": 34,
"y": 59,
"w": 1072,
"h": 122
},
{
"id": "d12665575f7b0579",
"type": "group",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "Initializing flow.mute object",
"style": {
"label": true
},
"nodes": [
"f14c1421833d7554",
"6283f088b6ab6713"
],
"x": 54,
"y": 539,
"w": 432,
"h": 82
},
{
"id": "bd324b6874bb9a24",
"type": "inject",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "Inject",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 420,
"wires": [
[
"e5c5b2a88ada3379"
]
]
},
{
"id": "f14c1421833d7554",
"type": "inject",
"z": "1439a15d8cb392ab",
"g": "d12665575f7b0579",
"name": "Initialize flow.mute",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 190,
"y": 580,
"wires": [
[
"6283f088b6ab6713"
]
]
},
{
"id": "6283f088b6ab6713",
"type": "change",
"z": "1439a15d8cb392ab",
"g": "d12665575f7b0579",
"name": "",
"rules": [
{
"t": "set",
"p": "mute",
"pt": "flow",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 390,
"y": 580,
"wires": [
[]
]
},
{
"id": "59f67a7b8e124af2",
"type": "debug",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "debug 32",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 980,
"y": 400,
"wires": []
},
{
"id": "e5c5b2a88ada3379",
"type": "switch",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "Switch on flow.mute value",
"property": "mute",
"propertyType": "flow",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 390,
"y": 420,
"wires": [
[
"6a5e2d335fe2e4bb"
],
[
"ec9e386f9e6dc9c9"
]
]
},
{
"id": "23905b44c7d55824",
"type": "change",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "set flow.mute = true",
"rules": [
{
"t": "set",
"p": "mute",
"pt": "flow",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 890,
"y": 500,
"wires": [
[]
]
},
{
"id": "b5e8a1e33c414684",
"type": "change",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "set flow.mute = false",
"rules": [
{
"t": "set",
"p": "mute",
"pt": "flow",
"to": "false",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 890,
"y": 340,
"wires": [
[]
]
},
{
"id": "6a5e2d335fe2e4bb",
"type": "template",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "flow.mute now equals: {{flow.mute}}",
"output": "str",
"x": 660,
"y": 400,
"wires": [
[
"59f67a7b8e124af2",
"b5e8a1e33c414684"
]
]
},
{
"id": "ec9e386f9e6dc9c9",
"type": "template",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "flow.mute now equals: {{flow.mute}}",
"output": "str",
"x": 660,
"y": 440,
"wires": [
[
"23905b44c7d55824",
"681cd57cbd6b9342"
]
]
},
{
"id": "681cd57cbd6b9342",
"type": "debug",
"z": "1439a15d8cb392ab",
"g": "406e7ef770706f7c",
"name": "debug 33",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 980,
"y": 440,
"wires": []
},
{
"id": "e3ca9a10111b97f8",
"type": "Status",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "Rel1 State",
"mojo": {
"device": "idevice",
"parameter": "//relay/1/state",
"onebased": false
},
"x": 300,
"y": 120,
"wires": [
[
"6df40d236c040862"
]
]
},
{
"id": "f1d9723c9d47f2e5",
"type": "inject",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "Inject",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 130,
"y": 120,
"wires": [
[
"e3ca9a10111b97f8"
]
]
},
{
"id": "5c444e29686dbdf6",
"type": "debug",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "debug 34",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1000,
"y": 100,
"wires": []
},
{
"id": "6df40d236c040862",
"type": "switch",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "Switch on Relay 1 State ",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "true"
},
{
"t": "false"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 520,
"y": 120,
"wires": [
[
"714be65b64ba0b52"
],
[
"0e01aad07d0dfbe6"
]
]
},
{
"id": "2a6bf1f87286ec80",
"type": "debug",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "debug 35",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 1000,
"y": 140,
"wires": []
},
{
"id": "0e01aad07d0dfbe6",
"type": "Command",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "Set Rel1 True",
"mojo": {
"device": "idevice",
"command": "//relay/1/state",
"normalized": false,
"cmdvalue": "Manual configuration",
"args": true,
"onebased": false
},
"x": 770,
"y": 140,
"wires": [
[
"2a6bf1f87286ec80"
]
]
},
{
"id": "714be65b64ba0b52",
"type": "Command",
"z": "1439a15d8cb392ab",
"g": "590d989c208859bd",
"name": "Set Rel1 False",
"mojo": {
"device": "idevice",
"command": "//relay/1/state",
"normalized": false,
"cmdvalue": "Manual configuration",
"args": false,
"onebased": false
},
"x": 770,
"y": 100,
"wires": [
[
"5c444e29686dbdf6"
]
]
}
]