# How to triggers at event time coming

**URL:** <https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422>\
**Category:** General\
**Created:** [6 March 2022 00:39 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422 "2022-03-06T00:39:19Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 00:39 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/1 "2022-03-06T00:39:19Z")

</div>

Hi Everyone,

Anyone can help and advise how to triggers play mp3 at event time coming (e.g sunrise/sunset time). I need do trigger to play mp3 once event is coming.

I can play mp3 to cast with inject manually. but i can not do trigger sunrise/sunset time of the result http request to automatic play mp3.

Is it need time reference to automate this flow? still confuse which node that will be use for this flow

Let you know the flow below:

```auto
[{"id":"e785afc51dbac133","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"7a7e32fbaf64babd","type":"inject","z":"e785afc51dbac133","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":170,"y":260,"wires":[["2980903373f6c1c2"]]},{"id":"2980903373f6c1c2","type":"http request","z":"e785afc51dbac133","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.aladhan.com/v1/timings?latitude=40.7145672345337&longitude=-74.00297622685953&method=99&methodSettings=20.0,null,18.0","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":350,"y":260,"wires":[["7f406d3aaab5539a"]]},{"id":"8e932711aecb661c","type":"debug","z":"e785afc51dbac133","name":"Sunset","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.sunset","targetType":"msg","statusVal":"payload.data.timings.Sunset","statusType":"auto","x":760,"y":300,"wires":[]},{"id":"e0cd13c63762cb24","type":"debug","z":"e785afc51dbac133","name":"Sunrise","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload.sunrise","targetType":"msg","statusVal":"payload.data.timings.Sunrise","statusType":"auto","x":760,"y":200,"wires":[]},{"id":"f29b01aee6d0bb9d","type":"cast-to-client","z":"e785afc51dbac133","name":"","url":"","contentType":"","message":"","language":"en","ip":"","port":"","volume":"","x":630,"y":440,"wires":[[]]},{"id":"7f406d3aaab5539a","type":"function","z":"e785afc51dbac133","name":"processing","func":"msg.payload.sunrise = msg.payload.data.timings.Sunrise;\nmsg.payload.sunset = msg.payload.data.timings.Sunset;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":550,"y":260,"wires":[["e0cd13c63762cb24","8e932711aecb661c"]]},{"id":"b14bcfd164ae1b10","type":"timecheck","z":"e785afc51dbac133","name":"","time":"","x":310,"y":420,"wires":[[],[]]}]

```

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [6 March 2022 00:55 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/2 "2022-03-06T00:55:26Z")

</div>

The Cronplus node can inject a message at various solar event times such as sunrise and sunset.

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 01:31 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/3 "2022-03-06T01:31:53Z")

</div>

Hi @jbudd,

is cronplus can inject a various event from http request result? I need triggers not only for solar event time.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2022 07:13 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/4 "2022-03-06T07:13:59Z")

</div>

> [@mrrobot](#):
>
> can inject a various event from http request result?

I don't understand what you mean by that. The node will send a message at the scheduled time, which you can then use to do whatever you like.

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 07:45 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/5 "2022-03-06T07:45:59Z")

</div>

Hi @Colin,

What I means is need triggers play mp3 at event time coming from http request returns an object.

an object is not only solar event times. Let you know the flow below:

Is it need time reference to automate this flow? Please help the node or function that will be use for this flow

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2022 08:16 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/6 "2022-03-06T08:16:48Z")

</div>

> [@mrrobot](#):
>
> What I means is need triggers play mp3 at event time coming from http request returns an object.

Do you mean that the time at which it is to trigger must be configured by data received in an http request? If so then please look at the readme for the node and you will see that it can be configured via messages sent to it.

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 08:47 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/7 "2022-03-06T08:47:00Z")

</div>

Hi @Colin,

Yes. Could you suggest which node that will be use? so I can read it.

Please help how to revise the flow for this trigger

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [6 March 2022 08:49 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/8 "2022-03-06T08:49:28Z")

</div>

The node we have been talking about. node-red-cron-plus.

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 09:08 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/9 "2022-03-06T09:08:02Z")

</div>

Hi @Colin ,

Ok. Is it will be the flow like this ? The output cron-plus going to cast node

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0e599e79aaa31e3df8238f35b61705acb95c9f9a.png)

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2022 09:16 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/10 "2022-03-06T09:16:15Z")

</div>

The point of mentioning cron plus was you DONT need to go to the internet for sunrise and sunset times - the cron plus node can do this.

Flow  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/7/0734e7f76de23eec90d79f34b42bfe54a2648ba9.png)

Cron plus

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/5/f/5f6f396ed0a88a0a9d8e1d8f2e2b6d92839dc6d8.png)

Demo flow...

