Skip to content

Instantly share code, notes, and snippets.

@Jleagle
Created July 18, 2022 09:40
Show Gist options
  • Save Jleagle/71341571c6036078af2a6df2364db6ec to your computer and use it in GitHub Desktop.
Save Jleagle/71341571c6036078af2a6df2364db6ec to your computer and use it in GitHub Desktop.
[
{
"id": "4989b63269e665e1",
"type": "http request",
"z": "37c10c7a9fbad0de",
"name": "Set Brightness",
"method": "GET",
"ret": "txt",
"paytoqs": "ignore",
"url": "",
"tls": "",
"persist": false,
"proxy": "",
"authType": "",
"senderr": false,
"headers": [],
"x": 1160,
"y": 1280,
"wires": [
[]
]
},
{
"id": "53f7e048e0fcf338",
"type": "split",
"z": "37c10c7a9fbad0de",
"name": "",
"splt": ",",
"spltType": "str",
"arraySplt": 1,
"arraySpltType": "len",
"stream": false,
"addname": "payload",
"x": 410,
"y": 1280,
"wires": [
[
"fff2e21df2e42cef"
]
]
},
{
"id": "a71005418c7343bb",
"type": "function",
"z": "37c10c7a9fbad0de",
"name": "",
"func": "\nmsg.brightness = msg.payload.brightness_pct\nmsg.payload = Object.keys(global.get('light_map'));\n\n//node.log(msg.payload)\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 260,
"y": 1280,
"wires": [
[
"53f7e048e0fcf338"
]
]
},
{
"id": "f14742284d95a23c",
"type": "api-current-state",
"z": "37c10c7a9fbad0de",
"name": "",
"server": "a3040d918205a56e",
"version": 3,
"outputs": 1,
"halt_if": "",
"halt_if_type": "str",
"halt_if_compare": "is",
"entity_id": "{{ent_id}}",
"state_type": "str",
"blockInputOverrides": false,
"outputProperties": [
{
"property": "entity",
"propertyType": "msg",
"value": "",
"valueType": "entityState"
},
{
"property": "data",
"propertyType": "msg",
"value": "",
"valueType": "entity"
}
],
"for": "0",
"forType": "num",
"forUnits": "minutes",
"override_topic": false,
"state_location": "payload",
"override_payload": "msg",
"entity_location": "data",
"override_data": "msg",
"x": 770,
"y": 1280,
"wires": [
[
"54abca94b3364bfc"
]
]
},
{
"id": "fff2e21df2e42cef",
"type": "function",
"z": "37c10c7a9fbad0de",
"name": "",
"func": "let ip = msg.payload\nlet ipMap = global.get('light_map')\n\nmsg.ip_suffix = ip;\nmsg.ent_id = 'light.' + ipMap[ip];\n\n//node.warn(msg.ent_id)\n\nreturn msg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 560,
"y": 1280,
"wires": [
[
"f14742284d95a23c"
]
]
},
{
"id": "d0f277a13e479031",
"type": "link in",
"z": "37c10c7a9fbad0de",
"name": "Dim Lights",
"links": [
"9cf7455b55b54f56",
"aa7371d290f5e954",
"bf3f570b2ab53b61",
"a8233d67caee9b26"
],
"x": 145,
"y": 1280,
"wires": [
[
"a71005418c7343bb"
]
]
},
{
"id": "54abca94b3364bfc",
"type": "function",
"z": "37c10c7a9fbad0de",
"name": "",
"func": "\nmsg.url = 'http://192.168.0.'+msg.ip_suffix+'/light/0?brightness='+msg.brightness+'&transition=5000'\n\nif (msg.override){\n return msg\n}\n\nlet b = msg.data.attributes.brightness\n\nif(!b){\n return msg\n}\n\nb = (msg.data.attributes.brightness/255)*100\n\n//node.warn(['current:', b,'new:', msg.brightness])\n\nif (b > msg.brightness){\n return msg;\n}\n\nreturn null\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 980,
"y": 1280,
"wires": [
[
"4989b63269e665e1",
"dc3ec379198c1566"
]
]
},
{
"id": "c56b5064771f90ce",
"type": "comment",
"z": "37c10c7a9fbad0de",
"name": "Dim Lights",
"info": "",
"x": 120,
"y": 1240,
"wires": []
},
{
"id": "112d4af6e7494738",
"type": "ha-button",
"z": "37c10c7a9fbad0de",
"name": "",
"version": 0,
"debugenabled": false,
"outputs": 1,
"entityConfig": "7113a9ca1110aa98",
"outputProperties": [
{
"property": "payload.brightness_pct",
"propertyType": "msg",
"value": "100",
"valueType": "str"
}
],
"x": 110,
"y": 1320,
"wires": [
[
"a71005418c7343bb"
]
]
},
{
"id": "dc3ec379198c1566",
"type": "debug",
"z": "37c10c7a9fbad0de",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "url",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1140,
"y": 1320,
"wires": []
},
{
"id": "a3040d918205a56e",
"type": "server",
"name": "Home Assistant",
"version": 2,
"addon": false,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": true,
"heartbeatInterval": "60"
},
{
"id": "7113a9ca1110aa98",
"type": "ha-entity-config",
"server": "a3040d918205a56e",
"name": "node-red-no-dim",
"version": 2,
"haConfig": [
{
"property": "name",
"value": "Max Brightness"
},
{
"property": "icon",
"value": ""
},
{
"property": "device_class",
"value": ""
}
],
"entityType": "button"
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment