Node Red Room aware Alexa voice commands

Previous post became obsolete, this method is working as of 04/07/2021

7/7/2021 - Both node-red-contrib-alexa-remote2-applestrudel and Alexa Media Player seem to have problems getting Alexa events consistently. It’s not terrible, but maybe 1 out of 10 times the “Currently listening device” flow won’t do its job. It’s not a problem of the flow itself, those issues will be resolved at some point with updates for those two components

With Alexa Media Player

  • You need to create an input_boolean.room_aware.
  • You need to have Alexa Media Player component installed.
  • You will need node-red-contrib-amazon-echo.

Currently listening device

This flow gets the currently listening device and stores it in a flow variable.

[{"id":"a68fa6c.573dd58","type":"comment","z":"877467b7.3b2fb8","name":"Setting currently listening device","info":"","x":1570,"y":100,"wires":[]},{"id":"ae2bdde6.40c2d","type":"api-call-service","z":"877467b7.3b2fb8","name":"input on","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","entityId":"input_boolean.room_aware","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2080,"y":200,"wires":[["5ac29017.2a519"]]},{"id":"346e8b21.278eb4","type":"api-call-service","z":"877467b7.3b2fb8","name":"input off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.room_aware","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2280,"y":200,"wires":[[]]},{"id":"65eeb9ff.f15568","type":"change","z":"877467b7.3b2fb8","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1975,"y":200,"wires":[["ae2bdde6.40c2d"]],"l":false},{"id":"5ac29017.2a519","type":"trigger","z":"877467b7.3b2fb8","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":2175,"y":200,"wires":[["346e8b21.278eb4"]],"l":false},{"id":"27051631.2b3b9a","type":"server-events","z":"877467b7.3b2fb8","name":"Alexa media player","server":"9405c3fe.d0a6c","event_type":"state_changed","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"x":1530,"y":200,"wires":[["c5030371.c4747"]]},{"id":"c5030371.c4747","type":"switch","z":"877467b7.3b2fb8","name":"","property":"payload.event.new_state.attributes.last_called","propertyType":"msg","rules":[{"t":"true"}],"checkall":"true","repair":false,"outputs":1,"x":1675,"y":200,"wires":[["6bc78314.18073c"]],"l":false},{"id":"6bc78314.18073c","type":"change","z":"877467b7.3b2fb8","name":"Set Echo you're talking to","rules":[{"t":"set","p":"echodevice","pt":"flow","to":"payload.event.new_state.attributes.friendly_name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1830,"y":200,"wires":[["65eeb9ff.f15568"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

It works better than using the yaml based last called sensor as a condition since the input boolean allows the other flows to continue when and only when the last called device has been surely retrieved. Something similar could be achieved with a yaml automation though. It’s very hard, if not impossible, to run into false positives, like lights from other rooms turning on by mistake due to the last called sensor not updating fast enough.

Just copy and paste this part and put it in the same board/flow as the next part.

Room aware lights

[{"id":"401c9a3e.0b2e34","type":"link in","z":"877467b7.3b2fb8","name":"Amazon Echo Hub in","links":["61cde6c.c6ddf18"],"x":95,"y":740,"wires":[["fbab8f8.37d637","990d39ad.bd6c28"]]},{"id":"fbab8f8.37d637","type":"amazon-echo-device","z":"877467b7.3b2fb8","name":"La luz","topic":"","x":190,"y":720,"wires":[["707cfe18.c0ef"]]},{"id":"990d39ad.bd6c28","type":"amazon-echo-device","z":"877467b7.3b2fb8","name":"Luz","topic":"","x":190,"y":760,"wires":[["707cfe18.c0ef"]]},{"id":"8fb91032.8dfb1","type":"ha-wait-until","z":"877467b7.3b2fb8","name":"","server":"9405c3fe.d0a6c","outputs":2,"entityId":"input_boolean.room_aware","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"10","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":335,"y":740,"wires":[["e15e9fef.f41b7","173d7bed.7a57a4"],[]],"l":false},{"id":"e15e9fef.f41b7","type":"api-call-service","z":"877467b7.3b2fb8","name":"input off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.room_aware","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":340,"y":680,"wires":[[]]},{"id":"707cfe18.c0ef","type":"trigger","z":"877467b7.3b2fb8","name":"","op1":"","op2":"","op1type":"nul","op2type":"payl","duration":"150","extend":true,"overrideDelay":false,"units":"ms","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":275,"y":740,"wires":[["8fb91032.8dfb1"]],"l":false},{"id":"27b89df.7955a62","type":"change","z":"877467b7.3b2fb8","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"},{"t":"change","p":"meta.input.on","pt":"msg","from":"true","fromt":"bool","to":"turn_on","tot":"str"},{"t":"change","p":"meta.input.on","pt":"msg","from":"false","fromt":"bool","to":"turn_off","tot":"str"},{"t":"set","p":"service","pt":"msg","to":"meta.input.on","tot":"msg"},{"t":"change","p":"meta.input.hue","pt":"msg","from":"meta.input.hue","fromt":"msg","to":"rgb","tot":"msg"},{"t":"set","p":"payload.data.rgb_color","pt":"msg","to":"meta.input.hue","tot":"msg"},{"t":"change","p":"meta.input.ct","pt":"msg","from":"meta.input.ct","fromt":"msg","to":"ct","tot":"msg"},{"t":"set","p":"payload.data.color_temp","pt":"msg","to":"$number(meta.input.ct) - 34","tot":"jsonata"},{"t":"change","p":"meta.input.bri","pt":"msg","from":"meta.input.bri","fromt":"msg","to":"percentage","tot":"msg"},{"t":"set","p":"payload.data.brightness_pct","pt":"msg","to":"meta.input.bri","tot":"msg"},{"t":"set","p":"payload.data.transition","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":600,"y":740,"wires":[["6ecb103a.29f2e"]]},{"id":"6ecb103a.29f2e","type":"api-call-service","z":"877467b7.3b2fb8","name":"Light","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"light","service":"{{service}}","entityId":"{{entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":750,"y":740,"wires":[[]]},{"id":"cff52c1.92fb6d","type":"comment","z":"877467b7.3b2fb8","name":"Lights","info":"","x":130,"y":600,"wires":[]},{"id":"173d7bed.7a57a4","type":"change","z":"877467b7.3b2fb8","name":"Set entity","rules":[{"t":"set","p":"entity_id","pt":"msg","to":"echodevice","tot":"flow"},{"t":"change","p":"entity_id","pt":"msg","from":"Echo device 1","fromt":"str","to":"light.light_1","tot":"str"},{"t":"change","p":"entity_id","pt":"msg","from":"Echo device 2","fromt":"str","to":"light.light_2, light.light_3","tot":"str"},{"t":"change","p":"entity_id","pt":"msg","from":"Echo device 3","fromt":"str","to":"light.light_4","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":740,"wires":[["27b89df.7955a62"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

This is an example with lights. You should create two devices with node-red-contrib-amazon-echo, light & the light (and even lights and the lights if you use them) as creating all of them increases compatibility.

Under Set entity, set your entity or comma sepparated string of entities related to each echo device. Echo devices should be typed exactly as they show up in your Alexa app.

Done! It should be working by now, you needn’t do anything else

You can change the transition whithin the later change node, you can find it in the bottom of the list.

-----------------------------------------------------------------------------------------------------------------------------------------

You should use node-red-contrib-alexa-remote2-applestrudel for the first section, cakebaked is obsolete

If you preffer it:

[{"id":"ee3c5fed.ec2e1","type":"alexa-remote-event","z":"877467b7.3b2fb8","name":"On device activity","account":"7c02d978.c2de98","event":"ws-device-activity","x":180,"y":240,"wires":[["85e53f62.7a3eb"]]},{"id":"4ac2d190.b7afa","type":"change","z":"877467b7.3b2fb8","name":"Set Echo you're talking to","rules":[{"t":"set","p":"echoDeviceSerial","pt":"global","to":"payload.deviceSerialNumber","tot":"msg"},{"t":"set","p":"echodevice","pt":"global","to":"payload.name","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":590,"y":240,"wires":[["33080b5e.c00114"]]},{"id":"aa7c9bb4.102938","type":"api-call-service","z":"877467b7.3b2fb8","name":"input on","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_on","areaId":[],"deviceId":[],"entityId":["input_boolean.room_aware"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":840,"y":240,"wires":[["972b78be.7156a8"]]},{"id":"51080f6c.28cb3","type":"api-call-service","z":"877467b7.3b2fb8","name":"input off","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"homeassistant","service":"turn_off","areaId":[],"deviceId":[],"entityId":["input_boolean.room_aware"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1060,"y":240,"wires":[[]]},{"id":"33080b5e.c00114","type":"change","z":"877467b7.3b2fb8","name":"","rules":[{"t":"delete","p":"payload","pt":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":735,"y":240,"wires":[["aa7c9bb4.102938"]],"l":false},{"id":"972b78be.7156a8","type":"trigger","z":"877467b7.3b2fb8","name":"","op1":"","op2":"0","op1type":"nul","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":935,"y":240,"wires":[["51080f6c.28cb3"]],"l":false},{"id":"85e53f62.7a3eb","type":"switch","z":"877467b7.3b2fb8","name":"","property":"payload.data.utteranceType","propertyType":"msg","rules":[{"t":"eq","v":"GENERAL","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":355,"y":240,"wires":[["4ac2d190.b7afa"]],"l":false},{"id":"7c02d978.c2de98","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.1.29","proxyPort":"1234","cookieFile":"/config/.storage/authentication","refreshInterval":"3","alexaServiceHost":"alexa.amazon.es","pushDispatchHost":"","amazonPage":"amazon.es","acceptLanguage":"es-ES","onKeywordInLanguage":"on","userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/15.5 Safari/605.1.15","usePushConnection":"on","autoInit":"on"},{"id":"9405c3fe.d0a6c","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}]

-----------------------------------------------------------------------------------------------------------------------------------------

You can more easily integrate other types of devices using node-red-contrib-alexa-home-skill

EXAMPLE WITH FANS.

This one could easily be done with the other too

[{"id":"d24786c2.2b4078","type":"ha-wait-until","z":"7fd466a.0d41e98","name":"","server":"9405c3fe.d0a6c","outputs":2,"entityId":"input_boolean.room_aware","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"7","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":155,"y":360,"wires":[["5e8b78b5.d8bcb8","ac4bf641.625088"],[]],"l":false},{"id":"5e8b78b5.d8bcb8","type":"api-call-service","z":"7fd466a.0d41e98","name":"input off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.room_aware","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":240,"y":300,"wires":[[]]},{"id":"ac4bf641.625088","type":"switch","z":"7fd466a.0d41e98","name":"Echo Device?","property":"echodevice","propertyType":"flow","rules":[{"t":"eq","v":"Echo Dot","vt":"str"},{"t":"eq","v":"Your second echo device","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":340,"y":360,"wires":[["1a625271.e3916e"],["e9e83113.14e01"]]},{"id":"8e574cf9.a11f3","type":"switch","z":"7fd466a.0d41e98","name":"Action?","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"SetPercentageRequest","vt":"str"},{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"IncrementPercentageRequest","vt":"str"},{"t":"eq","v":"DecrementPercentageRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":5,"x":580,"y":360,"wires":[["65b4f64a.d1d5b8"],["14703901.766ae7"],["13ac203c.68ec6"],["7e5a04cb.9a9f2c"],["9e782d2e.9e2bd"]]},{"id":"1a625271.e3916e","type":"change","z":"7fd466a.0d41e98","name":"","rules":[{"t":"set","p":"fan_entity_id","pt":"flow","to":"fan.fan1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":340,"wires":[["8e574cf9.a11f3"]],"l":false},{"id":"14703901.766ae7","type":"api-call-service","z":"7fd466a.0d41e98","name":"Turn on","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fan_speed","data":"{\"value\": \"1.0\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":400,"wires":[[]]},{"id":"13ac203c.68ec6","type":"api-call-service","z":"7fd466a.0d41e98","name":"Turn off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fan_speed","data":"{\"value\": \"0.0\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":440,"wires":[[]]},{"id":"a7c20b40.946118","type":"api-call-service","z":"7fd466a.0d41e98","name":"Increment","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"input_number","service":"increment","entityId":"input_number.fan_speed","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":480,"wires":[[]]},{"id":"e8be74b9.b74d38","type":"api-call-service","z":"7fd466a.0d41e98","name":"Decrement","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"input_number","service":"decrement","entityId":"input_number.fan_speed","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":850,"y":560,"wires":[[]]},{"id":"af5a9dc0.9e30d","type":"api-call-service","z":"7fd466a.0d41e98","name":"Set","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"input_number","service":"set_value","entityId":"input_number.fan_speed","data":"{\"value\": \"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":950,"y":300,"wires":[[]]},{"id":"f0fcb16e.3ffae","type":"server-state-changed","z":"7fd466a.0d41e98","name":"Input number","server":"9405c3fe.d0a6c","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"input_number.fan_speed","entityidfiltertype":"exact","outputinitially":false,"state_type":"num","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":1150,"y":380,"wires":[["f844bb4f.cd2b58"]]},{"id":"f844bb4f.cd2b58","type":"switch","z":"7fd466a.0d41e98","name":"Speed","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"0.0","vt":"str"},{"t":"eq","v":"1.0","vt":"str"},{"t":"eq","v":"2.0","vt":"str"},{"t":"eq","v":"3.0","vt":"str"}],"checkall":"true","repair":false,"outputs":4,"x":1300,"y":380,"wires":[["1b08a13.0f5815f"],["5771095d.b318e8"],["c9d0473e.5a0db8"],["a9472270.22ffb"]]},{"id":"1b08a13.0f5815f","type":"api-call-service","z":"7fd466a.0d41e98","name":"Turn off fan","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"{{flow.fan_entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1470,"y":320,"wires":[[]]},{"id":"5771095d.b318e8","type":"api-call-service","z":"7fd466a.0d41e98","name":"Fan to low","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"{{flow.fan_entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1470,"y":360,"wires":[[]]},{"id":"c9d0473e.5a0db8","type":"api-call-service","z":"7fd466a.0d41e98","name":"Fan to medium","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"{{flow.fan_entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1480,"y":400,"wires":[[]]},{"id":"a9472270.22ffb","type":"api-call-service","z":"7fd466a.0d41e98","name":"Fan to high","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"","service":"","entityId":"{{flow.fan_entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1470,"y":440,"wires":[[]]},{"id":"e9e83113.14e01","type":"change","z":"7fd466a.0d41e98","name":"","rules":[{"t":"set","p":"fan_entity_id","pt":"flow","to":"fan.fan2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":380,"wires":[["8e574cf9.a11f3"]],"l":false},{"id":"65b4f64a.d1d5b8","type":"switch","z":"7fd466a.0d41e98","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"10","vt":"num"},{"t":"eq","v":"50","vt":"num"},{"t":"eq","v":"100","vt":"num"},{"t":"eq","v":"0","vt":"str"},{"t":"eq","v":"1","vt":"str"},{"t":"eq","v":"2","vt":"str"},{"t":"eq","v":"3","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":8,"x":735,"y":280,"wires":[["1f92e528.7d35ab"],["b6a40d99.4da3b"],["ad727808.dc1588"],["af5a9dc0.9e30d"],["af5a9dc0.9e30d"],["af5a9dc0.9e30d"],["af5a9dc0.9e30d"],["58b1adfd.85ae74"]],"l":false},{"id":"1f92e528.7d35ab","type":"change","z":"7fd466a.0d41e98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":815,"y":180,"wires":[["af5a9dc0.9e30d"]],"l":false},{"id":"b6a40d99.4da3b","type":"change","z":"7fd466a.0d41e98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"2","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":815,"y":220,"wires":[["af5a9dc0.9e30d"]],"l":false},{"id":"ad727808.dc1588","type":"change","z":"7fd466a.0d41e98","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"3","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":815,"y":260,"wires":[["af5a9dc0.9e30d"]],"l":false},{"id":"7e5a04cb.9a9f2c","type":"api-current-state","z":"7fd466a.0d41e98","name":"","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"2","halt_if_type":"num","halt_if_compare":"lte","override_topic":false,"entity_id":"input_number.fan_speed","state_type":"num","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":735,"y":500,"wires":[["a7c20b40.946118"],["773c7f48.b1978"]],"l":false},{"id":"773c7f48.b1978","type":"alexa-remote-routine","z":"7fd466a.0d41e98","name":"Error max","account":"85bd714f.ef94d","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"Fan is already set to high"},"devices":{"type":"flow","value":"echoDeviceSerial"}}},"x":840,"y":520,"wires":[[]]},{"id":"9e782d2e.9e2bd","type":"api-current-state","z":"7fd466a.0d41e98","name":"","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"2","halt_if_type":"num","halt_if_compare":"gte","override_topic":false,"entity_id":"input_number.fan_speed","state_type":"num","state_location":"","override_payload":"none","entity_location":"","override_data":"none","blockInputOverrides":false,"x":735,"y":580,"wires":[["e8be74b9.b74d38"],["38a6e3a4.8ce39c"]],"l":false},{"id":"38a6e3a4.8ce39c","type":"alexa-remote-routine","z":"7fd466a.0d41e98","name":"Error min","account":"85bd714f.ef94d","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"Fan is already set to low"},"devices":{"type":"flow","value":"echoDeviceSerial"}}},"x":840,"y":600,"wires":[[]]},{"id":"58b1adfd.85ae74","type":"alexa-remote-routine","z":"7fd466a.0d41e98","name":"Error","account":"85bd714f.ef94d","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"Fan doesn't operate under this parameter"},"devices":{"type":"flow","value":"echoDeviceSerial"}}},"x":830,"y":340,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true},{"id":"85bd714f.ef94d","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"3","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.es","acceptLanguage":"","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

-----------------------------------------------------------------------------------------------------------------------------------------

EXAMPLE WITH THERMOSTAT.

[{"id":"5ff3cc29.ad7c04","type":"comment","z":"5701b8c7.b4f238","name":"Thermostat example","info":"","x":150,"y":260,"wires":[]},{"id":"ae3dd514.a53828","type":"switch","z":"5701b8c7.b4f238","name":"Echo Device?","property":"echodevice","propertyType":"flow","rules":[{"t":"eq","v":"First Echo Device","vt":"str"},{"t":"eq","v":"Second Echo Device","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":600,"y":380,"wires":[["53c34aa7.c4ca24"],["c146961e.7d4a48"]]},{"id":"35d04e69.baf142","type":"switch","z":"5701b8c7.b4f238","name":"Action?","property":"command","propertyType":"msg","rules":[{"t":"eq","v":"TurnOnRequest","vt":"str"},{"t":"eq","v":"TurnOffRequest","vt":"str"},{"t":"eq","v":"SetTargetTemperatureRequest","vt":"str"},{"t":"eq","v":"IncrementTargetTemperatureRequest","vt":"str"},{"t":"eq","v":"DecrementTargetTemperatureRequest","vt":"str"},{"t":"eq","v":"GetTemperatureReadingRequest","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":880,"y":380,"wires":[["40f34c09.465034"],["71f4af2b.79088"],["54ae0cad.eedd44"],["76a4c33a.7bad1c"],["76a4c33a.7bad1c"],["e7562823.136188"]],"outputLabels":["On","Off","Set","Increment","Decrement","Get temperature"]},{"id":"53c34aa7.c4ca24","type":"change","z":"5701b8c7.b4f238","name":"","rules":[{"t":"set","p":"entity_id","pt":"msg","to":"Climate device entity related to first Echo device","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":735,"y":360,"wires":[["35d04e69.baf142"]],"l":false},{"id":"c146961e.7d4a48","type":"change","z":"5701b8c7.b4f238","name":"","rules":[{"t":"set","p":"entity_id","pt":"msg","to":"Climate device entity related to second Echo device","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":735,"y":400,"wires":[["35d04e69.baf142"]],"l":false},{"id":"38dae152.1018ce","type":"ha-wait-until","z":"5701b8c7.b4f238","name":"","server":"9405c3fe.d0a6c","outputs":2,"entityId":"input_boolean.your_input","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"7","timeoutType":"num","timeoutUnits":"seconds","entityLocation":"","entityLocationType":"none","checkCurrentState":true,"blockInputOverrides":true,"x":235,"y":380,"wires":[["9f8c8be7.b582c8","3204e684.0d4daa"],[]],"l":false},{"id":"9f8c8be7.b582c8","type":"api-call-service","z":"5701b8c7.b4f238","name":"input off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","entityId":"input_boolean.your_input","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":320,"y":320,"wires":[[]]},{"id":"40f34c09.465034","type":"api-call-service","z":"5701b8c7.b4f238","name":"On","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_on","entityId":"{{entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1190,"y":280,"wires":[["191b3b50.76cf05"]]},{"id":"71f4af2b.79088","type":"api-call-service","z":"5701b8c7.b4f238","name":"Off","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"climate","service":"turn_off","entityId":"{{entity_id}}","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1190,"y":320,"wires":[["191b3b50.76cf05"]]},{"id":"54ae0cad.eedd44","type":"api-call-service","z":"5701b8c7.b4f238","name":"Set temp","server":"9405c3fe.d0a6c","version":1,"debugenabled":false,"service_domain":"climate","service":"set_temperature","entityId":"{{entity_id}}","data":"{\"temperature\":\"{{payload}}\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1200,"y":360,"wires":[["795bd974.53ec38"]]},{"id":"df8aff82.fcdbb","type":"alexa-home-resp","z":"5701b8c7.b4f238","x":1500,"y":440,"wires":[]},{"id":"191b3b50.76cf05","type":"change","z":"5701b8c7.b4f238","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1295,"y":300,"wires":[["df8aff82.fcdbb"]],"l":false},{"id":"795bd974.53ec38","type":"function","z":"5701b8c7.b4f238","name":"","func":"if (msg.payload < msg.min || msg.payload > msg.max) {\n    var range = {\n        min: msg.min,\n        max: msg.max\n    }\n    msg.payload = false;\n    msg.extra = range;\n    \n\n} else {\n    msg.extra = {\n        targetTemperature: {\n            value: msg.payload\n        }\n    };\n    msg.payload = true;\n}\n    \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1295,"y":360,"wires":[["df8aff82.fcdbb"]],"l":false},{"id":"76a4c33a.7bad1c","type":"api-current-state","z":"5701b8c7.b4f238","name":"","server":"9405c3fe.d0a6c","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"{{entity_id}}","state_type":"str","state_location":"climate","override_payload":"msg","entity_location":"climateData","override_data":"msg","blockInputOverrides":false,"x":1035,"y":400,"wires":[["5c880bc6.0dd234"]],"l":false},{"id":"5c880bc6.0dd234","type":"change","z":"5701b8c7.b4f238","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$number(msg.climateData.attributes.temperature) + $number(msg.payload)","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":1095,"y":400,"wires":[["54ae0cad.eedd44"]],"l":false},{"id":"27886eb0.d6df82","type":"function","z":"5701b8c7.b4f238","name":"","func":"msg.extra = {\n    \"temperatureReading\": {\n        \"value\": msg.climateData.attributes.current_temperature\n    },\n    \"applianceResponseTimestamp\": new Date().toISOString()\n};\nmsg.payload = true;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1095,"y":440,"wires":[["df8aff82.fcdbb"]],"l":false},{"id":"e7562823.136188","type":"api-current-state","z":"5701b8c7.b4f238","name":"","server":"9405c3fe.d0a6c","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"{{entity_id}}","state_type":"str","state_location":"climate","override_payload":"msg","entity_location":"climateData","override_data":"msg","blockInputOverrides":false,"x":1035,"y":440,"wires":[["27886eb0.d6df82"]],"l":false},{"id":"3204e684.0d4daa","type":"change","z":"5701b8c7.b4f238","name":"min & max","rules":[{"t":"set","p":"min","pt":"msg","to":"5.0","tot":"num"},{"t":"set","p":"max","pt":"msg","to":"25.0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":410,"y":380,"wires":[["ae3dd514.a53828"]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]

Disable “Auto Acknowledge” from your device node.
Fill input nodes with your input.
Fill “min & max” node with your device’s minimum and maximum working temperatures.
Fill “Echo Device?” node with your Echo devices
Fill the subsequent nodes with your entities related to each Echo device

-----------------------------------------------------------------------------------------------------------------------------------------

Other great alternative for creating virtual devices

node-red-contrib-virtual-smart-home

Only 7 virtual devices allowed in its free mode. 1€ a month for the PRO plan. It does support a great number devices to chose among though:

  • Blinds
  • Color Changing Light Bulb
  • Contact Sensor
  • Dimmable Light Bulb
  • Dimmer Switch
  • Entertainment Device
  • Fan
  • Garage Door Opener (en-US locale only)
  • Lock
  • Motion Sensor
  • Plug
  • Switch
  • Scene
  • Temperature Sensor
  • Thermostat

-----------------------------------------------------------------------------------------------------------------------------------------

Other ideas

You can even say “Alexa, turn on Eurosport” and get the propper broadlink/TV to act .

You can request “Alexa, what’s the humidity?” and get alexa to respond with the humidity value of the area you are in through the device you made your request.

“Alexa, turn off the room”

“Alexa, close the shutter”

“Alexa, set the shutter to 35%”

etc etc

Just get rid of naming the area of the device you want to interact with like “Alexa, close the shutter of the living room”, the flow does the work for you.

This is just what I’m looking for! Unfortunately I know nothing about Node-Red but this project is giving the motivation to dive in. I have a couple quick questions, I have several bedrooms with a ceiling fan that I currently have routines setup for in Alexa. Unfortunately it doesn’t pass the “Guest Test” when someone comes over and just says: Alexa, turn the fan on. Your solution would allow me to create identical flows and turn on the appropriate devices based on the room/alexa they are talking to. I tried creating groups in the Alexa app but I’ve never been able to get them functioning the way I hoped.

You mention that an input_boolean needs to be created. Do I need a separate boolean for every flow?

I know I’ll have a lot more questions over the next couple days as I attempt to get this working and dabble in Node-Red. Thanks again!

Does this not replicate the Alexa app grouping features (turn on lights turns on lights for the group that device is in?)

Some say it does, some others say it doesn’t. For lights it does work, but not for every device… What if you want to say “Alexa, turn off the room”?, being “the room” the one where you’re in at that moment. Or what if you had a broadlink in every room with a tv and would like to be able to say, “Alexa, turn on Eurosport”, expecting the appropriate Broadlink to act?

For lights it does work, however, if you manage to get it to work with, for example, fans, please post it because several people are after this feature.

1 Like

Just dive in Node Red, you won’t regret it. Not only for this, you’ll very likely end up moving several of your automations to Node Red, and it is begginers proof. Ask as much as you like, I’ll help if I can, no problem with that.

You’ll need just one input boolean for them all, repeat the same pattern right after every device (wait until + turn off)

1 Like

I copied from this thread to create room aware alexa commands
https://community.home-assistant.io/t/approaches-to-room-aware-voice-commands-for-alexa-with-node-red/165399

His example is for fans. I use it for lights, but no reason it won’t work for fans.
I’ll take a look at this logic when I’m at home tonight, curious how it works and what the differences are.

@randytsuch that’s a beautiful approach. By looking at it I believe the results might be very similar. He creates a device Fan to avoid Alexa complaining about not finding such device and analyzes the summary with regex filters. Thanks for sharing.

His device ‘Fan’ doesn’t depend on the cloud, which is great. Mine is apparently more compact, and I’m not sure how regex works so I can’t really tell whether the available request sentences you can use are more flexible in my flow or equally flexible.

Ok well that didn’t take long…I have the flow deployed and listening is working, but the Alexa Home node shows disconnected. I tried putting my Alexa login and password in the account but that didn’t seem to work? What am I missing

cap2

Try restarting Node Red under Supervisor/Dashboard/Node-Red/restart.

If it still isn’t working… have you followed the instructions here?:

https://alexa-node-red.bm.hardill.me.uk/docs

try following everything from the beginning step by step. That shouldn’t be too difficult, perhaps you missed something

This is correct and to add to this click the pencil icon on the wrong Alexa Account and then “Delete” so you clean it up and remove it

Bah. This requires you to sign up for an account with a third party website.

check out that one, you might like it more

Surely there is a reason you are using this third party service? Similarly, perhaps you know why is it required that if I do not use the Alexa Other node and use other builtin HA nodes I need to clear the payload so as to not create API errors (e.g. extra keys in ‘data’ - ‘_disambiguationId’)?

I use it because it has great flexibility with the sentences you can use to make requests and when you send a, for example, set% request it creates an entirely different message than when you make a turn on request, so it’s really easy to work with. Other nodes when you send a “turn on” command with Alexa, they send the turn on attribute plus all the color, percentage, etc… attributes from the last state, which makes it more difficult to work with. One clear example is the Room Aware setup from the guy from post above. He was aware of this issue so he ended up regexing everything in order to achieve this goal, and I believe that even that way, it’s not as flexible as the Alexa Home node.

I dunno why you are reluctant to use a third party integration, all I can say about this one is that I’ve been using it for a year now and it’s been down maybe a few hours a couple of times during this period. No big deal.

Regarding the API error, I don’t know why it happens, but as you said, deleting the payload solves the issue. That ‘_disambiguationId’ is located in the original message, perhaps you could solve it by just deleting that attribute and not the entire payload

I’m not against it so much as trying to understand the compelling reasons away from trying to stay as natively as possible - also sending my requests to another 3rd party like you said is a dependency but also raises some privacy concerns a bit although I’m a pretty boring person to look in on :wink:

heheheee… checking out zkniebel approach you can read what happens from the section "Overall Cons:" in his thread and down. They’ve been tinkering to get it to work. That one’s Cons is this one’s Pros and the other way around too…

Me pretty boring too :smiley:

Ok, I think I’ve made some progress on getting the initial setup completed on my system. I’ve created an account and device on the Alexa Home Skill Bridge website and linked them in the flow…I’m still a bit confused where I tell this script which entity (light) I’m referring to when prompted to: “Alexa, turn off the lights”. I see placeholders for entity_id in the four yellow “Edit change nodes” and the five “Edit Service Call nodes”. Do I need to add a specific entity to each of those or just one set or the other?

I used the cloud based hardill node-red-contrib-alexa-home-skill pallette for many years, it works fine. In fact I still have a few flows with it.

A few months ago, I moved most of my alexa voice command flows to node-red-contrib-amazon-echo.

Amazon-echo is local, so I get a faster response from it, where home-skill might have a few second longer delay.

I’m pretty sure anything you can do with one, you can do with the other. With amazon-echo you make a node with the device word/phrase you want to use, you don’t need to define it at a website, so one less step.

The disadvantage for me was I could never get amazon-echo to run from my NR pi3 correctly. I had to install NR on a PC I have running 24/7. From the PC, it works fine. Means I have 2 instances of NR running. I use MQTT when I need to send something from one to the other.

I looked at this a little last night, but need some more time to understand it.

BTW, if you haven’t used node-red-contrib-alexa-home-skill pallette before, it might be easier to get that working first, to a point where you can say “Alexa turn on kitchen light” and it turns on your light.
Then implement this flow to make it room aware.

Randy

@randytsuch advice is not bad, but if you want to get it to work first and get to understand it later, take a look at this little example. To get this one particular flow to work you need to do the following. Imagine you have in your house just an “Echo Studio” and an “Echo Dot”, so you should modify the “Echo Device?” node as in the picture (remember to put the name of your devices exactly as they show in your Alexa app, case sensitive). You can add more lines if you have more Echo Devices by clicking ‘add’ in the bottom left or you can delete lines by clicking the ‘x’ button from every line. Put the name, not the model. If you have called your Echo Studio “Living room speaker”, put “Living room speaker” in the “Echo Device?” node:

Now, going to the second step, you should accomplish this:


I put two titles (“Echo Dot devices” and “Echo Studio devices”) so it is more visual for you, but that is irrelevant, you only need to worry about filling the nodes properly. Add all light devices that are in the same room as every of your echoes. You can either set a group in HA and put the group, you can put a comma separated string of entities, like in the picture above, or, if it’s just one light, put that single entity right there. Don’t change anything else, just put your echo devices and the lights related to each device. If you create a group or make any change in your config files, don’t forget to restart Node Red.

1 Like

@obaldius Thank you! This is VERY helpful. I will tinker with it more tonight when I get home and keep you posted. Much appreciated!