```auto
[{"id":"4b1b8f5d50904d86","type":"cronplus","z":"e785afc51dbac133","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[{"name":"sunrise","topic":"sunrise","payloadType":"json","payload":"{ \"url\": \"https://www.trekcore.com/audio/doors/tng_chime_clean.mp3\" }","expressionType":"solar","expression":"0 * * * * * *","location":"40.7145672345337 -74.00297622685953","offset":"0","solarType":"selected","solarEvents":"sunrise"},{"name":"sunset","topic":"sunset","payloadType":"json","payload":"{ \"url\": \"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp3\" }","expressionType":"solar","expression":"0 * * * * * *","location":"40.7145672345337 -74.00297622685953","offset":"0","solarType":"selected","solarEvents":"sunset"}],"x":340,"y":440,"wires":[["3a6e0f35b47ca978"]]},{"id":"049c2da1a3024c8e","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunrise","payloadType":"str","x":140,"y":400,"wires":[["4b1b8f5d50904d86"]]},{"id":"e00d2d2ca8497195","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunset","payloadType":"str","x":150,"y":480,"wires":[["4b1b8f5d50904d86"]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2022 09:19 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/11 "2022-03-06T09:19:32Z")

</div>

Alternatively, you can set multple outputs on cron-plus to do it more "visually"...

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/e/ae5f63916756eaadc8b063abdf60b4e8dd41543b.png)

Demo flow (use `CTRL+I` to import)

```auto
[{"id":"4b1b8f5d50904d86","type":"cronplus","z":"e785afc51dbac133","name":"","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"fanOut","outputs":4,"options":[{"name":"sunrise","topic":"sunrise","payloadType":"default","payload":"","expressionType":"solar","expression":"0 * * * * * *","location":"40.7145672345337 -74.00297622685953","offset":"0","solarType":"selected","solarEvents":"sunrise"},{"name":"sunset","topic":"sunset","payloadType":"default","payload":"","expressionType":"solar","expression":"0 * * * * * *","location":"40.7145672345337 -74.00297622685953","offset":"0","solarType":"selected","solarEvents":"sunset"}],"x":340,"y":440,"wires":[["3a6e0f35b47ca978"],["ec4b65c1cd5a8016"],[],[]]},{"id":"3a6e0f35b47ca978","type":"cast-to-client","z":"e785afc51dbac133","name":"sunrise sound","url":"https://www.trekcore.com/audio/doors/tng_chime_clean.mp3","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":620,"y":400,"wires":[[]]},{"id":"049c2da1a3024c8e","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunrise","payloadType":"str","x":140,"y":400,"wires":[["4b1b8f5d50904d86"]]},{"id":"e00d2d2ca8497195","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunset","payloadType":"str","x":150,"y":480,"wires":[["4b1b8f5d50904d86"]]},{"id":"ec4b65c1cd5a8016","type":"cast-to-client","z":"e785afc51dbac133","name":"sunset sound","url":"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":610,"y":460,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 09:41 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/12 "2022-03-06T09:41:53Z")

</div>

Hi @Steve-Mcl ,

Well understood. Already try it if the trigger is only solar event can work like charm.

But what I need is not only solar event times. that's why I need to go to the internet for various event time such as http request returns an object

How to use it with cron-plus ? and how to revise the flow for this trigger ?

Let you know the flow below:

```auto
[{"id":"e785afc51dbac133","type":"tab","label":"Flow 2","disabled":false,"info":"","env":[]},{"id":"7a7e32fbaf64babd","type":"inject","z":"e785afc51dbac133","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":270,"y":280,"wires":[["2980903373f6c1c2"]]},{"id":"2980903373f6c1c2","type":"http request","z":"e785afc51dbac133","name":"","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.aladhan.com/v1/timings?latitude=40.7145672345337&longitude=-74.00297622685953&method=99&methodSettings=20.0,null,18.0","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":450,"y":280,"wires":[["3cbfadbd1b3433a4","d7babb4cab4c483f"]]},{"id":"3cbfadbd1b3433a4","type":"cronplus","z":"e785afc51dbac133","name":"","outputField":"payload.data.timings.Sunset","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"fanOut","outputs":6,"options":[{"name":"schedule1","topic":"topic1","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule2","topic":"topic2","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule3","topic":"topic3","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"},{"name":"schedule4","topic":"topic4","payloadType":"default","payload":"","expressionType":"cron","expression":"0 * * * * * *","location":"","offset":"0","solarType":"all","solarEvents":"sunrise,sunset"}],"x":660,"y":280,"wires":[["e0f0489bc88db126"],["573cf6a9f8203270"],["adedf9f529118d77"],["89c9aa37f059507b"],[],[]]},{"id":"d7babb4cab4c483f","type":"debug","z":"e785afc51dbac133","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":140,"wires":[]},{"id":"e0f0489bc88db126","type":"cast-to-client","z":"e785afc51dbac133","name":"sunrise","url":"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":860,"y":180,"wires":[[]]},{"id":"573cf6a9f8203270","type":"cast-to-client","z":"e785afc51dbac133","name":"sunset","url":"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":850,"y":240,"wires":[[]]},{"id":"adedf9f529118d77","type":"cast-to-client","z":"e785afc51dbac133","name":"morning","url":"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":860,"y":300,"wires":[[]]},{"id":"89c9aa37f059507b","type":"cast-to-client","z":"e785afc51dbac133","name":"afternoon","url":"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":860,"y":360,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2022 09:51 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/13 "2022-03-06T09:51:05Z")

</div>

If you must go out to the internet for the timings, you need to set the schedular (cron-plus) dynamically.

Here is a demo...

![chrome_dDoaZ2vChD](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/3/031fe6abf940d6e923fcdf2c015bf90cdb03b082.gif)

_↑ Ignore the times, I am in a different timezone - should look normal for you)_

Demo flow...

```auto
[{"id":"7a7e32fbaf64babd","type":"inject","z":"e785afc51dbac133","name":"","props":[],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":530,"y":180,"wires":[["2980903373f6c1c2"]]},{"id":"2980903373f6c1c2","type":"http request","z":"e785afc51dbac133","name":"Get times","method":"GET","ret":"obj","paytoqs":"ignore","url":"https://api.aladhan.com/v1/timings?latitude=40.7145672345337&longitude=-74.00297622685953&method=99&methodSettings=20.0,null,18.0","tls":"","persist":false,"proxy":"","authType":"","senderr":false,"x":680,"y":180,"wires":[["7f406d3aaab5539a"]]},{"id":"7f406d3aaab5539a","type":"function","z":"e785afc51dbac133","name":"Create Schedules","func":"const now = new Date();\n\nlet sunriseHHMM = msg.payload.data.timings.Sunrise.split(\":\").map(e => Number(e))\nlet sunsetHHMM = msg.payload.data.timings.Sunset.split(\":\").map(e => Number(e))\n\nlet sunrise = new Date()\nsunrise.setHours(sunriseHHMM[0])\nsunrise.setMinutes(sunriseHHMM[1])\n\nlet sunset = new Date()\nsunset.setHours(sunsetHHMM[0])\nsunset.setMinutes(sunsetHHMM[1])\n\n//if next event has past, add 1 day to the time\nif (sunrise < now) {\n sunrise.setDate(sunrise.getDate()+1);\n}\n\nif (sunset < now) {\n sunset.setDate(sunset.getDate()+1);\n}\n\nmsg.payload = [\n {\n \"command\": \"add\",\n \"name\": \"sunrise\",\n \"topic\": \"sunrise\",\n \"expression\": sunrise,\n \"expressionType\": \"dates\",\n \"payloadType\": \"json\",\n \"payload\": {\n \"url\": \"https://www.trekcore.com/audio/doors/tng_chime_clean.mp3\"\n }\n },\n {\n \"command\": \"add\",\n \"name\": \"sunset\",\n \"topic\": \"sunset\",\n \"expression\": sunset,\n \"expressionType\": \"dates\",\n \"payloadType\": \"json\",\n \"payload\": {\n \"url\": \"https://www.trekcore.com/audio/computer/voice/transfercomplete_clean.mp\"\n }\n }\n]\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":850,"y":180,"wires":[["7f11a3ee9f40197a"]]},{"id":"7f11a3ee9f40197a","type":"cronplus","z":"e785afc51dbac133","name":"cron (dynamic)","outputField":"payload","timeZone":"","persistDynamic":false,"commandResponseMsgOutput":"output1","outputs":1,"options":[],"x":560,"y":240,"wires":[["4c91d39174bc639c"]]},{"id":"afa01256089061f5","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunrise","payloadType":"str","x":330,"y":200,"wires":[["7f11a3ee9f40197a"]]},{"id":"bfbe6c063e9ec457","type":"inject","z":"e785afc51dbac133","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"trigger","payload":"sunset","payloadType":"str","x":330,"y":260,"wires":[["7f11a3ee9f40197a"]]},{"id":"4c91d39174bc639c","type":"cast-to-client","z":"e785afc51dbac133","name":"cast","url":"","contentType":"","message":"","language":"en","ip":"192.168.1.19","port":"8009","volume":"","x":810,"y":240,"wires":[[]]}]

```

---

<div class="post-metadata">

**Author:** ![mrrobot](https://avatars.discourse-cdn.com/v4/letter/m/b38774/32.png) [@mrrobot](https://discourse.nodered.org/u/mrrobot)\
**Post date:** [6 March 2022 10:22 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/14 "2022-03-06T10:22:03Z")

</div>

Hi @Steve-Mcl

Let me try for the schedular dynamically. Is it will be auto play to cast once event time is coming?

If it's not then how to automate it? so we no need trigger node to play cast.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [6 March 2022 10:43 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/15 "2022-03-06T10:43:13Z")

</div>

The time strings are taken from your HTTP Request. They are converted to dynamic schedules in the function and injected into the CRON node. After that, the cron node will fire the event at the specified time.  
The HTTP Request must be made each day to get the next days times (sunrise and sunset change every day)

---

<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:** [5 May 2022 10:44 UTC](https://discourse.nodered.org/t/how-to-triggers-at-event-time-coming/59422/16 "2022-05-05T10:44:04Z")

</div>

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