Skip to content

Instantly share code, notes, and snippets.

@jordanrounds
Created August 17, 2020 22:18
Show Gist options
  • Save jordanrounds/ab7edc7dab8abbf03d7ca5d11fb1fb0c to your computer and use it in GitHub Desktop.
Save jordanrounds/ab7edc7dab8abbf03d7ca5d11fb1fb0c to your computer and use it in GitHub Desktop.
Node Red Flow allowing Insteon Dimmers to control Hue Bulbs
[
{
"id": "be5d7e99.087c9",
"type": "tab",
"label": "Insteon Dimmers",
"disabled": false,
"info": ""
},
{
"id": "e49ef50c.13e7a8",
"type": "server-state-changed",
"z": "be5d7e99.087c9",
"name": "Dimmer",
"server": "2ef1a1b8.4b157e",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "light.dimmer",
"entityidfiltertype": "substring",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": true,
"x": 190,
"y": 1380,
"wires": [
[
"2556d986.9ca816"
]
]
},
{
"id": "918c5a36.866f38",
"type": "mqtt in",
"z": "be5d7e99.087c9",
"name": "",
"topic": "insteon/+/manual_state",
"qos": "2",
"datatype": "json",
"broker": "f619c574.7242d8",
"x": 240,
"y": 1240,
"wires": [
[
"946433ec.c7c76"
]
]
},
{
"id": "c45ef057.56516",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Dim/Brighten",
"func": "let light = msg.payload;\nlet step = 30, max = 20, transition = .4;\nlet curBrightness = 0, nextBrightness = 0;\n\nmsg.instructions = { \"increase\": true, \"transition\": transition, \"step\": step, \"count\": 0, \"max\": max, \"brightness\": 0};\n\n//brightness attribute may not exist if brightening from off state\nif(light.attributes.hasOwnProperty('brightness')) {\n curBrightness = light.attributes.brightness;\n}\n\nif(msg.manual_state == \"DOWN\") {\n nextBrightness = curBrightness - step;\n nextBrightness = nextBrightness < 0 ? 0 : nextBrightness;\n msg.instructions.increase = false;\n} else {\n nextBrightness = curBrightness + step;\n nextBrightness = nextBrightness > 255 ? 255 : nextBrightness;\n}\n\nmsg.instructions.brightness = nextBrightness\nmsg.light = light;\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 710,
"y": 1200,
"wires": [
[
"33067ec4.4c8322"
]
],
"icon": "font-awesome/fa-arrows-v"
},
{
"id": "7222b439.77935c",
"type": "switch",
"z": "be5d7e99.087c9",
"name": "On/Off",
"property": "payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 570,
"y": 1380,
"wires": [
[
"c40ccd86.1040c"
],
[
"5c227774.6b06e8"
]
],
"outputLabels": [
"On",
"Off"
],
"icon": "font-awesome/fa-question-circle"
},
{
"id": "5c227774.6b06e8",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Light Off",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_off",
"entityId": "{{data.new_state.attributes.sync_entity_id}}",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 720,
"y": 1420,
"wires": [
[]
],
"icon": "font-awesome/fa-toggle-off"
},
{
"id": "4805c60.ac8da3c",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Light On",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{data.new_state.attributes.sync_entity_id}}",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 869,
"y": 1371,
"wires": [
[]
],
"icon": "font-awesome/fa-toggle-on"
},
{
"id": "3d8df394.6c6d3c",
"type": "mqtt in",
"z": "be5d7e99.087c9",
"name": "",
"topic": "insteon/+/state",
"qos": "0",
"datatype": "json",
"broker": "f619c574.7242d8",
"x": 220,
"y": 1020,
"wires": [
[
"4ab6b9e9.1c6db8"
]
]
},
{
"id": "fe8eced6.3b90e",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Set Brightness",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{payload.entity_id}}",
"data": "{ \"brightness\": {{brightness}} }",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 1020,
"y": 1020,
"wires": [
[]
],
"icon": "font-awesome/fa-lightbulb-o"
},
{
"id": "a897e411.b26bf8",
"type": "ha-get-entities",
"z": "be5d7e99.087c9",
"server": "2ef1a1b8.4b157e",
"name": "Light",
"rules": [
{
"property": "entity_id",
"logic": "is",
"value": "dimmer.attributes.sync_entity_id",
"valueType": "msg"
}
],
"output_type": "split",
"output_empty_results": false,
"output_location_type": "msg",
"output_location": "lights",
"output_results_count": 1,
"x": 690,
"y": 1020,
"wires": [
[
"fe8eced6.3b90e"
]
],
"icon": "font-awesome/fa-search",
"info": "Find the Light that is synced to this dimmer's address."
},
{
"id": "2142dfa2.67dc6",
"type": "ha-get-entities",
"z": "be5d7e99.087c9",
"server": "2ef1a1b8.4b157e",
"name": "Light",
"rules": [
{
"property": "attributes.sync_address",
"logic": "is",
"value": "payload.address",
"valueType": "msg"
}
],
"output_type": "split",
"output_empty_results": false,
"output_location_type": "msg",
"output_location": "lights",
"output_results_count": 1,
"x": 570,
"y": 1200,
"wires": [
[
"c45ef057.56516"
]
],
"icon": "font-awesome/fa-search"
},
{
"id": "4ab6b9e9.1c6db8",
"type": "ha-get-entities",
"z": "be5d7e99.087c9",
"server": "2ef1a1b8.4b157e",
"name": "Dimmer",
"rules": [
{
"property": "attributes.address",
"logic": "is",
"value": "payload.address",
"valueType": "msg"
}
],
"output_type": "array",
"output_empty_results": false,
"output_location_type": "msg",
"output_location": "dimmers",
"output_results_count": 1,
"x": 400,
"y": 1020,
"wires": [
[
"116bc6d8.daed69"
]
],
"icon": "font-awesome/fa-search",
"info": "Finds the dimmer using the address from the mqtt payload as long as its state is on. The allows for responding to a press of the switch if its not already at 100%."
},
{
"id": "ee309b59.d0b0c8",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Stop",
"func": "let attrs = msg.data.new_state.attributes;\nlet hasManual = attrs.hasOwnProperty(\"manual_state\");\n\nif(!hasManual || hasManual && attrs.manual_state == \"STOP\") {\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 450,
"y": 1380,
"wires": [
[
"7222b439.77935c"
]
],
"outputLabels": [
"Not Manual"
],
"icon": "font-awesome/fa-question-circle"
},
{
"id": "7fff3c3f.6ec034",
"type": "server-state-changed",
"z": "be5d7e99.087c9",
"name": "Light",
"server": "2ef1a1b8.4b157e",
"version": 1,
"exposeToHomeAssistant": false,
"haConfig": [
{
"property": "name",
"value": ""
},
{
"property": "icon",
"value": ""
}
],
"entityidfilter": "light.",
"entityidfiltertype": "substring",
"outputinitially": false,
"state_type": "str",
"haltifstate": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"outputs": 1,
"output_only_on_state_change": false,
"x": 189,
"y": 1507,
"wires": [
[
"2575373d.692778"
]
]
},
{
"id": "2575373d.692778",
"type": "switch",
"z": "be5d7e99.087c9",
"name": "Bulb",
"property": "data.new_state.attributes.is_sync_bulb",
"propertyType": "msg",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 309,
"y": 1507,
"wires": [
[
"587c8d49.98bb24"
]
],
"icon": "font-awesome/fa-exchange"
},
{
"id": "2556d986.9ca816",
"type": "switch",
"z": "be5d7e99.087c9",
"name": "Dimmer",
"property": "data.new_state.attributes.is_sync_dimmer",
"propertyType": "msg",
"rules": [
{
"t": "true"
}
],
"checkall": "true",
"repair": false,
"outputs": 1,
"x": 320,
"y": 1380,
"wires": [
[
"ee309b59.d0b0c8"
]
],
"icon": "font-awesome/fa-exchange"
},
{
"id": "587c8d49.98bb24",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Sync Entities",
"func": "let attrs = msg.data.new_state.attributes;\nlet payload = msg.payload;\n\nif(attrs.hasOwnProperty(\"sync_entities\")) {\n msg.payload = attrs.sync_entities;\n msg.original_payload = payload;\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 449,
"y": 1507,
"wires": [
[
"5a8eb054.60fcd"
]
],
"outputLabels": [
"Not Manual"
],
"icon": "font-awesome/fa-question-circle"
},
{
"id": "5a8eb054.60fcd",
"type": "split",
"z": "be5d7e99.087c9",
"name": "",
"splt": "\\n",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "",
"x": 589,
"y": 1507,
"wires": [
[
"5c130d08.7d94f4"
]
]
},
{
"id": "8e14edc5.7b031",
"type": "switch",
"z": "be5d7e99.087c9",
"name": "On/Off",
"property": "original_payload",
"propertyType": "msg",
"rules": [
{
"t": "eq",
"v": "on",
"vt": "str"
},
{
"t": "eq",
"v": "off",
"vt": "str"
}
],
"checkall": "false",
"repair": false,
"outputs": 2,
"x": 849,
"y": 1507,
"wires": [
[
"10ab9d89.52a942"
],
[
"de22d1c5.9658"
]
],
"outputLabels": [
"On",
"Off"
],
"icon": "font-awesome/fa-question-circle"
},
{
"id": "10ab9d89.52a942",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Stop",
"func": "let attrs = msg.payload.attributes;\nlet hasManual = attrs.hasOwnProperty(\"manual_state\");\n\nif(!hasManual || hasManual && attrs.manual_state == \"STOP\") {\n return msg;\n}",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 990,
"y": 1463,
"wires": [
[
"2c336f65.ec6d7"
]
],
"outputLabels": [
"Not Manual"
],
"icon": "font-awesome/fa-exclamation-triangle"
},
{
"id": "2c336f65.ec6d7",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Dimmer On",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{payload.entity_id}}",
"data": "{ \"brightness\": {{data.new_state.attributes.brightness}} }",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 1150,
"y": 1463,
"wires": [
[]
],
"icon": "font-awesome/fa-toggle-on"
},
{
"id": "de22d1c5.9658",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Dimmer Off",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_off",
"entityId": "{{payload.entity_id}}",
"data": "",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 1151,
"y": 1514,
"wires": [
[]
],
"icon": "font-awesome/fa-toggle-off"
},
{
"id": "5c130d08.7d94f4",
"type": "ha-get-entities",
"z": "be5d7e99.087c9",
"server": "2ef1a1b8.4b157e",
"name": "Dimmer",
"rules": [
{
"property": "entity_id",
"logic": "is",
"value": "payload",
"valueType": "msg"
}
],
"output_type": "split",
"output_empty_results": false,
"output_location_type": "msg",
"output_location": "dimmers",
"output_results_count": 1,
"x": 719,
"y": 1507,
"wires": [
[
"8e14edc5.7b031"
]
],
"icon": "font-awesome/fa-search"
},
{
"id": "6f164eab.e6208",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "ON 255",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"state\" : \"ON\", \"brightness\" : 255, \"reason\" : \"device\", \"mode\" : \"normal\", \"address\" : \"41.b8.f6\" }",
"payloadType": "json",
"x": 250,
"y": 960,
"wires": [
[
"4ab6b9e9.1c6db8"
]
]
},
{
"id": "35a18b62.66afb4",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "UP",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"manual_state\" : \"UP\", \"address\" : \"41.b3.5e\" }",
"payloadType": "json",
"x": 250,
"y": 1100,
"wires": [
[
"946433ec.c7c76"
]
]
},
{
"id": "d371b6e.ad06948",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "STOP",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"manual_state\" : \"STOP\", \"address\" : \"41.b3.5e\" }",
"payloadType": "json",
"x": 250,
"y": 1180,
"wires": [
[
"946433ec.c7c76"
]
]
},
{
"id": "c6ddd6b5.3a4828",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "DOWN",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"manual_state\" : \"DOWN\", \"address\" : \"41.b3.5e\" }",
"payloadType": "json",
"x": 250,
"y": 1140,
"wires": [
[
"946433ec.c7c76"
]
]
},
{
"id": "116bc6d8.daed69",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Manual Tap",
"func": "let payload = msg.payload;\n\nmsg.dimmer = msg.dimmers[0];\ndelete msg.dimmers;\n\nlet device_on = payload.reason == \"device\" && payload.state == \"ON\";\nlet device_off = payload.reason == \"device\" && payload.state == \"OFF\";\nlet fast = payload.mode == \"fast\";\n\nlet fast_on = msg.dimmer.state == \"off\" && device_on && fast;\nlet fast_off = msg.dimmer.state == \"on\" && device_off && fast;\n\nlet fast_on_from_on = msg.dimmer.state == \"on\" && device_on && fast;\nlet fast_off_from_off = msg.dimmer.state == \"off\" && device_off && fast\n\nlet on_from_on = msg.dimmer.state == \"on\" && device_on\n\nif(fast_on || on_from_on) {\n msg.brightness = payload.brightness;\n return msg;\n}\n\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 550,
"y": 1020,
"wires": [
[
"a897e411.b26bf8"
]
],
"icon": "font-awesome/fa-question-circle",
"info": "`fast_on` and `fast_off` assume the dimmer was in the opposite state\n\n`fast_on_from_on` and `fast_off_from_off` could be used as extra commands, cycle through light colors, other automations, etc.\n\nOnly `fast_on`, and `on_from_on` have been handled."
},
{
"id": "946433ec.c7c76",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Stop",
"func": "let state = msg.payload.manual_state;\nmsg.manual_state = state;\n\nif(state == \"STOP\") {\n msg.payload = \"stop\"\n return [null, msg];\n}\n\nreturn [msg, null]\n",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 430,
"y": 1240,
"wires": [
[
"2142dfa2.67dc6"
],
[
"d68584db.272cb8"
]
],
"icon": "font-awesome/fa-question-circle"
},
{
"id": "d68584db.272cb8",
"type": "stoptimer",
"z": "be5d7e99.087c9",
"duration": "400",
"units": "Millisecond",
"payloadtype": "num",
"payloadval": "0",
"name": "",
"x": 1117,
"y": 1246,
"wires": [
[
"c3329d3.07ae36"
],
[]
]
},
{
"id": "5e6db0.ac1fc25",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Set Brightness",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{light.entity_id}}",
"data": "{ \"brightness\": {{instructions.brightness}}, \"transition\" : {{instructions.transition}} }",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 1138,
"y": 1339,
"wires": [
[
"d68584db.272cb8"
]
],
"inputLabels": [
"Instructions"
],
"icon": "font-awesome/fa-lightbulb-o"
},
{
"id": "c3329d3.07ae36",
"type": "function",
"z": "be5d7e99.087c9",
"name": "Update Instructions",
"func": "let inst = msg.instructions;\n\ninst.count++;\n\nif(inst.count >= inst.max || inst.brightness > 255 || inst.brightness < 0) {\n msg.payload = \"stop\"\n return [null, msg]\n}\n\n\nif(inst.increase) {\n inst.brightness += inst.step;\n} else {\n inst.brightness -= inst.step;\n}\n\nreturn [msg, null];",
"outputs": 2,
"noerr": 0,
"initialize": "",
"finalize": "",
"x": 1127,
"y": 1295,
"wires": [
[
"5e6db0.ac1fc25"
],
[
"d68584db.272cb8"
]
],
"inputLabels": [
"Timer Instructions"
],
"outputLabels": [
"Update Brightness",
"Stop"
],
"icon": "font-awesome/fa-book"
},
{
"id": "79ec6ae4.579e34",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "FAST ON",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"state\" : \"ON\", \"brightness\" : 255, \"reason\" : \"device\", \"mode\" : \"fast\", \"address\" : \"41.b3.5e\" }",
"payloadType": "json",
"x": 240,
"y": 920,
"wires": [
[
"4ab6b9e9.1c6db8"
]
]
},
{
"id": "ceb96b8a.32a488",
"type": "inject",
"z": "be5d7e99.087c9",
"name": "FAST OFF",
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "{ \"state\" : \"OFF\", \"brightness\" : 0, \"reason\" : \"device\", \"mode\" : \"fast\", \"address\" : \"41.ad.4f\" }",
"payloadType": "json",
"x": 240,
"y": 880,
"wires": [
[]
]
},
{
"id": "c40ccd86.1040c",
"type": "api-current-state",
"z": "be5d7e99.087c9",
"name": "Light Off?",
"server": "2ef1a1b8.4b157e",
"version": 1,
"outputs": 2,
"halt_if": "off",
"halt_if_type": "str",
"halt_if_compare": "is",
"override_topic": false,
"entity_id": "{{data.new_state.attributes.sync_entity_id}}",
"state_type": "str",
"state_location": "",
"override_payload": "none",
"entity_location": "",
"override_data": "none",
"blockInputOverrides": false,
"x": 720,
"y": 1318,
"wires": [
[
"4805c60.ac8da3c"
],
[]
]
},
{
"id": "33067ec4.4c8322",
"type": "api-call-service",
"z": "be5d7e99.087c9",
"name": "Set Brightness",
"server": "2ef1a1b8.4b157e",
"version": 1,
"debugenabled": false,
"service_domain": "light",
"service": "turn_on",
"entityId": "{{light.entity_id}}",
"data": "{ \"brightness\": {{instructions.brightness}}, \"transition\" : {{instructions.transition}} }",
"dataType": "json",
"mergecontext": "",
"output_location": "",
"output_location_type": "none",
"mustacheAltTags": false,
"x": 880,
"y": 1200,
"wires": [
[
"d68584db.272cb8"
]
],
"inputLabels": [
"Instructions"
],
"icon": "font-awesome/fa-lightbulb-o"
},
{
"id": "2ef1a1b8.4b157e",
"type": "server",
"z": "",
"name": "Rounds House",
"legacy": false,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true
},
{
"id": "f619c574.7242d8",
"type": "mqtt-broker",
"z": "",
"name": "NUC",
"broker": "192.168.7.234",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": false,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment