I’m a complete novice with node-red, I was trying to make a flow to control my light bulbs with alexa, I managed to turn them on and off, but I can not set the brightness.
I’ve managed to solve it
Hi @Superimo88. I just got Node-Red up and running myself and have the same question. The Alexa -> Node-Red -> Home-assistant workflow is still a bit niche so not many posts about it yet.
How did you get it to work? Any tips/examples gratefully received.
Cheers!
Yes, us newbies would appreciate knowing how you fixed it. I am doing it through Node-Red as well and I would like to see how others solve it.
Here’s how I control my Z-Wave light from Node-Red.
The non-standard nodes used in this flow are: Alexa Home and Home Assistant Call-Service.
[{"id":"af9657ae.fbfc18","type":"api-call-service","z":"af411996.664988","name":"Landing Light ON","server":"1a3c51f6.4b493e","service_domain":"homeassistant","service":"turn_on","data":"{\"entity_id\": \"light.landing\"}","mergecontext":"","x":950,"y":540,"wires":[[]]},{"id":"c557e1b4.0e2a5","type":"api-call-service","z":"af411996.664988","name":"Landing Light OFF","server":"1a3c51f6.4b493e","service_domain":"homeassistant","service":"turn_off","data":"{\"entity_id\": \"light.landing\"}","mergecontext":"","x":950,"y":600,"wires":[[]]},{"id":"ee739870.dfe898","type":"switch","z":"af411996.664988","name":"On-Off, or Bri?","property":"on_off_command","propertyType":"msg","rules":[{"t":"true"},{"t":"false"}],"checkall":"true","repair":true,"outputs":2,"x":480,"y":580,"wires":[["14c7dffc.85685"],["31148082.0f8df"]]},{"id":"704fb134.52d8d","type":"alexa-local","z":"af411996.664988","devicename":"Landing Light","inputtrigger":false,"x":260,"y":500,"wires":[["de86c26c.9a57d"]]},{"id":"de86c26c.9a57d","type":"range","z":"af411996.664988","minin":"0","maxin":"100","minout":"0","maxout":"255","action":"clamp","round":true,"property":"bri","name":"Map Bri 0-100 into 0-255","x":490,"y":500,"wires":[["ee739870.dfe898"]]},{"id":"14c7dffc.85685","type":"switch","z":"af411996.664988","name":"On or Off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":720,"y":580,"wires":[["af9657ae.fbfc18"],["c557e1b4.0e2a5"]]},{"id":"31148082.0f8df","type":"function","z":"af411996.664988","name":"Payload= Entity_ID and Brightness value.","func":"msg.payload = {\"data\":{\"entity_id\":\"light.landing\",\"brightness\":msg.bri}};\nreturn msg;\n","outputs":1,"noerr":0,"x":640,"y":660,"wires":[["28d69d33.c84182"]]},{"id":"28d69d33.c84182","type":"api-call-service","z":"af411996.664988","name":"Landing Light ON","server":"1a3c51f6.4b493e","service_domain":"homeassistant","service":"turn_on","data":"{}","mergecontext":"","x":950,"y":660,"wires":[[]]},{"id":"8b088378.70834","type":"switch","z":"af411996.664988","name":"on, off, or number from 0-255","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":380,"y":720,"wires":[["af9657ae.fbfc18"],["c557e1b4.0e2a5"],["7e9db5ae.8be74c"]]},{"id":"7e9db5ae.8be74c","type":"function","z":"af411996.664988","name":"Payload= Entity_ID and Brightness value.","func":"msg.payload = {\"data\":{\"entity_id\":\"light.landing\",\"brightness\":msg.payload}};\nreturn msg;\n","outputs":1,"noerr":0,"x":720,"y":740,"wires":[["28d69d33.c84182"]]},{"id":"a9752a3a.1a8138","type":"inject","z":"af411996.664988","name":"ON","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":600,"wires":[["8b088378.70834"]]},{"id":"2b2c683f.6ef4f8","type":"inject","z":"af411996.664988","name":"OFF","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":640,"wires":[["8b088378.70834"]]},{"id":"b51a8c3b.3c32e","type":"inject","z":"af411996.664988","name":"","topic":"","payload":"50","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":680,"wires":[["8b088378.70834"]]},{"id":"18e688c1.dc2e27","type":"inject","z":"af411996.664988","name":"","topic":"","payload":"10","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":720,"wires":[["8b088378.70834"]]},{"id":"1a3c51f6.4b493e","type":"server","z":"","name":"Home Assistant- Raspberry","legacy":true,"hassio":true,"rejectUnauthorizedCerts":true}]
From the Alexa Home node, the flow goes into a map node. Alexa only recognizes 0-100% for the brightness, but the light expects a value from 0-255. The map node fixes this. Next, I switch depending if the message.on_off_command is true, then Alexa heard “on” or “off”. If false, then Alexa heard a value for the brightness.
If the message is “on” or “off”, then I switch to the appropriate Home Assistant Turn_On or Turn_off nodes.
I am sure there are more elegant methods, but this works for me.
(BTW, “Landing Light” refers to the light at the top of the stairs. In the US, this is called a landing.)
@stevemann Wow! Thanks for this. I’ll import it and have a play. At this stage, ‘working’ is more important than ‘elegant’ to me - you should have seen the state of some of my early YAML!
BTW Landing light is the same in the UK
Nick.
I am a pilot, so “Landing Light” has another higher meaning to me.
What is funny is the Ikea Tradfri lights in our bedroom. One on each of our nightstands. I just named the lights for myself and my wife. So, when I was showing my work to my wife, I said. “Alexa, turn Steve on”.
Lol! That’s the easy part. The hard part is getting it to work on your wife…
I imported your example and on and off work fine.
I can see the brightness command getting sent to the light but it’s not having any effect.
I can’t see any brightness parameters getting passed (or an entity_id for that matter). Does this match yours?
I created a light-up make-up mirror for my daughter yesterday but so far she has to turn it on using a switch like a cave-person, and it’s too bright.
Cheers again for your advice
Found it! light.landing_light was buried in the function nodes. changed that to light.kizzies_mirror and it works!
Thanks again for all your help!
NIck.
This is how i’ve done.
[{"id":"788da537.8368e4","type":"tab","label":"Alexa","disabled":false,"info":""},{"id":"23d2073f.7b6a3","type":"api-call-service","z":"788da537.8368e4","name":"Set Bri","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight\"}","render_data":false,"mergecontext":"","x":716.5,"y":189,"wires":[[]]},{"id":"dfbb746.bf96688","type":"alexa-home","z":"788da537.8368e4","conf":"448f4814.7677e","device":"40893","acknoledge":true,"name":"Ailight","topic":"","x":133.5,"y":207,"wires":[["45dfb190.1ccca8"]]},{"id":"6c07067c.bc757","type":"api-call-service","z":"788da537.8368e4","name":"Turn On","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight\",\"transition\":5}","render_data":false,"mergecontext":"","x":673.5,"y":85,"wires":[[]]},{"id":"79da039f.d711cc","type":"api-call-service","z":"788da537.8368e4","name":"Turn Off","server":"b374edd7.1b1668","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.ailight\",\"transition\":5}","render_data":false,"mergecontext":"","x":701.5,"y":138,"wires":[[]]},{"id":"70123bec.0ec284","type":"api-call-service","z":"788da537.8368e4","name":"Set Color","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight\"}","render_data":false,"mergecontext":"","x":755.5,"y":241,"wires":[[]]},{"id":"8d9e91ad.071cc","type":"range","z":"788da537.8368e4","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload.saturation","name":"","x":477.5,"y":241,"wires":[["c53611d6.8fa9"]]},{"id":"45dfb190.1ccca8","type":"switch","z":"788da537.8368e4","name":"Command","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"SetColorRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":312.5,"y":147,"wires":[["fcee670a.3d5f2"],["79da039f.d711cc"],["a67ec398.d73b"],["8d9e91ad.071cc"]]},{"id":"a67ec398.d73b","type":"function","z":"788da537.8368e4","name":"Brightness","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight', brightness_pct: msg.payload }\n};\nreturn msg;","outputs":1,"noerr":0,"x":536.5,"y":173,"wires":[["23d2073f.7b6a3"]]},{"id":"c53611d6.8fa9","type":"function","z":"788da537.8368e4","name":"Color","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight', \"white_value\": 0, \"hs_color\": [msg.payload.hue,msg.payload.saturation]}\n};\nreturn msg;","outputs":1,"noerr":0,"x":616.5,"y":241,"wires":[["70123bec.0ec284"]]},{"id":"917d222d.08ad7","type":"api-call-service","z":"788da537.8368e4","name":"Set Bri","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight_1\"}","render_data":false,"mergecontext":"","x":726,"y":463,"wires":[[]]},{"id":"ac6bf1ed.a0fdd8","type":"alexa-home","z":"788da537.8368e4","conf":"448f4814.7677e","device":"41034","acknoledge":true,"name":"Ailight1","topic":"","x":143,"y":481,"wires":[["9a9afe5b.7bafa8"]]},{"id":"32fad359.c8b084","type":"api-call-service","z":"788da537.8368e4","name":"Turn On","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight_1\",\"transition\":5}","render_data":false,"mergecontext":"","x":683,"y":359,"wires":[[]]},{"id":"6e63aff7.9403b8","type":"api-call-service","z":"788da537.8368e4","name":"Turn Off","server":"b374edd7.1b1668","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.ailight_1\",\"transition\":5}","render_data":false,"mergecontext":"","x":711,"y":412,"wires":[[]]},{"id":"6ecaede8.a2205c","type":"api-call-service","z":"788da537.8368e4","name":"Set Color","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.ailight_1\"}","render_data":false,"mergecontext":"","x":765,"y":515,"wires":[[]]},{"id":"621e154.e74d06c","type":"range","z":"788da537.8368e4","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload.saturation","name":"","x":487,"y":517,"wires":[["8145b2bc.ce50c8"]]},{"id":"9a9afe5b.7bafa8","type":"switch","z":"788da537.8368e4","name":"Command","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"SetColorRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":322,"y":421,"wires":[["5d95550c.714e7c"],["6e63aff7.9403b8"],["bc9a2621.eae9d"],["621e154.e74d06c"]]},{"id":"bc9a2621.eae9d","type":"function","z":"788da537.8368e4","name":"Brightness","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight_1', brightness_pct: msg.payload }\n};\nreturn msg;","outputs":1,"noerr":0,"x":546,"y":447,"wires":[["917d222d.08ad7"]]},{"id":"8145b2bc.ce50c8","type":"function","z":"788da537.8368e4","name":"Color","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight_1', \"white_value\": 0, \"hs_color\": [msg.payload.hue,msg.payload.saturation]}\n};\nreturn msg;","outputs":1,"noerr":0,"x":628,"y":517,"wires":[["6ecaede8.a2205c"]]},{"id":"b42c4310.4dd8b8","type":"api-call-service","z":"788da537.8368e4","name":"","server":"b374edd7.1b1668","service_domain":"switch","service":"turn_on","data":"{\"entity_id\":\"switch.sonoff\"}","render_data":false,"mergecontext":"","x":601.5,"y":637,"wires":[[]]},{"id":"26e3c8b7.ec901","type":"alexa-home","z":"788da537.8368e4","conf":"448f4814.7677e","device":"41035","acknoledge":true,"name":"Sonoff","topic":"","x":135.5,"y":669,"wires":[["9bd71d6a.a673a8"]]},{"id":"9bd71d6a.a673a8","type":"switch","z":"788da537.8368e4","name":"Command","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":351,"y":662,"wires":[["b42c4310.4dd8b8"],["2d44bf84.70b92"]]},{"id":"2d44bf84.70b92","type":"api-call-service","z":"788da537.8368e4","name":"","server":"b374edd7.1b1668","service_domain":"switch","service":"turn_off","data":"{\"entity_id\":\"switch.sonoff\"}","render_data":false,"mergecontext":"","x":601,"y":686,"wires":[[]]},{"id":"a05ac4ce.3458e8","type":"api-call-service","z":"788da537.8368e4","name":"Set Bri","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.hyperion\"}","render_data":false,"mergecontext":"","x":730,"y":886,"wires":[[]]},{"id":"ffc9a8f6.c804c8","type":"alexa-home","z":"788da537.8368e4","conf":"448f4814.7677e","device":"41038","acknoledge":true,"name":"Hyperion","topic":"","x":157,"y":904,"wires":[["a29a1e4.b4b32e"]]},{"id":"f75b884c.1dd9f8","type":"api-call-service","z":"788da537.8368e4","name":"Turn On","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.hyperion\",\"transition\":5}","render_data":false,"mergecontext":"","x":687,"y":782,"wires":[[]]},{"id":"7b3ea6dc.faca7","type":"api-call-service","z":"788da537.8368e4","name":"Turn Off","server":"b374edd7.1b1668","service_domain":"light","service":"turn_off","data":"{\"entity_id\":\"light.hyperion\",\"transition\":5}","render_data":false,"mergecontext":"","x":715,"y":835,"wires":[[]]},{"id":"a9a59115.7011a8","type":"api-call-service","z":"788da537.8368e4","name":"Set Color","server":"b374edd7.1b1668","service_domain":"light","service":"turn_on","data":"{\"entity_id\":\"light.hyperion\"}","render_data":false,"mergecontext":"","x":769,"y":938,"wires":[[]]},{"id":"c0573a15.fb3528","type":"range","z":"788da537.8368e4","minin":"0","maxin":"1","minout":"0","maxout":"100","action":"scale","round":false,"property":"payload.saturation","name":"","x":491,"y":940,"wires":[["23701f84.3b37e8"]]},{"id":"a29a1e4.b4b32e","type":"switch","z":"788da537.8368e4","name":"Command","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"SetColorRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":326,"y":844,"wires":[["f75b884c.1dd9f8"],["7b3ea6dc.faca7"],["1c1cec5d.f9066c"],["c0573a15.fb3528"]]},{"id":"1c1cec5d.f9066c","type":"function","z":"788da537.8368e4","name":"Brightness","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.hyperion', brightness_pct: msg.payload }\n};\nreturn msg;","outputs":1,"noerr":0,"x":550,"y":870,"wires":[["a05ac4ce.3458e8"]]},{"id":"23701f84.3b37e8","type":"function","z":"788da537.8368e4","name":"Color","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.hyperion', \"hs_color\": [msg.payload.hue,msg.payload.saturation]}\n};\nreturn msg;","outputs":1,"noerr":0,"x":632,"y":940,"wires":[["a9a59115.7011a8"]]},{"id":"fcee670a.3d5f2","type":"function","z":"788da537.8368e4","name":"Withe on","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight', \"white_value\": 255}\n};\nreturn msg;","outputs":1,"noerr":0,"x":531.5,"y":84,"wires":[["6c07067c.bc757"]]},{"id":"5d95550c.714e7c","type":"function","z":"788da537.8368e4","name":"Withe on","func":"msg.payload = {\n domain: 'light',\n service: 'turn_on',\n data: { entity_id: 'light.ailight_1', \"white_value\": 255}\n};\nreturn msg;","outputs":1,"noerr":0,"x":537,"y":358,"wires":[["32fad359.c8b084"]]},{"id":"b374edd7.1b1668","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":false,"rejectUnauthorizedCerts":false},{"id":"448f4814.7677e","type":"alexa-home-conf","z":"","username":"USRNAME"}]
How did you get Alexa Home to respond to color?
I couldn’t import your flow because it contains hundreds of “enhanced” quotes and single quotes. The forum editor converts simple quotes to grammatically correct open and close quotes, but they don’t work in code.
“id”
should be
"id"
Try putting it in the </> code blocks.
Steve
I’ve edited the post above.
Putting this here in case others might find this helpful, I am not a developer and I play with HA as a hobby, so I am sure there are lots of issues with my code but it works great and simplified my alexa intergration a lot.
Firstly I use the following for local control of alexa… I cant recommend it enough as its super simple and works great: node-red-contrib-alexa-home.
Secondly I have a number of ikea lights that need to be controlled via the “light” service and I have a number of lights that are controlled by a “switch” meaning I have to use the switch service, hence the need for a domain in the array. I have a total of about 26 lights and devices that i use this node to control on and off and brightness… (ps…you could use the same code for RGB colour as well as color temp just change to your needs, you just need to add the “data:” to include the colour stuff)
Here is the code snippet:
[
{
"id": "6a02514571fc69b4",
"type": "tab",
"label": "Flow 4",
"disabled": false,
"info": "",
"env": []
},
{
"id": "9c2a40e48fba63ab",
"type": "function",
"z": "6a02514571fc69b4",
"name": "All in One",
"func": "var array = [\n {\n \"device_name\": \"Office Light\",\n \"entity_id\": \"light.office_light\",\n \"domain\": \"light\"\n },\n {\n \"device_name\": \"Lounge Light\",\n \"entity_id\": \"switch.lounge_light\",\n \"domain\": \"switch\"\n }\n];\nvar property = \"device_name\" ? \"device_name\": msg.device_name\nvar condition = msg.device_name\n\n\nvar newPayload=\"\"\narray.forEach(element => {\n if(element[property] === condition){\n newPayload = element\n \n }\n});\nif (msg.payload.on === true){\n if (msg.payload.command === \"switch\") {\n msg.payload = {\n domain: newPayload.domain,\n service: \"turn_on\",\n data: { entity_id: newPayload.entity_id }\n }\n }\n else if (newPayload.domain === \"light\"){\n msg.payload = {\n domain: newPayload.domain,\n service: \"turn_on\",\n data: { entity_id: newPayload.entity_id, \"brightness_pct\": msg.payload.bri_normalized }\n }\n }\n else {\n msg.payload = {\n domain: newPayload.domain,\n service: \"turn_on\",\n data: { entity_id: newPayload.entity_id }\n } \n \n }\n\n\n}\nelse{\n msg.payload = {\n domain: newPayload.domain,\n service: \"turn_off\",\n data: { entity_id: newPayload.entity_id }\n }\n} \n \nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 320,
"y": 260,
"wires": [
[
"501a8ec42d1131fc"
]
]
},
{
"id": "b50ed7d589487166",
"type": "debug",
"z": "6a02514571fc69b4",
"name": "debug 1",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "true",
"targetType": "full",
"statusVal": "",
"statusType": "auto",
"x": 480,
"y": 340,
"wires": []
},
{
"id": "2506d432f070a598",
"type": "alexa-home",
"z": "6a02514571fc69b4",
"devicename": "Office Light",
"devicetype": "Dimmable light",
"x": 110,
"y": 200,
"wires": [
[
"9c2a40e48fba63ab"
]
]
},
{
"id": "501a8ec42d1131fc",
"type": "api-call-service",
"z": "6a02514571fc69b4",
"name": "Magic Button",
"server": "cbb458bc.e8ad88",
"version": 5,
"debugenabled": false,
"domain": "",
"service": "",
"areaId": [],
"deviceId": [],
"entityId": [],
"data": "",
"dataType": "jsonata",
"mergeContext": "",
"mustacheAltTags": false,
"outputProperties": [],
"queue": "none",
"x": 490,
"y": 260,
"wires": [
[
"b50ed7d589487166"
]
]
},
{
"id": "2f4454da14a77594",
"type": "alexa-home",
"z": "6a02514571fc69b4",
"devicename": "Lounge Light",
"devicetype": "Dimmable light",
"x": 110,
"y": 260,
"wires": [
[
"9c2a40e48fba63ab"
]
]
},
{
"id": "c78afde5c61dee0d",
"type": "alexa-home-controller",
"z": "6a02514571fc69b4",
"controllername": "Alexa Controller",
"useNode": false,
"port": 80,
"maxItems": -1,
"x": 130,
"y": 140,
"wires": []
},
{
"id": "cbb458bc.e8ad88",
"type": "server",
"name": "Home Assistant",
"version": 5,
"addon": true,
"rejectUnauthorizedCerts": true,
"ha_boolean": "y|yes|true|on|home|open",
"connectionDelay": true,
"cacheJson": true,
"heartbeat": false,
"heartbeatInterval": 30,
"areaSelector": "friendlyName",
"deviceSelector": "friendlyName",
"entitySelector": "friendlyName",
"statusSeparator": "at: ",
"statusYear": "hidden",
"statusMonth": "short",
"statusDay": "numeric",
"statusHourCycle": "h23",
"statusTimeFormat": "h:m",
"enableGlobalContextStore": true
}
]