Skip to content

Instantly share code, notes, and snippets.

@DIYtechie
Last active November 6, 2023 16:45
Show Gist options
  • Save DIYtechie/97d1ad82740d1c0ca1e7d1936862969e to your computer and use it in GitHub Desktop.
Save DIYtechie/97d1ad82740d1c0ca1e7d1936862969e to your computer and use it in GitHub Desktop.
HueMagic dimmer (subflow)

(Disclaimer: this subflow might be outdated. I stopped using it myself after switching from hue bridge to deConz)

Subflow to be used with node-red-contrib-huemagic

Subflow subflow

Example flow

example flow


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

[
{
"id": "e07b1600.952758",
"type": "subflow",
"name": "HueMagic dimmer",
"info": "",
"category": "",
"in": [
{
"x": 40,
"y": 60,
"wires": [
{
"id": "fddda787.df7248"
}
]
}
],
"out": [
{
"x": 860,
"y": 200,
"wires": [
{
"id": "e5991875.4a2368",
"port": 0
},
{
"id": "d839dbf8.4fbda8",
"port": 0
},
{
"id": "87028dea.edc6",
"port": 0
}
]
}
],
"env": [
{
"name": "ButtonPressed",
"type": "num",
"value": "0"
},
{
"name": "ButtonReleased",
"type": "num",
"value": "1"
},
{
"name": "Step",
"type": "num",
"value": "5",
"ui": {
"icon": "font-awesome/fa-percent",
"type": "input",
"opts": {
"types": [
"num"
]
},
"label": {}
}
}
],
"color": "#E6E0F8",
"inputLabels": [
"from trigger"
],
"outputLabels": [
"to hue light"
],
"icon": "node-red/light.svg",
"status": {
"x": 860,
"y": 140,
"wires": [
{
"id": "87028dea.edc6",
"port": 0
},
{
"id": "d839dbf8.4fbda8",
"port": 0
},
{
"id": "e5991875.4a2368",
"port": 0
}
]
}
},
{
"id": "fddda787.df7248",
"type": "switch",
"z": "e07b1600.952758",
"name": "pressed/released?",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "ButtonReleased",
"vt": "env"
},
{
"t": "eq",
"v": "ButtonPressed",
"vt": "env"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 190,
"y": 60,
"wires": [
[
"9b2fca04.97ffd8",
"3c5b21f7.36c6ce"
],
[
"47aae127.8b73f",
"b7fdabcf.07e1d8"
]
]
},
{
"id": "47aae127.8b73f",
"type": "trigger",
"z": "e07b1600.952758",
"op1": "",
"op2": "true",
"op1type": "nul",
"op2type": "bool",
"duration": "500",
"extend": false,
"units": "ms",
"reset": "reset",
"bytopic": "all",
"name": "Button held?",
"x": 410,
"y": 120,
"wires": [
[
"ec831b0a.31d458"
]
]
},
{
"id": "e5991875.4a2368",
"type": "change",
"z": "e07b1600.952758",
"name": "{\"toggle\":1}",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "{\"toggle\":1}",
"tot": "json"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 710,
"y": 100,
"wires": [
[]
]
},
{
"id": "234d2c25.d97894",
"type": "change",
"z": "e07b1600.952758",
"name": "flow.next = 0",
"rules": [
{
"t": "set",
"p": "next",
"pt": "flow",
"to": "0",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 650,
"y": 140,
"wires": [
[]
]
},
{
"id": "804c04c1.d35ce8",
"type": "change",
"z": "e07b1600.952758",
"name": "flow.next = 1",
"rules": [
{
"t": "set",
"p": "next",
"pt": "flow",
"to": "1",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 650,
"y": 260,
"wires": [
[]
]
},
{
"id": "a791a981.82a298",
"type": "trigger",
"z": "e07b1600.952758",
"op1": "Step",
"op2": "0",
"op1type": "env",
"op2type": "str",
"duration": "-400",
"extend": false,
"units": "ms",
"reset": "reset",
"bytopic": "all",
"name": "",
"x": 440,
"y": 180,
"wires": [
[
"234d2c25.d97894",
"87028dea.edc6"
]
]
},
{
"id": "26d688ef.4aacf8",
"type": "trigger",
"z": "e07b1600.952758",
"op1": "Step",
"op2": "0",
"op1type": "env",
"op2type": "str",
"duration": "-400",
"extend": false,
"units": "ms",
"reset": "reset",
"bytopic": "all",
"name": "",
"x": 440,
"y": 220,
"wires": [
[
"804c04c1.d35ce8",
"d839dbf8.4fbda8"
]
]
},
{
"id": "ec831b0a.31d458",
"type": "switch",
"z": "e07b1600.952758",
"name": "flow.next switch",
"property": "next",
"propertyType": "flow",
"rules": [
{
"t": "eq",
"v": "1",
"vt": "str"
},
{
"t": "else"
}
],
"checkall": "true",
"repair": false,
"outputs": 2,
"x": 180,
"y": 200,
"wires": [
[
"a791a981.82a298"
],
[
"26d688ef.4aacf8"
]
]
},
{
"id": "87028dea.edc6",
"type": "template",
"z": "e07b1600.952758",
"name": "incrementBrightness",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\"incrementBrightness\":{{payload}}}",
"output": "json",
"x": 680,
"y": 180,
"wires": [
[]
]
},
{
"id": "d839dbf8.4fbda8",
"type": "template",
"z": "e07b1600.952758",
"name": "decrementBrightness",
"field": "payload",
"fieldType": "msg",
"format": "handlebars",
"syntax": "mustache",
"template": "{\"decrementBrightness\":{{payload}}}",
"output": "json",
"x": 680,
"y": 220,
"wires": [
[]
]
},
{
"id": "9b2fca04.97ffd8",
"type": "change",
"z": "e07b1600.952758",
"name": "reset",
"rules": [
{
"t": "set",
"p": "payload",
"pt": "msg",
"to": "reset",
"tot": "str"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 170,
"y": 120,
"wires": [
[
"a791a981.82a298",
"26d688ef.4aacf8",
"47aae127.8b73f"
]
]
},
{
"id": "b7fdabcf.07e1d8",
"type": "change",
"z": "e07b1600.952758",
"name": "",
"rules": [
{
"t": "set",
"p": "PressedTime",
"pt": "flow",
"to": "",
"tot": "date"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 40,
"wires": [
[]
]
},
{
"id": "3c5b21f7.36c6ce",
"type": "change",
"z": "e07b1600.952758",
"name": "",
"rules": [
{
"t": "set",
"p": "ReleasedTime",
"pt": "flow",
"to": "",
"tot": "date"
}
],
"action": "",
"property": "",
"from": "",
"to": "",
"reg": false,
"x": 440,
"y": 80,
"wires": [
[
"6df4edcd.364f64"
]
]
},
{
"id": "6df4edcd.364f64",
"type": "function",
"z": "e07b1600.952758",
"name": "Short press?",
"func": "if (flow.get(\"ReleasedTime\") - flow.get(\"PressedTime\") < 500)\n{\n msg.payload = \"Short press\";\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"x": 630,
"y": 60,
"wires": [
[
"e5991875.4a2368"
]
]
}
]
@SL8R8R
Copy link

SL8R8R commented Nov 6, 2023

Is there an easy way to add number of presses to this flow? If I want to press a button 4 times and have it perform an action, is that possible?

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