Pull current time into AlexaSpeak

Hi,
I have a loop timer that sends alexaspeak messages to my sons echo every 10 minutes until his door is open in the morning. I'm using a template node with the code below that sends the payload to the Alexa Routine node that plays it on my sons echo. I'm wanting to pull the current time in message. Is there a way to do this?

<speak>    
<s><voice name="Amy">Shawn it is (**CURRENT TME**), you need to wake up and get ready for school. </voice></s>
</speak>

Yes you can do it in a change node with Jsonata

[{"id":"3e74806.62c288","type":"change","z":"7760f563.ea0324","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"'<speak><s><voice name=\"Amy\">Shawn it is ' &\t($substring($substringAfter($now(), \"T\"), 0 , 5)) &\t', you need to wake up and get ready for school.<voice></s></speak>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":220,"y":340,"wires":[["b7b75c67.b4beb"]]}]

or in the templete with {{payload}}

@E1cid I copied your change node, but when I test it it's saying that is having trouble accessing my simon says skill? Sorry still new to node-red, but starting to understand more.

[{"id":"72b4d1f8.d8b33","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"1b744803.e51308","type":"change","z":"72b4d1f8.d8b33","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"'<speak><s><voice name=\"Amy\">Shawn it is ' &\t($substring($substringAfter($now(), \"T\"), 0 , 5)) &\t', you need to wake up and get ready for school.<voice></s></speak>'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":120,"wires":[["85df7e9.593c08"]]},{"id":"85df7e9.593c08","type":"alexa-remote-routine","z":"72b4d1f8.d8b33","name":"","account":"cb7f4bd7.16ead8","routineNode":{"type":"speakAtVolume","payload":{"type":"regular","text":{"type":"msg","value":"payload"},"volume":{"type":"num","value":"10"},"mode":"set","devices":["G000MW06722207P0"]}},"x":610,"y":120,"wires":[[]]},{"id":"d5b4a0b9.1b30a","type":"inject","z":"72b4d1f8.d8b33","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["1b744803.e51308"]]},{"id":"cb7f4bd7.16ead8","type":"alexa-remote-account","z":"","name":"","authMethod":"proxy","proxyOwnIp":"192.168.1.170","proxyPort":"3456","cookieFile":"fileauth","refreshInterval":"3","alexaServiceHost":"pitangui.amazon.com","amazonPage":"amazon.com","acceptLanguage":"en-US","userAgent":"","useWsMqtt":"on","autoInit":"on"}]

The routine node does not like the SSML mark up

Try without

[{"id":"c48433c6.4ac1a8","type":"change","z":"4fa1e6b8.1bbb5","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"'Shawn it is ' &\t($substring($substringAfter($now(), \"T\"), 0 , 5)) &\t', you need to wake up and get ready for school.'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":120,"wires":[["a149702a.de223"]]}]

If you select custom, you can then feed a object like below and set type as ssml. Then i think it will accept ssml mark up.

  • { type: 'speak', payload: { type: 'regular', text: 'Hello!', devices: ['My Echo']}
    or
  • { type: 'speakAtVolume', payload: { type: 'regular', text: 'Hello!', volume: 50 devices: ['My Echo']}
  • type: regular , ssml , announcement

That was it! I don't necessarily need the SSML, but is there a way to use standard time versus military time?

If you add the node-red-contrib-simpletime node, and replace the change node with a template node, you can format the time however you wish.
(not tested with the Alexa node)

time

[{"id":"68f6c3ee.fba57c","type":"inject","z":"bf304132.09ed3","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":120,"wires":[["a2fb5476.42d308"]]},{"id":"ac4401c.6a349","type":"template","z":"bf304132.09ed3","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<speak><s><voice name=\"Amy\">Shawn it is {{myhourpm}}.{{myminute}}{{mypm}}, you need to wake up and get ready for school.<voice></s></speak>","output":"str","x":440,"y":120,"wires":[["d4d010de.9aeac"]]},{"id":"d4d010de.9aeac","type":"debug","z":"bf304132.09ed3","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":120,"wires":[]},{"id":"a2fb5476.42d308","type":"simpletime","z":"bf304132.09ed3","name":"","mydate":true,"myymd":true,"myyear":true,"mymonth":true,"mymonthn":true,"mydom":true,"mydoy":true,"myday":true,"myhourpm":true,"myhour":true,"mytime":true,"mytimes":true,"myminute":true,"myminutes":true,"mysecond":true,"mymillis":true,"myepoch":true,"myrawdate":true,"mypm":true,"x":290,"y":120,"wires":[["ac4401c.6a349"]]}]
[{"id":"eb96e085.368d5","type":"change","z":"7760f563.ea0324","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"'Shawn it is ' &\t$fromMillis($millis(),\"[h]:[m]\") &\t', you need to wake up and get ready for school.'","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":500,"wires":[["b7b75c67.b4beb"]]}]

You sounded like the military type. lol

Paul you can format the date/time in JSONata as you wish, I find it's simpiler than using Javascript and no need to install another node.

Yes, and not forgetting that moment is now available to use in the change node (would that handle daylight saving better?)

Ooh, is that in 1.2? I haven't updated yet.

It was introduced in ver 1.1, so yes.
See Formatting times & dates with moment.js examples

Missed that, i have been on JSONata site learning the functions and syntax. So that is a node-red extension to jsonata, as no mention on their website.

It's the moment.js module that has been added to node-RED core, but at this time it can only be accessed through a change node. I'm hoping that eventually we'll be able to also access it through a function node as it will cut down the amount of javascript that I use to format date/times.

I also tried that, but the more I read - the less I understand about jsonata :grimacing:

1 Like

Cheers for info, i will add that to look at list.

LOL I'm not, but my son is planning on going to the military after high school. Thank you for the help!

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