Variable in Notification (tts)

Hey, im new in Node-Red and playing with it actually. At the moment im trying to just transfer all my yaml-automations to node red. I guess its very easy, but atm I personally stuck.

I want to call the notify service for Alexa_media. But how can I insert a Variable in the message. For example I want to say “Actually its 30 degrees outside” … the 30 for example should be the value of my sensor.dark_sky_temperature. I think I have to get the current state of the entity, and then insert the msg.payload in my text. But how?

appreciate any help guys!

There is more than one way to do it but call service node is very flexible with those things. you can use something like this:

image

[{"id":"de95e4dd.f5e818","type":"inject","z":"294e4f5f.46b07","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":1140,"wires":[["9cb50326.797c6"]]},{"id":"9cb50326.797c6","type":"api-current-state","z":"294e4f5f.46b07","name":"temperature","server":"e447d17a.16a64","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.dark_sky_temperature","state_type":"str","state_location":"temperature","override_payload":"msg","entity_location":"","override_data":"none","blockInputOverrides":false,"x":330,"y":1140,"wires":[["7d0304c3.092bec"]]},{"id":"7d0304c3.092bec","type":"api-call-service","z":"294e4f5f.46b07","name":"speak","server":"e447d17a.16a64","version":1,"debugenabled":true,"service_domain":"tts","service":"google_translate_say","entityId":"media_player.googlehome5129","data":"{\"message\":\"Actually its {{temperature}} degrees outside\"}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":510,"y":1140,"wires":[[]]},{"id":"e447d17a.16a64","type":"server","z":"","name":"Home Assistant","legacy":false,"hassio":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":false}]

I don’t use alexa so you need to check how is the data structure and adapt accordingly.

1 Like

Thank you Serkan. I was interested in exactly this part here {“message”:“Actually its {{temperature}} degrees outside”}.

For the newbies like me, I also figured out, that you can rename the msg.output, if you want more variables.

1 Like

You are also able to look up states directly from a template without using the current-state node.

{"message": "Actually its {{entity.sensor.dark_sky_temperature}} degrees outside"}

Check out the info panel of the call-service node for more examples.

4 Likes

@kermit firstly thanks for you excellent responses in support of RN and templating. I’ve learnt a lot from your postings.

If I could ask you though… How does one insert a sound (wav or mp3) into a template before sending the message JSON ? What I’m thinking of is some sort of alert to draw attention to the fact that a voice notification is about to be voiced on Alexa. Thank you!

Wow! Thank you very much, that is even better. It is described very good in the info-panel, thank you for the hint.

may I ask you something else: My Alexa is saying for a value of 1.5 (example) “first five”. The problem is the dot instead of a comma, can I change this somehow? I was able to change the dot for a comma with the change-node after a get-state node, but how could I realize that when I use direct templating?

{
“message”: “Die Temperatur beträgt {{entity.sensor.dark_sky_temperature}} Grad.”,
“data”: {
“type”: “tts”
}
}

If you change the “tts” to “announce”, you will get the typically announce sound of Alexa before she reads the message.

1 Like

You can’t manipulate data using mustache templates but you could change the data type of the data field from JSON to JSONata expression.

{"message": "Actually its " & $replace($entities("sensor.dark_sky_temperature").state, ".", ",") & " degrees outside"}

https://community.home-assistant.io/t/jsonata-examples-for-ha-nodes/128963?u=kermit

1 Like

Perfect!! Thank @fitim appreciate your advice.

The audio tag is exactly what you want but according to the alexa media player wiki the audio tag is the only one that isnt available. So just use the announce as the type. Instead of tts. And you get a Tada! Before the message

You then have the additional method which is speak or all, there use to be a show but it’s been removed.
All will display the message on the echo show
I use announce just because it goes Tada! Sort of like that. Don’t forget you can use the SSML tags and use 60 different voices. Which is what I do to announce the washing machine has finished. Don’t want to hear Alexa all the time.
German Hans
“This is Hans, The Washing Machine is Now Finished”
Spanish
This is Conchita…
Italian
This is Giorgio…
And there much more I haven’t even tried
Effect
Like whisper, excited
Check out the wiki
And click on the SSML markup in the notification

check out this
it may help you
https://docs.aws.amazon.com/polly/latest/dg/supportedtags.html

Thank you for your help buddy! :slight_smile:

How do you change the voice? I tried for example:

{
“message”: " Hey, wie geht es dir? Was machst du? Ich hoffe es geht dir gut. ",
“data”: {
“type”: “announce”,
“VoiceId”: “Hans”
}
}

That not working, Alexa is talking like always :smiley:

I will paste an example for you shortly
When I get home

{
    "data": {
        "type": "announce",
        "method": "all"
    },
    "message": "<voice name='Conchita'>This is Conchita. The Washing Machine is Now Finished</voice>",
    "target": [
        "media_player.kitchen",
        "media_player.george_s_echo_show",
        "media_player.living_room_right",
        "media_player.echo_plus",
        "media_player.sunroom_left"
    ]
}

This is my shared project for my washing machine announcement
i’m going to expand it to do the 60 voices and use the whisper effect outside of the 8:00am -9:30pm time i currently allow it to announce

1 Like

Is it possible to go one step deeper? When I’d for example want Google to announce an attribute, not the payload?
So for example, that it does use the “100” instead of “open”?

see

{{entity.cover.shelly_shsw_25_bcddc277b3b8.attributes.current_position}}

My hero :smiley: Thanks!