Skip to content

Instantly share code, notes, and snippets.

@DIYtechie
Last active October 11, 2022 08:42
Show Gist options
  • Save DIYtechie/7c76f205de0dd761a075b6cb0128b480 to your computer and use it in GitHub Desktop.
Save DIYtechie/7c76f205de0dd761a075b6cb0128b480 to your computer and use it in GitHub Desktop.
Single Button MultiPress (subflow)

Sends single, double, triple or long press commands based on binary input (e.g GPIO switches or other switches that sends "pressed" and "released" events). Video of this subflow in action here

If you are using an IHC controller, you should create the multipress logic in the original controller software instead.

Subflow image

Example flow 1 image

Example flow 2 image


Copy the subflow below to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option

[
{
"id": "c23401c4.cf92b",
"type": "subflow",
"name": "Single Button MultiPress",
"info": "",
"category": "",
"in": [
{
"x": 60,
"y": 100,
"wires": [
{
"id": "f6674880.4a98d8"
}
]
}
],
"out": [
{
"x": 780,
"y": 260,
"wires": [
{
"id": "621fd442.e3355c",
"port": 0
},
{
"id": "bb24b600.e59d68",
"port": 0
}
]
},
{
"x": 780,
"y": 300,
"wires": [
{
"id": "621fd442.e3355c",
"port": 1
}
]
},
{
"x": 780,
"y": 340,
"wires": [
{
"id": "621fd442.e3355c",
"port": 2
}
]
},
{
"x": 780,
"y": 380,
"wires": [
{
"id": "9a560181.5faed",
"port": 0
}
]
}
],
"env": [
{
"name": "ButtonPressed",
"type": "str",
"value": "0"
},
{
"name": "ButtonReleased",
"type": "str",
"value": "1"
},
{
"name": "single press",
"type": "str",
"value": "single press output"
},
{
"name": "double press",
"type": "str",
"value": "double press output"
},
{
"name": "triple press",
"type": "str",
"value": "triple press output"
},
{
"name": "long press",
"type": "str",
"value": "long press output"
}
],
"color": "#E6E0F8",
"inputLabels": [
"from trigger"
],
"outputLabels": [
"Single press",
"Double press",
"Triple press",
"Long press"
],
"icon": "node-red/serial.svg",
"status": {
"x": 780,
"y": 220,
"wires": [
{
"id": "9a560181.5faed",
"port": 0
},
{
"id": "3833bace.548da6",
"port": 0
},
{
"id": "bb24b600.e59d68",
"port": 0
}
]
}
},
{
"id": "7fefbd86.bcfda4",
"type": "trigger",
"z": "c23401c4.cf92b",
"op1": "",
"op2": "1",
"op1type": "nul",
"op2type": "str",
"duration": "400",
"extend": false,
"units": "ms",
"reset": "",
"bytopic": "all",
"name": "Wait for 400 ms",
"x": 480,
"y": 180,
"wires": [
[
"3833bace.548da6"
]
]
},
{
"id": "f6674880.4a98d8",
"type": "switch",
"z": "c23401c4.cf92b",
"name": "pressed/released?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ButtonPressed",
"vt": "env"
},
{
"t": "eq",
"v": "ButtonReleased",
"vt": "env"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 210,
"y": 100,
"wires": [
[
"6218943c.5fc54c",
"6fd796e.e5a7968"
],
[
"7fefbd86.bcfda4",
"31b52fd1.ea8d1"
]
]
},
{
"id": "3ced6124.55172e",
"type": "function",
"z": "c23401c4.cf92b",
"name": "set press variable",
"func": "if (flow.get(\"presses\") == env.get(\"triple press\"))\n {\n }\nelse\n if (flow.get(\"presses\") == env.get(\"double press\"))\n {\n flow.set(\"presses\", env.get(\"triple press\"));\n }\n else\n {\n flow.set(\"presses\", env.get(\"double press\"));\n }\nreturn msg",
"outputs": 1,
"noerr": 0,
"x": 210,
"y": 220,
"wires": [
[
"81be5c16.dd42a"
]
]
},
{
"id": "6218943c.5fc54c",
"type": "trigger",
"z": "c23401c4.cf92b",
"op1": "",
"op2": "1",
"op1type": "nul",
"op2type": "str",
"duration": "1.5",
"extend": false,
"units": "s",
"reset": "",
"bytopic": "all",
"name": "long press?",
"x": 470,
"y": 100,
"wires": [
[
"9a560181.5faed"
]
]
},
{
"id": "3833bace.548da6",
"type": "change",
"z": "c23401c4.cf92b",
"name": "flow -> payload",
"rules": [
{
"t": "move",
"p": "presses",
"pt": "flow",
"to": "payload",
"tot": "msg"
},
{
"t": "set",
"p": "presses",
"pt": "flow",
"to": "single press",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 520,
"y": 220,
"wires": [
[
"621fd442.e3355c"
]
]
},
{
"id": "9a560181.5faed",
"type": "change",
"z": "c23401c4.cf92b",
"name": "long press",
"rules": [
{
"t": "set",
"p": "presses",
"pt": "flow",
"to": "long press",
"tot": "env"
},
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "long press",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 630,
"y": 100,
"wires": [
[]
]
},
{
"id": "621fd442.e3355c",
"type": "switch",
"z": "c23401c4.cf92b",
"name": "Sort payloads",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "single press",
"vt": "env"
},
{
"t": "eq",
"v": "double press",
"vt": "env"
},
{
"t": "eq",
"v": "triple press",
"vt": "env"
},
{
"t": "null"
},
{
"t": "eq",
"v": "long press",
"vt": "env"
}
],
"checkall": "true",
"repair": false,
"outputs": 5,
"x": 520,
"y": 280,
"wires": [
[],
[],
[],
[
"bb24b600.e59d68"
],
[
"7c14d743.8ab428"
]
]
},
{
"id": "bb24b600.e59d68",
"type": "change",
"z": "c23401c4.cf92b",
"name": "null -> single press",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "single press",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 530,
"y": 340,
"wires": [
[]
]
},
{
"id": "31b52fd1.ea8d1",
"type": "change",
"z": "c23401c4.cf92b",
"name": "reset trigger",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 510,
"y": 140,
"wires": [
[
"6218943c.5fc54c"
]
]
},
{
"id": "81be5c16.dd42a",
"type": "change",
"z": "c23401c4.cf92b",
"name": "reset trigger",
"rules": [
{
"t": "set",
"p": "reset",
"pt": "msg",
"to": "true",
"tot": "bool"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 230,
"y": 260,
"wires": [
[
"7fefbd86.bcfda4"
]
]
},
{
"id": "6fd796e.e5a7968",
"type": "change",
"z": "c23401c4.cf92b",
"name": "press timers",
"rules": [
{
"t": "move",
"p": "NewTime",
"pt": "flow",
"to": "OldTime",
"tot": "flow"
},
{
"t": "set",
"p": "NewTime",
"pt": "flow",
"to": "",
"tot": "date"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 230,
"y": 140,
"wires": [
[
"daa2d16.c4ed63"
]
]
},
{
"id": "daa2d16.c4ed63",
"type": "function",
"z": "c23401c4.cf92b",
"name": "Short time?",
"func": "if (flow.get(\"NewTime\") - flow.get(\"OldTime\") <= 400)\n{\n msg.payload = \"Short press\";\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 230,
"y": 180,
"wires": [
[
"3ced6124.55172e"
]
]
},
{
"id": "7c14d743.8ab428",
"type": "change",
"z": "c23401c4.cf92b",
"name": "set default flow.presses",
"rules": [
{
"t": "set",
"p": "presses",
"pt": "flow",
"to": "single press",
"tot": "env"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 550,
"y": 380,
"wires": [
[]
]
},
{
"id": "8cf7c1f0.509b4",
"type": "comment",
"z": "c23401c4.cf92b",
"name": "Link to latest version of this subflow: https://flows.nodered.org/flow/7c76f205de0dd761a075b6cb0128b480",
"info": "",
"x": 410,
"y": 40,
"wires": []
}
]
@pyloutom
Copy link

Bonjour, je souhaite avoir la même chose, mais je n'arrive pas à la faire. J'aimerais avoir un bouton qui change de fonction à chaque impulsion pour changer mon type de chauffage par exemple. Un appuis mode OFF Deux appuis mode ECO Trois Normal et Quatre Marche forcé. Si vous avez une idée, je suis preneur après pas mal d'heure de recherche...

@DIYtechie
Copy link
Author

Not sure I understand. Are you perhaps looking for something like this instead? https://flows.nodered.org/flow/4e5614087340e87b87f4a6013298d0ac

@pyloutom
Copy link

Merci, je vais étudier cela, peut-être que ça pourrais convenir, c'est gentil merci beaucoup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment