Linking Vera devices to alexa, via node-red

@ElCid I just ordered some Sengled RGB bulbs from Amazon. They pair with the Vera using the Sylvania Zigbee template. They show up just like a regular Vera device. I’m sure the dimming will work with the Nodered function you created, but I’d love to be able to control the color as well through Alexa. I see the discussion above regarding RGB but tbh, it’s a little beyond me. Would you be able to modify your Function to create a properly formatted message to the Vera to manipulate the color?

Thanks!

Working on it now, not sure of time scale but will post the new function for testing when ready

Awesome! Thanks so much! :slightly_smiling_face:

Ok test this for me
the node topic is set
123#colour (for rgb dimming on/off)
or
123#colour#W100#D150 (for rgb white dimming on/off)
W and D can be 0-255 which will adjust your white temp settings.

“set light to cool white” or “set light to warm white” sets colour temp.

[{"id":"a605448.899d8b8","type":"amazon-echo-device","z":"8659fc6b.981b4","name":"bedroom four","topic":"199#colour#W100#D150","x":390,"y":960,"wires":[["688830f.c57775"]]},{"id":"688830f.c57775","type":"function","z":"8659fc6b.981b4","name":"","func":"let types = {\n    \"dimming\":[\"urn:upnp-org:serviceId:Dimming1\",\"SetLoadLevelTarget\",\"newLoadlevelTarget\"],\n    \"binary\":[\"urn:upnp-org:serviceId:SwitchPower1\",\"SetTarget\",\"newTargetValue\"],\n    \"scene\":[\"urn:micasaverde-com:serviceId:HomeAutomationGateway1\",\"RunScene\",\"SceneNum\"],\n    \"colour\":[\"urn:micasaverde-com:serviceId:Color1\",{\"tt\":\"SetColor\",\"hs\":\"SetColorRGB\",\"ct\":\"SetColorTemp\"},{\"tt\":\"newColorTarget\",\"hs\":\"newColorRGBTarget\",\"ct\":\"newColorTempTarget\"}] \t\n}\nfunction binaryPayload(device, type, turnOn, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.DeviceNum = device;\n    payload.action = type[1];\n    payload[type[2]] = (turnOn === true ? 1 : 0);\nreturn payload;\n}\n\nfunction dimmingPayload(device, type, level, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.DeviceNum = device;\n    payload.action = type[1];\n    payload[type[2]] = level;\nreturn payload;\n}\nfunction scenePayload(device, type, turnOn, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.action = type[1];\n    payload[type[2]] = (turnOn === true ? device[0] : (device[2] || device[0]));\nreturn payload;\n}\n\nfunction rgbPayload(device, types, msg, payload) { \n    if(msg.on === true && msg.meta.changes.on === false && msg.meta[\"input\"].on === true){\n        payload =  binaryPayload(device[0], types[\"binary\"], msg.on, {});\n    }else if (msg.meta.changes.percentage && msg.on === true){\n        payload = dimmingPayload(device[0], types[\"dimming\"], msg.percentage, {});\n    }else if (msg.on === true && msg.colormode === \"hs\"){\n        payload.id = \"action\";\n        payload.serviceId = types[\"colour\"][0];\n        payload.DeviceNum = device[0];\n        payload.action = types[\"colour\"][1][\"hs\"];\n        payload[types[\"colour\"][2][\"hs\"]] =   msg.rgb[0] + \",\" + msg.rgb[1] + \",\" + msg.rgb[2];   \n    }else if (msg.on === true && msg.colormode === \"ct\" && device[3]){\n        payload.id = \"action\";\n        payload.serviceId = types[\"colour\"][0];\n        payload.DeviceNum = device[0];\n        payload.action = types[\"colour\"][1][\"ct\"];\n        payload[types[\"colour\"][2][\"ct\"]] = (msg.ct < 291 ? device[3] : device[2]);// + msg.rgb[0] + \",3=\" + msg.rgb[1] + \",4=\" + msg.rgb[2];   \n    }\nreturn payload;\n}\n\nmsg.topic = msg.topic.split(\"#\").map(Function.prototype.call, String.prototype.trim);\nmsg.hold = msg.payload;\nmsg.payload = {};\nlet type = msg.topic[1] || \"binary\";\nif(msg.topic[1] === \"scene\"){\n    msg.payload = scenePayload(msg.topic, types[\"scene\"], msg.on, {});\n}else if (msg.topic[1] === \"binary\" || msg.percentage === 0 || msg.on === false){\n    msg.payload =  binaryPayload(msg.topic[0], types[\"binary\"], msg.on, {});\n}else if(msg.topic[1] ===\"dimming\"){\n    msg.payload = dimmingPayload(msg.topic[0], types[\"dimming\"], msg.percentage, {});\n}else if (msg.topic[1] === \"colour\"){\n    msg.payload = rgbPayload(msg.topic, types, msg, {});\n}\nif (Object.keys(msg.payload).length < 1){\n    msg.payload = {\n        \"id\":\"variableget\",\n        \"DeviceNum\":msg.topic[0],\n        \"serviceId\":types[msg.topic[1]][0],\n        \"Variable\":\"Status\"\n        }\n}\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":630,"y":960,"wires":[["680d28ae.8a163"]]}]

