# Pull current time into AlexaSpeak

**URL:** <https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005>\
**Category:** General\
**Created:** [9 October 2020 15:09 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005 "2020-10-09T15:09:09Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [9 October 2020 15:09 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/1 "2020-10-09T15:09:09Z")

</div>

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?

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

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 16:10 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/2 "2020-10-09T16:10:09Z")

</div>

Yes you can do it in a change node with Jsonata

```auto
[{"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}}`

---

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [9 October 2020 16:44 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/3 "2020-10-09T16:44:29Z")

</div>

@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.

```auto
[{"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"}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 18:17 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/4 "2020-10-09T18:17:02Z")

</div>

The routine node does not like the SSML mark up

Try without

```auto
[{"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`

---

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [9 October 2020 18:54 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/5 "2020-10-09T18:54:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [9 October 2020 19:11 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/6 "2020-10-09T19:11:04Z")

</div>

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](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2fd6cb59cbb271ad9cac33be13f5ac055b9a909.jpeg)

```auto
[{"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"]]}]

```

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 19:28 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/7 "2020-10-09T19:28:21Z")

</div>

```auto
[{"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

> **[Date/Time functions · JSONata](https://docs.jsonata.org/date-time-functions#frommillis)**
>
> \## \`$now()\`

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 19:33 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/8 "2020-10-09T19:33:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [9 October 2020 19:37 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/9 "2020-10-09T19:37:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 19:38 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/10 "2020-10-09T19:38:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [9 October 2020 19:39 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/11 "2020-10-09T19:39:49Z")

</div>

It was introduced in ver 1.1, so yes.  
See [Formatting times & dates with moment.js examples](https://discourse.nodered.org/t/formatting-times-dates-with-moment-js-examples/29553)

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 19:44 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/12 "2020-10-09T19:44:51Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Paul-Reed](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/paul-reed/32/66906_2.png) [@Paul-Reed](https://discourse.nodered.org/u/Paul-Reed)\
**Post date:** [9 October 2020 19:49 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/13 "2020-10-09T19:49:33Z")

</div>

> [@E1cid](#):
>
> So that is a node-red extension to jsonata

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.

> [@E1cid](#):
>
> i have been on JSONata site learning the functions and syntax

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

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [9 October 2020 19:52 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/14 "2020-10-09T19:52:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![CAL37](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@CAL37](https://discourse.nodered.org/u/CAL37)\
**Post date:** [9 October 2020 22:00 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/15 "2020-10-09T22:00:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 October 2020 22:00 UTC](https://discourse.nodered.org/t/pull-current-time-into-alexaspeak/34005/16 "2020-10-23T22:00:13Z")

</div>

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