Need help with a semi complicated flow

Below you can see the flow I’m working with. Currently if I ask Alexa, “Where is C?”, this automation is triggered. The automation will get C’s location from the C’s_Street sensor, and put the location in a format so that Alexa will say for example, “She is at 100 East Main Street, Atlanta, Ga”.

This all works fine. The problem is currently Alexa responds on a specific echo instead of where the question was originally asked. So I have another sensor called sensor.last_alexa which contains the name of the Amazon echo where the message needs to go, but I cannot figure out how to work it into the flow.

Here is the current template node that formats the message that the alexa media player needs. However instead of “echo plus” , I need the contents of the sensor.last_alexa:

{ "data" : { "entity_id": "media_player.echo_plus", "message": "She is at {{payload}}" }}

Can someone help me?

This might not work correctly depending on what version of the Node-RED Home Assistant module you’re using.

You should be able to just drop the sensor in front of the template node and uncheck overwrite payload. Then in the template reference data.state to get the last_alexa. Also if you using the latest websocket version 0.3.1 you don’t need the template node you can use that string in the data property of the call-service node.

{ "data" : { "entity_id": "{{data.state}}", "message": "She is at {{payload}}" }}

If you still using the original module you’re going to have to use a change node after C’s Street and move msg.payload to something like msg.street and then insert the sensor.last_alexa and change your template to be something like { "data" : { "entity_id": "{{payload}}", "message": "She is at {{street}}" }}

2 Likes

From the after sensor.last_alexa you can set a change node and set a flow context for the payload. You can then call the flow context in the template or in the call service, don’t know if this last is possible @Kermit can confirm.

There is also a join node that I think is for this but I haven’t used yet.

1 Like

Thank you, that worked for the most part. It works for all Amazon Echos that don’t have a space in their name. I’m using “alexa_remote_control.sh” in a command_line sensor to give me “last_alexa”. However that sh script returns what HA considers the Friendly Name of the media player with spaces instead of underscores.

Is there a way to use some kind of replace function in that template node to replace spaces with underscores so that "entity_id": "media_player.Echo Plus" becomes "entity_id": "media_player.Echo_Plus".

If not I guess I have other alternatives such as replacing the space in that alexa_remote_control.sh script or the py script that calls the sh script for the command line sensor.

Thanks again!

Edit: I decided to modify the alexa_wrapper.py so that it replaced spaces with underscores. All is working well now. Thanks!

Thanks for letting me know about those options!

There is string that has several functions to manipulate text.

1 Like

That works perfectly. Thank you!