How to triggers at event time coming

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:

[{"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":[[],[]]}]

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

Hi @jbudd,

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

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.

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

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.

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

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

Hi @Colin ,

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

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

Cron plus

Demo flow...

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

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

image

Demo flow (use CTRL+I to import)

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

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:

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

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

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

Demo flow...

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

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.

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)

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