Switch lights at certain times
For performing tasks at specified times in Node-Red we can use the Bigtimer library.
Add new libraries to Node-Red thru the pulldown menu in the upper right hand corner and pick the option Manage palette. On that dialog, on the install tabpage, you can search for new libraries.
The big timer node has many possible settings such as switching at sunset/sunrise and it can be configured to only switch at certain days.
For my vivarium I only use the time and maybe sunrise/sunset, although most kept reptiles come from regions near the equator so the difference in length of day are really minimal.
I added the big timer to the previously made flow as shown above, using the settings as shown below:
- On Time: Sunrise
- Off Time: Sunset
- Latitude: 51.974911
- Longtitude: 5.911681
This location is a very famous WW2 bridge in The Netherlands…
- ON Msg: 1
- OFF Msg: 0
When deployed the big timer node will output a 1 or 0 every minute to the function node which changes it into the correct JSON format which then sends it to the MQTT broker.
Note that the On Time can only be set to quarters. If you need to turn the relay on at 11:59 until 12:05 this can be done easily by using the On/Off Offset fields:
This way the timer will turn ON at 1 minute before 12:00 and OFF at 9 minutes past 12:00