P.S This function will do dimming , binary and scenes as well.

1 Like

We should create a repo and add them to it. Easily to find than buried into a thread somewhere in the forum :wink:

My RGB bulbs won’t be in until tomorrow, but I’ll test it as soon as I get them installed.

Question, how exactly does this work? It looks like you’re including the color in the device Topic. I thought the color info comes from Alexa? If I say, “set the bedroom lamp to red”, I would expect Alexa to send the codes for red and your Function just formats them and passes them to the HTTP node. I might be missing something here.

Thanks!

Maybe i should put them on my repo, i will move this to first post once tested fully.

1 Like

Th W and D set the white colour teperature, it’s there to give easy adjustment if the white colour is off.

Oh so the word “colour” in the Topic identifies it as a colour capable device? I thought it was the actual colour you wanted to set it to. Ok, I understand now. So what happens if I say, “make the bedroom lamp warmer”. What will it do if the W/D values are present in the Topic? Will they override the “warmer” info coming from Alexa? What happens if I omit them in the Topic for a particular device?

Nothing, for now you just get “set light to warm white” or daylight/coolwhite. If you omit them then you will not get any warm or cool white. Not sure what happens if you just set to white, please report back. I have only tested on a virtual device. will probably add defaults for W/D so they can be omitted.

Ok, thanks! I’ll test it tomorrow when the bulbs come in.

Ok here is an update.
Added -
“make light warmer” or cooler.
Status report on node.
W/D default is 310, you can change it by adding #new_number to end of topic e.g 123#colour#320

