Speaking clock with Rhasspy

Good evening to all.

I am home automation user and I discover node red through rhasspy.
I am also a beginner in java script.

For several weeks I have looking for a proper syntax java script to speech the current time.
In the rhasspy voice assistant my intent is [GetTime] and i’d like to hear the current time when i say 'what time is it ?' ( of course in french).

I copied a code template into a tutorial.
Here my code in a node 'Function' who is working (i hear the voice) well with string value example 18(hh) and 45(mn) or other string value :

msg.payload = "{"speech":{"text":"Il est 18 heures et 45 minutes "},"site_id":"" + msg.payload.site_id + ""}"
return msg;

I found this code below :

var aujourdhui = new Date();
var heure = aujourdhui.getHours();
var minutes = aujourdhui.getMinutes();
var secondes = aujourdhui.getSeconds();

I guess i have to replace 18 and 45 by a 'msg.payload' value but i have syntax errors.

what is the right syntax to replace string time value (18 and 45) to the current time ?

Can you help me, please ?

Try something like this

var aujourdhui = new Date();
var heure = aujourdhui.getHours();
var minutes = aujourdhui.getMinutes();
msg.payload = {"speech":{"text":"Il est " + heure + " heures et " + minutes + " minutes "},"site_id":  msg.payload.site_id };
return msg;
1 Like

Instead of that, you could use the neater:

`Il est ${heure} heures et ${minutes} minutes `

Note the back-ticks instead of quotes.

1 Like

For this to work I only had to remove the json node after the function node.
It is fine now.
THANK YOU very much. :grinning:

1 Like