Alexa speak msg.payload within a defined sentence

I am using node-red for my smart home automation. So far my flows are working brilliantly integrating my rf bridge with home made rf door contacts, sonoff / tasmota switches, ip camera, lg smart tv, rf smart plugs and alexa (mainly routine execution and speak at volume announcements.
However I need help with my latest project. I am trying to use a android app called owntracks to make alexa announce to my wife when i get to a certain place and when i am on my way home. Owntracks sends a mqtt message with a different topic when a transition event occurs. This is when the phone enters or leaves a predetermined area or place.
Rather than writing individual separate flows for each transition place and event (enter or leave for every location using the switch node). Can someone help me find how to make alexa announce the actual value in the message payload within a sentence. For example Alexa says " rob is now about to (here alexa says the result of msg.topic owntracks/robmak/huawie/event msg.payload event {enter or leave} then the msg.payload of the location description). So my wife will hear "rob is now about to enter the tesco" or "rob is about to leave the tesco ".
I have searched everywhere and tried everything and cant get alexa to speak the msg.payload value returned only the actual words msg.payload.
I am sure this should be possible.
I already have a flow that works using a basic switch node for each location and each event to and from the location with individual speak at volume and phone push notifications for each. Its a long winded way of doing this but it works. But this method makes it impossible to add locations on the phone owntracks app and have alexa respond without adding another node red flow.
any help appreciated. My javascript knowledge is small but I really wanting to learn. So please use basic language and instructions. I am also quite new to node red but I have developed a fairly large collection of very useful working flows quickly. Before node red i found alexa integration with smart automation very limited.

here is an example how to create the msg.payload to feed into a alexa remote2 routine node set to custom.

[{"id":"8e6c5e64.ad9dc","type":"inject","z":"a2f1ba5f.ac38d8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"type\":\"speakAtVolume\",\"type2\":\"regular\",\"text\":\"say these words\",\"volume\":50,\"devices\":[\"Lounge\"]}","payloadType":"json","x":90,"y":380,"wires":[["a45b36d7.03eca"]]},{"id":"a45b36d7.03eca","type":"function","z":"a2f1ba5f.ac38d8","name":"","func":"msg.payload = { \"type\": msg.payload.type, \n                \"payload\": { \"type\": msg.payload.type2, \n                             \"text\": msg.payload.text,\n                              \"volume\": msg.payload.volume, \n                              \"devices\": msg.payload.devices\n                            }\n                }\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":110,"y":320,"wires":[["741d4d74.a13b54","a2eb7864.e04ef"]]},{"id":"741d4d74.a13b54","type":"alexa-remote-routine","z":"a2f1ba5f.ac38d8","name":"","account":"c9677242.dca69","routineNode":{"type":"custom","payload":{"type":"msg","value":"payload"}},"x":420,"y":320,"wires":[[]]},{"id":"c9677242.dca69","type":"alexa-remote-account","z":"","name":"alexaremote2","authMethod":"proxy","proxyOwnIp":"","proxyPort":"3456","cookieFile":"alexa-remote2.txt","refreshInterval":"14","alexaServiceHost":"","amazonPage":"","acceptLanguage":"en-UK","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

or if you want to add msg.payload into the text property

[{"id":"8e6c5e64.ad9dc","type":"inject","z":"a2f1ba5f.ac38d8","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"blue","payloadType":"str","x":90,"y":380,"wires":[["a45b36d7.03eca"]]},{"id":"a45b36d7.03eca","type":"function","z":"a2f1ba5f.ac38d8","name":"","func":"msg.payload = { \"type\": \"speakAtVolume\", \n                \"payload\": { \"type\": \"regular\", \n                             \"text\": \"this \" + msg.payload + \" cat\",\n                              \"volume\": 40, \n                              \"devices\": \"Lounge\"\n                            }\n                }\nreturn msg;\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":110,"y":320,"wires":[["741d4d74.a13b54","a2eb7864.e04ef"]]},{"id":"741d4d74.a13b54","type":"alexa-remote-routine","z":"a2f1ba5f.ac38d8","name":"","account":"c9677242.dca69","routineNode":{"type":"custom","payload":{"type":"msg","value":"payload"}},"x":420,"y":320,"wires":[[]]},{"id":"c9677242.dca69","type":"alexa-remote-account","z":"","name":"alexaremote2","authMethod":"proxy","proxyOwnIp":"","proxyPort":"3456","cookieFile":"alexa-remote2.txt","refreshInterval":"14","alexaServiceHost":"","amazonPage":"","acceptLanguage":"en-UK","userAgent":"","useWsMqtt":"on","autoInit":"on"}]
1 Like

thank you so much. works really well. just what i needed.

I am very pleased with the flow I am using now the variable place is spoken by alexa.
I have tried to edit the function code even more to also provide the same spoken sentence as a push notification.
I wondered if you have any help to offer me with this problem. I have tried all he obvious ways that I can think of. One issue is the push notification has a title text box and another text box of unknown name.
I dont mind making my own code if you know how to do this and can point me in the right direction.
Thanks Rob

show your flow, export it here so i can take a look and give some pointers and maybe edit function for you.

be sure to put code between back ticks as below

removed flow

The msg.payload looks fine, when it runs does the routine node show success?

invalid sequence node: "{"type":"Push Notification","payload":{"text":"rob is leaving home area now"}}" expected layout: "undefined"

"Push Notification" should be "pushNotification"

invalid sequence node: "{"type":"PushNotification","payload":{"text":"rob is leaving home area now"}}" expected layout: "undefined"

changed the alexa routine node to push notification and got this debug
invalid sequence node: "{"type":"pushNotification","payload":{"text":{"type":"PushNotification","payload":{"text":"rob is approaching home area now"}},"title":"Node-RED"}}" expected layout: "undefined"

thank you. I did not pay enough attention to your advice to change to pushNotification. I left the upper case p in my function. Changed it to exactly as you said and it now works.
Thank you so much. You are a star !!!!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.