Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[
{
"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,
"x": 710,
"y": 1200,
"wires": [
[
"d68584db.272cb8"
]
],
"icon": "font-awesome/fa-arrows-v"
},
{
"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": "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": "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": 920,
"y": 1245,
"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": 940,
"y": 1340,
"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,
"x": 930,
"y": 1300,
"wires": [
[
"5e6db0.ac1fc25"
],
[
"d68584db.272cb8"
]
],
"inputLabels": [
"Timer Instructions"
],
"outputLabels": [
"Update Brightness",
"Stop"
],
"icon": "font-awesome/fa-book"
},
{
"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": ""
},
{
"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
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment