Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[
{
"id":"a0a36d8b.fd7a3",
"type":"tab",
"label":"Lights",
"disabled":false,
"info":""
},
{
"id":"28d46fdf.da92",
"type":"tab",
"label":"Websocket IN",
"disabled":false,
"info":""
},
{
"id":"c150d7fb.353b58",
"type":"websocket-listener",
"z":"",
"path":"",
"wholemsg":"false"
},
{
"id":"6f67fba7.fa7c04",
"type":"yeelight-compat-hue-config",
"z":"",
"hostname":"192.168.0.13",
"port":"55443",
"name":"Weegle Room"
},
{
"id":"33b00827.912548",
"type":"yeelight-compat-hue-config",
"z":"",
"hostname":"192.168.0.13",
"port":"55443",
"name":"Weegle Room"
},
{
"id":"f2231b57.5147b8",
"type":"function",
"z":"a0a36d8b.fd7a3",
"name":"Add id",
"func":"msg.payload.id = 'weegle_light';\nreturn msg;",
"outputs":1,
"noerr":0,
"x":270,
"y":60,
"wires":[
[
"133fca4e.66f996"
]
]
},
{
"id":"c7a1d75a.d9b6f8",
"type":"websocket out",
"z":"a0a36d8b.fd7a3",
"name":"Websocket out",
"server":"c150d7fb.353b58",
"client":"",
"x":820,
"y":300,
"wires":[
]
},
{
"id":"133fca4e.66f996",
"type":"function",
"z":"a0a36d8b.fd7a3",
"name":"Update lights variable",
"func":"const lights = global.get('lights') || [];\n\nconst light = {\n id: msg.payload.id,\n on: msg.payload.state.on,\n bri: msg.payload.state.bri,\n name: msg.payload.name\n};\n\nconst lightExist = (lightArray, id) => \n lightArray.reduce((isHere, currentLight) => isHere || currentLight.id === id , false);\n \nlet newLights;\n \nif(!lightExist(lights, light.id)) {\n newLights = [...lights, light];\n} else {\n newLights = lights.map(currentLight => {\n if(currentLight.id === light.id){\n return Object.assign(currentLight, {\n on: light.on,\n bri: light.bri,\n name: light.name\n })\n }\n return currentLight\n })\n}\n\nglobal.set('lights', newLights);\n\nmsg.payload = {\n endpoint: \"yeelight::get\",\n payload: light\n}\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":440,
"y":60,
"wires":[
[
"c7a1d75a.d9b6f8",
"42af039a.595efc"
]
]
},
{
"id":"766f68ed.988678",
"type":"switch",
"z":"28d46fdf.da92",
"name":"Redirect to light",
"property":"payload.id",
"propertyType":"msg",
"rules":[
{
"t":"eq",
"v":"weegle_light",
"vt":"str"
},
{
"t":"eq",
"v":"salon_light",
"vt":"str"
}
],
"checkall":"true",
"repair":false,
"outputs":2,
"x":600,
"y":180,
"wires":[
[
"e213ce.dbb31c3"
],
[
]
]
},
{
"id":"2e1d488d.940c48",
"type":"websocket in",
"z":"28d46fdf.da92",
"name":"Websocket in",
"server":"c150d7fb.353b58",
"client":"",
"x":70,
"y":440,
"wires":[
[
"4bb130b2.993ad"
]
]
},
{
"id":"15f843e1.93cf1c",
"type":"switch",
"z":"28d46fdf.da92",
"name":"Router",
"property":"payload.endpoint",
"propertyType":"msg",
"rules":[
{
"t":"cont",
"v":"yeelight::set",
"vt":"str"
},
{
"t":"eq",
"v":"yeelight::getAll",
"vt":"str"
},
{
"t":"eq",
"v":"yeelight::get",
"vt":"str"
}
],
"checkall":"true",
"repair":false,
"outputs":3,
"x":330,
"y":440,
"wires":[
[
"4683f15.be2e01"
],
[
"2b9a77b6.c19838"
],
[
"5265d672.89cf28",
"fc8395f.e934468"
]
]
},
{
"id":"db3cd62c.da3e38",
"type":"websocket out",
"z":"28d46fdf.da92",
"name":"Websocket out",
"server":"c150d7fb.353b58",
"client":"",
"x":820,
"y":440,
"wires":[
]
},
{
"id":"2b9a77b6.c19838",
"type":"function",
"z":"28d46fdf.da92",
"name":"Get all lights",
"func":"const lights = global.get('lights') || [];\n\nmsg.payload = {\n endpoint: \"yeelight::getAll\",\n payload: lights.map(({id,on,name}) => ({\n id,\n on,\n name\n }))\n};\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":620,
"y":440,
"wires":[
[
"db3cd62c.da3e38"
]
]
},
{
"id":"1f917aaf.e632e5",
"type":"inject",
"z":"28d46fdf.da92",
"name":"",
"topic":"",
"payload":"{\"on\": false}",
"payloadType":"json",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"x":530,
"y":60,
"wires":[
[
"e213ce.dbb31c3"
]
]
},
{
"id":"33ffc0ab.65ad4",
"type":"inject",
"z":"28d46fdf.da92",
"name":"",
"topic":"",
"payload":"{\"on\": true}",
"payloadType":"json",
"repeat":"",
"crontab":"",
"once":false,
"onceDelay":0.1,
"x":540,
"y":20,
"wires":[
[
"e213ce.dbb31c3"
]
]
},
{
"id":"4bb130b2.993ad",
"type":"json",
"z":"28d46fdf.da92",
"name":"",
"property":"payload",
"action":"",
"pretty":false,
"x":210,
"y":440,
"wires":[
[
"15f843e1.93cf1c"
]
]
},
{
"id":"c7c668ee.3e06f8",
"type":"websocket out",
"z":"28d46fdf.da92",
"name":"Websocket out",
"server":"c150d7fb.353b58",
"client":"",
"x":840,
"y":520,
"wires":[
]
},
{
"id":"5265d672.89cf28",
"type":"function",
"z":"28d46fdf.da92",
"name":"Get one light",
"func":"const lights = global.get('lights') || [];\n\nconst light = lights.find(currentLight => currentLight.id === msg.payload.payload.id);\n\nmsg.payload = {\n endpoint: \"yeelight::get\",\n payload: light || null\n};\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":570,
"y":520,
"wires":[
[
"c7c668ee.3e06f8"
]
]
},
{
"id":"7b836474.fa701c",
"type":"yeelight-compat-hue-state",
"z":"a0a36d8b.fd7a3",
"name":"",
"server":"6f67fba7.fa7c04",
"x":120,
"y":60,
"wires":[
[
"f2231b57.5147b8"
]
]
},
{
"id":"e213ce.dbb31c3",
"type":"yeelight-compat-hue-out",
"z":"28d46fdf.da92",
"name":"",
"server":"6f67fba7.fa7c04",
"x":780,
"y":20,
"wires":[
]
},
{
"id":"4683f15.be2e01",
"type":"function",
"z":"28d46fdf.da92",
"name":"Extract command",
"func":"msg.payload = msg.payload.payload;\n\nreturn msg;",
"outputs":1,
"noerr":0,
"x":410,
"y":180,
"wires":[
[
"766f68ed.988678"
]
]
},
{
"id":"fc8395f.e934468",
"type":"debug",
"z":"28d46fdf.da92",
"name":"",
"active":true,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"x":580,
"y":600,
"wires":[
]
},
{
"id":"42af039a.595efc",
"type":"debug",
"z":"a0a36d8b.fd7a3",
"name":"",
"active":true,
"tosidebar":true,
"console":false,
"tostatus":false,
"complete":"false",
"x":720,
"y":100,
"wires":[
]
}
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.