[{"id":"a605448.899d8b8","type":"amazon-echo-device","z":"8659fc6b.981b4","name":"bedroom four","topic":"199#colour","x":410,"y":860,"wires":[["688830f.c57775","faff8343.c181c8"]]},{"id":"688830f.c57775","type":"function","z":"8659fc6b.981b4","name":"","func":"let types = {\n    \"dimming\":[\"urn:upnp-org:serviceId:Dimming1\",\"SetLoadLevelTarget\",\"newLoadlevelTarget\"],\n    \"binary\":[\"urn:upnp-org:serviceId:SwitchPower1\",\"SetTarget\",\"newTargetValue\"],\n    \"scene\":[\"urn:micasaverde-com:serviceId:HomeAutomationGateway1\",\"RunScene\",\"SceneNum\"],\n    \"colour\":[\"urn:micasaverde-com:serviceId:Color1\",{\"tt\":\"SetColor\",\"hs\":\"SetColorRGB\",\"ct\":\"SetColorTemp\"},{\"tt\":\"newColorTarget\",\"hs\":\"newColorRGBTarget\",\"ct\":\"newColorTempTarget\"}] \t\n}\nfunction binaryPayload(device, type, turnOn, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.DeviceNum = device;\n    payload.action = type[1];\n    payload[type[2]] = (turnOn === true ? 1 : 0);\n    payload.message = payload[type[2]];\nreturn payload;\n}\n\nfunction dimmingPayload(device, type, level, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.DeviceNum = device;\n    payload.action = type[1];\n    payload[type[2]] = level;\n    payload.message = level;\nreturn payload;\n}\nfunction scenePayload(device, type, turnOn, payload) {\n    payload.id = \"action\";\n    payload.serviceId = type[0];\n    payload.action = type[1];\n    payload[type[2]] = (turnOn === true ? device[0] : (device[2] || device[0]));\n    payload.message =\"OK\";\nreturn payload;\n}\n\nfunction rgbPayload(device, types, msg, payload) { \n    if(msg.on === true && msg.meta.changes.on === false && msg.meta[\"input\"].on === true){\n        payload =  binaryPayload(device[0], types[\"binary\"], msg.on, {});\n    }else if (msg.meta.changes.percentage && msg.on === true){\n        payload = dimmingPayload(device[0], types[\"dimming\"], msg.percentage, {});\n    }else if (msg.on === true && msg.colormode === \"hs\"){\n        payload.id = \"action\";\n        payload.serviceId = types[\"colour\"][0];\n        payload.DeviceNum = device[0];\n        payload.action = types[\"colour\"][1][\"hs\"];\n        payload[types[\"colour\"][2][\"hs\"]] =  msg.rgb.join(\",\");\n        payload.message = msg.rgb.join(\",\");\n    }else if (msg.on === true && msg.colormode === \"ct\"){\n        let diff = msg.ct - (Number(device[2]) || 310);\n        msg.ct = (diff < 0) ? \"D\" + Math.min(Math.abs(diff * 1.7),255).toFixed() : \"W\" + Math.abs(Math.min((diff * 1.7),255) - 255).toFixed();\n        payload.id = \"action\";\n        payload.serviceId = types[\"colour\"][0];\n        payload.DeviceNum = device[0];\n        payload.action = types[\"colour\"][1][\"ct\"];\n        payload[types[\"colour\"][2][\"ct\"]] = msg.ct;\n        payload.message = msg.ct;\n    }\nreturn payload;\n}\n\nmsg.topic = msg.topic.split(\"#\").map(Function.prototype.call, String.prototype.trim);\nmsg.hold = msg.payload;\nmsg.payload = {};\nlet type = msg.topic[1] || \"binary\";\nif(msg.topic[1] === \"scene\"){\n    msg.payload = scenePayload(msg.topic, types[\"scene\"], msg.on, {});\n}else if (msg.topic[1] === \"binary\" || msg.percentage === 0 || msg.on === false){\n    msg.payload =  binaryPayload(msg.topic[0], types[\"binary\"], msg.on, {});\n}else if(msg.topic[1] ===\"dimming\"){\n    msg.payload = dimmingPayload(msg.topic[0], types[\"dimming\"], msg.percentage, {});\n}else if (msg.topic[1] === \"colour\"){\n    msg.payload = rgbPayload(msg.topic, types, msg, {});\n}\nlet  error = [\"green\", msg.topic[1] + \" | \" + msg.topic[0], msg.payload.message];\ndelete msg.payload.message;\nif (Object.keys(msg.payload).length < 1){\n    error[0] =\"red\";\n    error[2] =\"failed to create payload\";\n}\nnode.status({\"fill\": error[0],\"shape\":\"ring\",\"text\": error[1] + \" | \" + error[2]});\n\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":590,"y":940,"wires":[["680d28ae.8a163"]]}]

Unfortunately, I won’t be able to test this today. The Sengled RGB bulbs aren’t compatible with the Vera. I’ve tried every template to add them and none of them work. The Sylvania template works for the white bulbs, but not the RGB ones. I’ve ordered some MagicLight WiFi bulbs which do work with a plugin on the Vera. They should be here tomorrow and hopefully I can test then. Thanks for all your hard work on this!

So, I just saw that the iOS app is sending this format:
W0,D0,R72,G255,B116

And the web UI is sending this as well (for white temperature):
W255,D150

I’ve added these formats to my Virtual RGB plugin, but frankly speaking it’s a mess.

This is the format they introduced somewhere between 4150 and 4414. And you know what’s ever better? Until 5245/6/7 they were sending the W and D values reversed (the warm intensity is on the D and the daylight is on the W, confirmed by review of the JS). That’s fixed at 5245.

oh, well. I’ll try the Android app later today, because I’m curious.

That’s from the web UI, by the way.