Expanding/Randomizing Output of Template Node

I don't know enough to know if this is possible and I'm not even sure how to even start looking into this, so I'm hoping someone can send me in the right direction.

With some amazing help I've been able to create a few flows that take spoken input from Rhasspy, interfacing with Home Assistant, and/or my Chromecast Audio, turn some light on, change the thermostat temperature, or play some radio streams on the Chromecast (as well as controlling playback and volume).

What I am wonding is, is there a way to create some variation in the spoke response from Rhasspy indicating the request is being actioned.

For example when I ask Rhasspy to play a Radio Station, Rhasspy responds with 'Now Playing {{slots.station}}' (obviously slots.station is the actual station name.
This response is a template node, set to mustache template, plain text output.

Is there a way for me to create other responses in this node and have one (sudo or actual) randomly selected?
So instead of always getting 'Now Playing Station X' it might say 'Tuning to Station X' or 'Station X, Great choice'.

Possilbe, not possible?

Maybe some options that are station specific even?

With some conditional mustache syntax yes, but its not pretty.

Far easier with a function node...

const station = msg.payload;
const options = [
    `Now playing station ${station}`,
    `Playing station ${station}, good choice`,
    `Tuning to Station ${station}`,
    //add more here
const index = Math.floor(Math.random() * options.length);
msg.payload = options[index];
return msg;


[{"id":"8fc733f4f1f3151a","type":"function","z":"9e7ee46441f8c187","name":"format station message","func":"const station = msg.payload;\nconst options = [\n    `Now playing station ${station}`,\n    `Playing station ${station}, good choice`,\n    `Tuning to Station ${station}`,\n];\nconst index = Math.floor(Math.random() * options.length);\nmsg.payload = options[index];\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2143.999984741211,"y":110.00002479553223,"wires":[["299967efbe8cd9a7"]]},{"id":"9ad7f8dc2fb7489a","type":"inject","z":"9e7ee46441f8c187","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Absolute Classic Rock","payloadType":"str","x":1843.999984741211,"y":110.00002479553223,"wires":[["8fc733f4f1f3151a"]]},{"id":"00a8b2fa6372eee9","type":"inject","z":"9e7ee46441f8c187","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Planet Rock","payloadType":"str","x":1813.999984741211,"y":150.00002479553223,"wires":[["8fc733f4f1f3151a"]]},{"id":"299967efbe8cd9a7","type":"debug","z":"9e7ee46441f8c187","name":"","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":2173.999984741211,"y":170.00002479553223,"wires":[]}]

That makes so much sense

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