Send random messages to google home?

Has anyone setup sending random messages or quotes to the google home?

Right now I have a message sent to one of my google homes when my daughter gets home saying “welcome home”. But it gets boring after awhile. Is there a way to have a data base of messages and Node red would pick a random one every time it was triggered?

Yes i currently have this set up with Node Red. In the “announce” section i utilize the HomeAssistant “template” with the below snippet.

{{ [
"Welcome Home Domenic",
"Domenic you are home, we missed you so much!",
"Welcome home Master",
"Hey there Domenic Welcome Home!",
"Domenic can not hide from the system. Welcome home.",
"Just a quick announcement. Domenic has arrived!",
"My systems are picking up the presence of additional humans. Domenic has been identified as home."
 ] | random }}

2 Likes

Thanks so much. Going to have so much fun with this. lol

1 Like
[{"id":"7589f533.bcd29c","type":"function","z":"e5243fcc.3bd4d","name":"Alexa random messages","func":"msg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.entity_id = {};\nmsg.payload.data.message ={};\n\nvar myArray = [\n  \"The entertainment system has been primed, and is ready to go... Enjoy yourself, and don't forget the snacks \",\n  \"hey sunshine, go put your feet up and watch a good movie\",\n  \"Marmalade will hold the fort, you go and enjoy yourself\",\n  \"See ya soon\",\n  \"Go on then bugger off, I'll sit and mumble to myself \",\n  \"The entertainment system is all set up, go have fun\"\n];\n\nvar randomItem = myArray[Math.floor(Math.random()*myArray.length)];\n\nmsg.payload.data.entity_id = \"media_player.annaka_s_echo_dot\";\nmsg.payload.data.message = randomItem;\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":611,"y":96,"wires":[[]]}]

This is a function node I use for Alexa to say random quotes

3 Likes

I’m using the Alexa as a Media Player component setup and I’m trying to get your function working. How do you get the message to play from a particular Alexa? I changed your media player to the media player that I want to say the message. Also when I manually run the function the debugger will give me a random message showing it works but I cant seem to get it to flow to the Alexa device.

Thanks,

Have you made sure the Entity ID’s match in the function node (line 17) and the Alexa Service node.

I double checked line 17 and it’s correct what is the Alexa Service node?

Here is my simple setup which you can try, you’re need to change the Alexa service node ‘call service node’ to match your setup.

