Can I pass a JSON message in a change node to a template node to be spoken?

I've taken out all unncessary parts of the flow, just FYI.

I know its currently wrong; but I am looking for how to do it, if possible. In my change node, I would like the message it passes along to be spoken to be dynamically changed based on its input.

So in my example, I set msg.carrier to ups. I would then like the change node to input that into its message that it passes to the TTS template node. So that in the end, my speaker says "A package from UPS has been delivered".

[{"id":"ebd69f4bccf807e7","type":"tab","label":"Mail","disabled":false,"info":"","env":[]},{"id":"8e97a41daf1fb970","type":"alexa-remote-routine","z":"ebd69f4bccf807e7","name":"Speak: msg.payload","account":"f0ce5fbc.18734","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"jsonata","value":"payload"},"volume":{"type":"num","value":"20"},"mode":"set","devices":["G6G0XG11030205CT"]}},"x":910,"y":390,"wires":[[]]},{"id":"22a918f799ca58e5","type":"template","z":"ebd69f4bccf807e7","name":"TTS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<speak>\n<voice name= \"{{voice}}\" >\n{{message}} \n</voice>\t\n</speak> ","output":"str","x":715,"y":390,"wires":[["8e97a41daf1fb970"]]},{"id":"dc6284b3ae4371fc","type":"inject","z":"ebd69f4bccf807e7","name":"Set carrier UPS","props":[{"p":"carrier","v":"ups","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":215,"y":390,"wires":[["7ee9cc44eb29febd"]]},{"id":"7ee9cc44eb29febd","type":"change","z":"ebd69f4bccf807e7","name":"Message: All packages delivered","rules":[{"t":"set","p":"message","pt":"msg","to":"A package from {{carrier}} has been delivered.","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":475,"y":390,"wires":[["22a918f799ca58e5"]]},{"id":"f0ce5fbc.18734","type":"alexa-remote-account","name":"","authMethod":"proxy","proxyOwnIp":"192.168.86.215","proxyPort":"3456","cookieFile":"Auth","refreshInterval":"15","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.com","acceptLanguage":"en-US","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

Try replacing the 'change' node with a 'function' that has the following code in it.

let text = "A package from "+msg.carrier+ " has been delivered";
msg = {message:text};
return msg;

You're almost there! :+1:

In the change node, set the new values format to "expression" (depicted by the 'J') and then use a bit of JSONata to put your message together, e.g.:

1 Like

@nappyjim This example should work for you.

[{"id":"dc6284b3ae4371fc","type":"inject","z":"ebd69f4bccf807e7","name":"Set carrier UPS","props":[{"p":"carrier","v":"u p s","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":120,"y":300,"wires":[["ae44a490487c5750"]]},{"id":"ae44a490487c5750","type":"change","z":"ebd69f4bccf807e7","name":"","rules":[{"t":"set","p":"voice","pt":"msg","to":"Emma","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":260,"y":240,"wires":[["22a918f799ca58e5"]]},{"id":"22a918f799ca58e5","type":"template","z":"ebd69f4bccf807e7","name":"TTS","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<speak>\n<voice name= \"{{voice}}\" >\nA package from {{carrier}} has been delivered\n</voice>\t\n</speak> ","output":"str","x":310,"y":300,"wires":[["8e97a41daf1fb970"]]},{"id":"8e97a41daf1fb970","type":"alexa-remote-routine","z":"ebd69f4bccf807e7","name":"Speak: msg.payload","account":"c8738129.d902c","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"payload"},"volume":{"type":"num","value":"20"},"mode":"set","devices":["G090LF1182850C6D"]}},"x":490,"y":280,"wires":[["5a2f5116933c43e5"]]},{"id":"5a2f5116933c43e5","type":"debug","z":"ebd69f4bccf807e7","name":"debug 347","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":710,"y":220,"wires":[]},{"id":"c8738129.d902c","type":"alexa-remote-account","name":"alexa remote 2","authMethod":"proxy","proxyOwnIp":"localhost","proxyPort":"3456","cookieFile":"","refreshInterval":"14","alexaServiceHost":"layla.amazon.co.uk","amazonPage":"amazon.co.uk","acceptLanguage":"en-GB","onKeywordInLanguage":"","userAgent":"","useWsMqtt":"on","autoInit":"off"}]

Using SSML Speech Synthesis Markup Language (SSML) Reference | Alexa Skills Kit

@ralphwetzel Sorry used the wrong reply button.

1 Like

Thank you guys for all the suggestions, I tried all and they all seem to work. Now I just gotta see which way works the best when incorporated into the full flow

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