[UPDATED] Room aware voice commands with Alexa Media Player and amazon-echo-device

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 can achieve the same result with node-red-contrib-alexa-remote2-applestrudel for the first section

If you preffer it:

[{"id":"ee3c5fed.ec2e1","type":"alexa-remote-event","z":"877467b7.3b2fb8","name":"Cakebacked","account":"7c02d978.c2de98","event":"ws-device-activity","x":310,"y":240,"wires":[["87da98ac.4bda08","2456ea2a.741cb6"]]},{"id":"28316360.79a22c","type":"comment","z":"877467b7.3b2fb8","name":"Setting currently listening device","info":"","x":270,"y":120,"wires":[]},{"id":"2456ea2a.741cb6","type":"switch","z":"877467b7.3b2fb8","name":"","property":"payload.data.utteranceType","propertyType":"msg","rules":[{"t":"eq","v":"GENERAL","vt":"str"}],"checkall":"false","repair":false,"outputs":1,"x":435,"y":240,"wires":[["4ac2d190.b7afa"]],"l":false},{"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":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_on","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":3,"debugenabled":false,"service_domain":"homeassistant","service":"turn_off","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":"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","amazonPage":"amazon.es","acceptLanguage":"es-ES","onKeywordInLanguage":"on","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30}]

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

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 from 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.

2 Likes

I just tried setting the fan up. Alexa just tells me there are a few devices named ‘fan’. How do I work around that?

edit: Oh! Your fan JOSN is missing the very first node. What is it?

You should set yours :slight_smile:

If alexa tells you there are a few devices called fan, remove every device except the one in your flow.

thank you. its working fine so far :slight_smile:

Did you ever get this working? I am having the same issue.

The only solution I can think of is to name my fan devices something else. Then use “fan” with the node-red flows.

1 Like

