Google TTS through Node-red

I’ve built almost my entire automation system with HA using node-red, mainly for the simplicity of adding new automations, editing existing and testing new things.
But I’ve stuck on how i should call the google.tts service to be able to read sensor states. Normal text works perfectly.

A regular automation for google.tts with templating looks like this

service: tts.google_say
data_template:
  message: "Temperature is {{states('sensor.temperature')}}."
  cache: false

But the default call-service within node-red uses regular “data” as the action, so passing the above “message” would result in the media player readin out “states sensor temperature”, not the actual value since it cant understand it’s a template message.

Does anyone know how to do this in a simple way? Or a hard way :slight_smile:

Currently, you’re not able to reference states from within the call-service node but you can call a current-state node before it and then use its payload in the call-service node.

{"message": "Temperature is {{payload}}."}

and then make sure you check the Render templates in Data

5 Likes

Thanks, that was a good way of solving it :slight_smile:

Hi,

@martikainen could you share your node-red flow for the tts ?

I actually never finished this project… Saving it for some rainy days =)

Here is an example for those who find this thread.

https://pastebin.com/5p75zh9b

5 Likes

Here you can find a tts node with advanced features

  • caching notification audio message
  • restoring device inital volume after having played the notification
  • queueing notifications messages
  • important flag for notifications to be playing immediatly

https://flows.nodered.org/node/node-red-google-notify