[{"id":"aaf052d2.caa5f","type":"api-call-service","z":"e5243fcc.3bd4d","name":"alexa voice","server":"62d7bb2f.196044","service_domain":"media_player","service":"alexa_tts","data":"{\"entity_id\":\"media_player.annaka_s_echo_dot\"}","mergecontext":"","output_location":"payload","output_location_type":"msg","x":630,"y":200,"wires":[[]]},{"id":"5de7a88f.3a4e38","type":"function","z":"e5243fcc.3bd4d","name":"Alexa random messages","func":"msg.payload = {};\nmsg.payload.data = {};\nmsg.payload.data.entity_id = {};\nmsg.payload.data.message ={};\n\nvar myArray = [\n  \"ok, i've turned off all the lights, so go and enjoy yourself\",\n  \"go on then bugger off, leave me by myself won't you\",\n  \"catch ya later\",\n  \"don't be long\",\n  \"see ya soon\",\n  \"yippee, time for a party, she's going out\"\n];\n\nvar randomItem = myArray[Math.floor(Math.random()*myArray.length)];\n\nmsg.payload.data.entity_id = \"media_player.annaka_s_echo_dot\";\nmsg.payload.data.message = randomItem;\n\n\nreturn msg;\n","outputs":1,"noerr":0,"x":430,"y":200,"wires":[["aaf052d2.caa5f"]]},{"id":"9c29fb7e.4a8528","type":"inject","z":"e5243fcc.3bd4d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":200,"y":200,"wires":[["5de7a88f.3a4e38"]]},{"id":"62d7bb2f.196044","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

I have my current flow setup in node red but am unable to get the random messages part to output. Does someone have a recommendation what direction i need to go in as the above examples are not working for me. I was trying to get the function node to work with google home but no luck.

[{"id":"e3f2f59e.40f998","type":"server-state-changed","z":"33dca058.1268e","name":"Amcrest Doorbell Motion","server":"71022f0.1f784d","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.amcrest_camera_motion_detected","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":150,"y":220,"wires":[["d0f91ec.6471ce","41aa1cc4.47f9a4"]]},{"id":"96f27b2c.e74b48","type":"cast-to-client","z":"33dca058.1268e","name":"Google Home","url":"","contentType":"","message":"","language":"en","ip":"","port":"","volume":"50","x":760,"y":220,"wires":[["d6da4360.67c82"]],"icon":"node-red-contrib-cast/google-home1.svg"},{"id":"6e455637.1d7ee8","type":"comment","z":"33dca058.1268e","name":"Front Door Motion ","info":"","x":130,"y":100,"wires":[]},{"id":"d0f91ec.6471ce","type":"debug","z":"33dca058.1268e","name":"Amcrest Door Motion on/off","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","x":460,"y":220,"wires":[]},{"id":"700a3827.119278","type":"inject","z":"33dca058.1268e","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":140,"wires":[["41aa1cc4.47f9a4"]]},{"id":"47a90a76.119134","type":"inject","z":"33dca058.1268e","name":"off","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":180,"wires":[["41aa1cc4.47f9a4"]]},{"id":"9071bf50.14bbf","type":"change","z":"33dca058.1268e","name":"Front Door Motion TTS","rules":[{"t":"change","p":"payload","pt":"msg","from":"on","fromt":"str","to":"something is at the front door","tot":"str"},{"t":"change","p":"payload","pt":"msg","from":"off","fromt":"str","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":140,"wires":[["96f27b2c.e74b48","f6b49e42.e1ccc"]]},{"id":"f6b49e42.e1ccc","type":"debug","z":"33dca058.1268e","name":"TTS","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":870,"y":140,"wires":[]},{"id":"d6da4360.67c82","type":"debug","z":"33dca058.1268e","name":"What Google received","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":960,"y":220,"wires":[]},{"id":"41aa1cc4.47f9a4","type":"time-range-switch","z":"33dca058.1268e","name":"","lat":"","lon":"","startTime":"06:00","endTime":"nauticalDusk","startOffset":0,"endOffset":0,"x":440,"y":160,"wires":[["9071bf50.14bbf"],[]]},{"id":"71022f0.1f784d","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open"}]

Add this to your flow.

[{"id":"b7a54547.852c88","type":"tab","label":"Flow 1","disabled":false,"info":""},{"id":"5aa06f02.63ca2","type":"api-render-template","z":"b7a54547.852c88","name":"Random","server":"2c499047.e53e1","template":"{{ [\n      \"OK\",\n      \"Sure\",\n      \"If you insist\",\n      \"Done\",\n      \"No worries\",\n      \"I can do that\",\n      \"Leave it to me\",\n      \"Consider it done\",\n      \"As you wish\",\n      \"By your command\",\n      \"Affirmative\",\n      \"Yes oh revered one\",\n      \"I will\",\n      \"As you decree, so shall it be\",\n      \"No Problem\"\n] |random }} ","resultsLocation":"payload","resultsLocationType":"msg","templateLocation":"template","templateLocationType":"msg","x":860,"y":200,"wires":[["1c150cb.bddf0f3"]]},{"id":"1c150cb.bddf0f3","type":"api-call-service","z":"b7a54547.852c88","name":"TTS","server":"2c499047.e53e1","version":1,"debugenabled":false,"service_domain":"tts","service":"google_say","entityId":" media_player.home_mini_cocina","data":"{\"message\":\"{{payload}}.\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1030,"y":200,"wires":[[]]},{"id":"13b1.bdf8b44f42","type":"inject","z":"b7a54547.852c88","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":680,"y":200,"wires":[["5aa06f02.63ca2"]]},{"id":"2c499047.e53e1","type":"server","z":"","name":"Hass.io","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Thank you!.I like it. Much cleaner than what I came up with.

I’vc wanted to set something like this up… it works nice… but doesn’t use my assistants selected voice, can I specify somehow which voice to use?

Could someone tell me how I can do this with the “call service” node instead of the cast node? I use GCS which has a much better voice/pronunciation etc. Sounds way less like a roboter (thanks to wavenet).

The template doesn’t work with the call service node sadly. “API Error”.

It should work fine using the call service node

Thanks! Still new to this, sorry for the probably dumb question. Works flawlessly! :slight_smile:

No worries, that’s what this forum is for :slight_smile:

1 Like

Hi

This is great but how do you get a variable into the conversation ie the day of the week ?

I have the code for day of the week but say I want it to say

Morning Martyn, it’s Tuesday
It’s Tuesday today Martyn
What a busy Tuesday you have today Martyn

I’ve tried ${msg.payload.weekday}, +(msg.payload.weekday) and {{msg.payload.weekday}}

Thanks

Martyn

You could also do this by building an array of responses in a Google spreadsheet, then using a Google Sheets node to read those values and store them in a global or flow variable, randomize their indexed position, and send that as the message data to TTS.

I’m a noob somewhat, what palate is the announce node found in?

Is not called “announce” node, its called “render template” node, and its in the home assistant palette, however i think it is not working anymore with the node red update to 3.0, at least mine is not working anymore.

If anyone have a solution to make #render template" to work again please let me know