[{"id":"e5f316773f958001","type":"comment","z":"de18413ec87a6b4b","name":"FAN","info":"","x":130,"y":540,"wires":[]},{"id":"c3b29a262e927892","type":"ha-wait-until","z":"de18413ec87a6b4b","name":"","server":"9405c3fe.d0a6c","version":2,"outputs":2,"entityId":"input_boolean.room_aware","entityIdFilterType":"exact","property":"state","comparator":"is","value":"on","valueType":"str","timeout":"7","timeoutType":"num","timeoutUnits":"seconds","checkCurrentState":true,"blockInputOverrides":true,"outputProperties":[],"x":235,"y":600,"wires":[["f489566aa03fcce9"],[]],"l":false},{"id":"8ecdc5098a53ba2d","type":"api-call-service","z":"de18413ec87a6b4b","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","output_location":"","output_location_type":"none","x":500,"y":600,"wires":[[]]},{"id":"dbcbd14c9afe60c3","type":"switch","z":"de18413ec87a6b4b","name":"Echo Device?","property":"echodevice","propertyType":"flow","rules":[{"t":"eq","v":"Lounge Dot","vt":"str"},{"t":"eq","v":"Kitchen Show","vt":"str"},{"t":"eq","v":"Rodri's Sonos One Second Edition","vt":"str"}],"checkall":"true","repair":false,"outputs":3,"x":240,"y":700,"wires":[["65e607a34ddc4f39"],["65e607a34ddc4f39"],["d117d3cfab52f19f"]]},{"id":"65e607a34ddc4f39","type":"change","z":"de18413ec87a6b4b","name":"","rules":[{"t":"set","p":"fan_entity_id","pt":"flow","to":"switch.wp1_fan","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":435,"y":700,"wires":[["71c5216c5f6bcc82"]],"l":false},{"id":"d117d3cfab52f19f","type":"change","z":"de18413ec87a6b4b","name":"","rules":[{"t":"set","p":"fan_entity_id","pt":"flow","to":"fan.bedroom_fan","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":435,"y":820,"wires":[["1bd499de9312fb27"]],"l":false},{"id":"4a3ac50455615c1d","type":"alexa-remote-routine","z":"de18413ec87a6b4b","name":"Error","account":"f464cfd28eca3add","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"Fan doesn't operate under this parameter"},"devices":["954e761c7dbe4615b4fe50a716ecea2b"]}},"x":810,"y":860,"wires":[[]]},{"id":"22b7636a3ed69ea6","type":"vsh-virtual-device","z":"de18413ec87a6b4b","name":"Fan","topic":"","connection":"47c16d8f8ae3b3c2","template":"FAN","retrievable":false,"passthrough":true,"diff":true,"filter":false,"filterTopic":false,"plan":"free","x":130,"y":600,"wires":[["c3b29a262e927892"]]},{"id":"c20225fb840fb8be","type":"link in","z":"de18413ec87a6b4b","name":"link in 1","links":["f489566aa03fcce9"],"x":115,"y":700,"wires":[["dbcbd14c9afe60c3"]]},{"id":"f489566aa03fcce9","type":"link out","z":"de18413ec87a6b4b","name":"link out 2","mode":"link","links":["c20225fb840fb8be","479ed625b571134b"],"x":285,"y":600,"wires":[]},{"id":"479ed625b571134b","type":"link in","z":"de18413ec87a6b4b","name":"link in 2","links":["f489566aa03fcce9"],"x":415,"y":600,"wires":[["8ecdc5098a53ba2d"]]},{"id":"1bd499de9312fb27","type":"function","z":"de18413ec87a6b4b","name":"Fan Speed Control","func":"var customName = \"FBedroomFanSpeed\"; // Define your custom name here\nvar fanSpeed = flow.get(\"fanSpeed\") || 0; // Retrieve the existing value of fanSpeed or initialize it to 0\n\nvar command = msg.payload.directive;\nvar speed = msg.payload.speed;\nvar numOfSpeeds = 3; // Define the number of speeds here\n\nif (command == \"TurnOn\" || command == \"TurnOff\") {\n    if (numOfSpeeds >= 1) {\n        if (command == \"TurnOn\") {\n            fanSpeed = 33;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (command == \"TurnOff\") {\n            fanSpeed = 0;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        }\n    } else {\n        return [null, msg];\n    }\n} else if (command == \"SetRangeValue\" || command == \"AdjustRangeValue\") {\n    if (numOfSpeeds >= speed) {\n        if (speed == 0) {\n            fanSpeed = 0;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 1) {\n            fanSpeed = 33;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 2) {\n            fanSpeed = 66;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 3) {\n            fanSpeed = 100;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        }\n    } else {\n        return [null, msg];\n    }\n}\n\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":820,"wires":[["48082ed8f75bf0bb"],["4a3ac50455615c1d"]]},{"id":"48082ed8f75bf0bb","type":"api-call-service","z":"de18413ec87a6b4b","name":"Fan Contol","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"fan","service":"set_percentage","areaId":[],"deviceId":[],"entityId":["{{flow.fan_entity_id}}"],"data":"{\"percentage\": \"{{payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":830,"y":800,"wires":[[]]},{"id":"71c5216c5f6bcc82","type":"function","z":"de18413ec87a6b4b","name":"Fan Switch Control","func":"var command = msg.payload.directive;\nvar speed = msg.payload.speed;\n\n\nif (command == \"TurnOn\" || command == \"TurnOff\") {\n    if (command == \"TurnOn\") {\n        msg.payload = \"turn_on\";\n    } else if (command == \"TurnOff\") {\n        msg.payload = \"turn_off\";\n    }\n} else if (command == \"SetRangeValue\" || command == \"AdjustRangeValue\") {\n    if (speed > 1) {\n    return [null, msg];\n    }\n}\n\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":700,"wires":[["264c7713893b34a4"],["80830cf4ed99b9ab"]]},{"id":"80830cf4ed99b9ab","type":"alexa-remote-routine","z":"de18413ec87a6b4b","name":"Error","account":"f464cfd28eca3add","routineNode":{"type":"speak","payload":{"type":"regular","text":{"type":"str","value":"Fan doesn't operate under this parameter"},"devices":["G0922H07244214XC"]}},"x":810,"y":720,"wires":[[]]},{"id":"264c7713893b34a4","type":"api-call-service","z":"de18413ec87a6b4b","name":"Fan Switch","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"switch","service":"{{payload}}","areaId":[],"deviceId":[],"entityId":["{{flow.fan_entity_id}}"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":830,"y":660,"wires":[[]]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"id","deviceSelector":"id","entitySelector":"id","statusSeparator":"","statusYear":"hidden","statusMonth":"hidden","statusDay":"hidden","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false},{"id":"f464cfd28eca3add","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.10.199","proxyPort":"3456","cookieFile":"","refreshInterval":"3","alexaServiceHost":"alexa.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-UK","onKeywordInLanguage":"","userAgent":"","useWsMqtt":"on","autoInit":"on"},{"id":"47c16d8f8ae3b3c2","type":"vsh-connection","name":"[email protected]","port":"8883","accessTokenExpiry":"1685055879481","debug":false,"backendUrl":"https://kfd5m4a21f.execute-api.eu-west-1.amazonaws.com/dev","lwaClientId":"amzn1.application-oa2-client.3f1bb07133854b078261ad43f2484c18"}]

Got this woking well in each room, great work thank you

Ive modified the fan to make it a bit smaller, it works with on, off, set speed and speed up and down for a 3 speed fan. ive also added a on off for a switch type

1 Like

I made compatibility with my system, and it doesn’t work, what should I tell Alexa?

id check to see if the input_boolean.room_aware is getting the name of the echo you speak to.

have you added
node-red-contrib-virtual-smart-home to your Node Red pallet?

you will need to configure it and add the virtual smart-home to your Alexa skills. this will make the new device discoverable in Alexa (make sure there is only one)

make sure you set your echo device in the select node. you could add a debug before the fan speed control set to complete message to see what’s happening

node-red-contrib-virtual-smart-home to your Node Red ---- I downloaded it - I saw that it was missing

Instead - input_boolean.room_aware
I have another boolean - it really doesn’t matter

you will need to configure it and add the virtual smart-home to your Alexa skills. this will make the new device discoverable in Alexa (make sure there is only one) ----- Where can I see the devices?
I connected through Alexa to Skill

when you open the virtual smart -home FAN you should see

the new device will be in you alexa devices, mine just appeared I didn’t need to discover

did you add the skill in the Alexa app too?

[{"id":"8ecdc5098a53ba2d","type":"api-call-service","z":"de18413ec87a6b4b","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","output_location":"","output_location_type":"none","x":500,"y":600,"wires":[[]]},{"id":"1bd499de9312fb27","type":"function","z":"de18413ec87a6b4b","name":"Fan Speed Control","func":"var customName = \"FBedroomFanSpeed\"; // Define your custom name here\nvar fanSpeed = flow.get(\"fanSpeed\") || 0; // Retrieve the existing value of fanSpeed or initialize it to 0\nvar alexa = flow.get(\"echodevice\") || 0; // Retrieve the existing value of alexadevice or initialize it to 0\nvar modifiedAlexa = alexa.replace(/[\\' ]/g, \"_\").toLowerCase(); // Conditions the output for HA\n\nvar command = msg.payload.directive;\nvar speed = msg.payload.speed;\nvar numOfSpeeds = 3; // Define the number of speeds here\n\nif (command == \"TurnOn\" || command == \"TurnOff\") {\n    if (numOfSpeeds >= 1) {\n        if (command == \"TurnOn\") {\n            fanSpeed = 33;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (command == \"TurnOff\") {\n            fanSpeed = 0;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        }\n    } else {\n        return [null, msg];\n    }\n} else if (command == \"SetRangeValue\" || command == \"AdjustRangeValue\") {\n    if (numOfSpeeds >= speed) {\n        if (speed == 0) {\n            fanSpeed = 0;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 1) {\n            fanSpeed = 33;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 2) {\n            fanSpeed = 66;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        } else if (speed == 3) {\n            fanSpeed = 100;\n            flow.set(customName, fanSpeed);\n            msg.payload = fanSpeed;\n        }\n    } else {\n        msg.payload = \"alexa_media_\" + modifiedAlexa;\n        return [null, msg];\n    }\n}\n\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":820,"wires":[["48082ed8f75bf0bb"],["d6ec95925a7cccfb"]]},{"id":"48082ed8f75bf0bb","type":"api-call-service","z":"de18413ec87a6b4b","name":"Fan Contol","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"fan","service":"set_percentage","areaId":[],"deviceId":[],"entityId":["{{flow.fan_entity_id}}"],"data":"{\"percentage\": \"{{payload}}\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":830,"y":800,"wires":[[]]},{"id":"71c5216c5f6bcc82","type":"function","z":"de18413ec87a6b4b","name":"Fan Switch Control","func":"var command = msg.payload.directive;\nvar speed = msg.payload.speed;\nvar alexa = flow.get(\"echodevice\") || 0; // Retrieve the existing value of alexadevice or initialize it to 0\nvar modifiedAlexa = alexa.replace(/[\\' ]/g, \"_\").toLowerCase(); // Conditions the output for HA\n\nif (command == \"TurnOn\" || command == \"TurnOff\") {\n    if (command == \"TurnOn\") {\n        msg.payload = \"turn_on\";\n    } else if (command == \"TurnOff\") {\n        msg.payload = \"turn_off\";\n    }\n} else if (command == \"SetRangeValue\" || command == \"AdjustRangeValue\") {\n    if (speed > 1) {\n        msg.payload = \"alexa_media_\" + modifiedAlexa;\n    return [null, msg];\n    }\n}\n\nreturn msg;\n","outputs":2,"noerr":0,"initialize":"","finalize":"","libs":[],"x":590,"y":700,"wires":[["264c7713893b34a4"],["13e5b45dfc5f9c56"]]},{"id":"264c7713893b34a4","type":"api-call-service","z":"de18413ec87a6b4b","name":"Fan Switch","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"switch","service":"{{payload}}","areaId":[],"deviceId":[],"entityId":["{{flow.fan_entity_id}}"],"data":"","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","output_location":"","output_location_type":"none","x":830,"y":680,"wires":[[]]},{"id":"d0d6752ddef61b27","type":"api-call-service","z":"de18413ec87a6b4b","name":"","server":"9405c3fe.d0a6c","version":5,"debugenabled":false,"domain":"notify","service":"{{payload}}","areaId":[],"deviceId":[],"entityId":[],"data":"\t{    \"message\": \"Fan doesn't operate under this parameter\",\t     \"data\": \t     {        \t         \"type\": \"tts\"\t        }\t}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":850,"y":600,"wires":[[]]},{"id":"ba5e596d81b42b50","type":"link in","z":"de18413ec87a6b4b","name":"link in 5","links":["d6ec95925a7cccfb","13e5b45dfc5f9c56"],"x":735,"y":600,"wires":[["d0d6752ddef61b27"]]},{"id":"d6ec95925a7cccfb","type":"link out","z":"de18413ec87a6b4b","name":"link out 4","mode":"link","links":["ba5e596d81b42b50"],"x":785,"y":860,"wires":[]},{"id":"13e5b45dfc5f9c56","type":"link out","z":"de18413ec87a6b4b","name":"link out 5","mode":"link","links":["ba5e596d81b42b50"],"x":775,"y":740,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"","connectionDelay":false,"cacheJson":false,"heartbeat":false,"heartbeatInterval":"","areaSelector":"id","deviceSelector":"id","entitySelector":"id","statusSeparator":"","statusYear":"hidden","statusMonth":"hidden","statusDay":"hidden","statusHourCycle":"default","statusTimeFormat":"h:m","enableGlobalContextStore":false}]

ive changed the function blocks and used HA to send notifications

1 Like

image

Ok so I managed to connect (I think)

The question is what do I have to say to Alexa for it to work? lol

You should be able to say turn fan on or set fan to speed 3, depending on your fan. ive noticed you bypassed the wait node? was that stopping it before ? that checks that the room_aware (your need to change this to your input_boolean) is switched on so it knows it has saved the echo device to the flow in the context menu, will be worth checking yours in the top right hand menu

the echodevice should be theme of the device you speak to, if this is not updating it won’t know where to send the command.

do you have this from the first post?

1 Like