IFTTT applet to use sunset/sunrise times as an additional if/then trigger for when to run an action. You can enable the original IFTTT applet here. Note that this is hardcoded for Dallas, TX.
IFTTT made filter code a premium feature, so for the benefit of the IFTTT community, I am open sourcing the code for this applet.
You can easily adapt this template to limit any typical IFTTT action to happen between any hour and/or supported SunCalc time: ['sunrise', 'sunset', 'sunriseEnd', 'sunsetStart', 'dawn', 'dusk', 'nauticalDawn', 'nauticalDusk', 'nightEnd', 'night', 'goldenHourEnd', 'goldenHour']
After installation, two parts should be customized:
- GPS coordinates for your location
An adapted version of SunCalc is used to calculate sunset/sunrise times based on the GPS coordinates
// Customize for your geolocation
// Dallas, TX
var myLatitude = 32.8;
var myLongitude = -96.8;
- IFTTT-based code for when to skip the action. For example, in this code, the action is skipped during daylight hours.
var todaySunlight = <any>SunCalc.getTimes(triggerDate, myLatitude, myLongitude);
// Customize with getTimes properties, sunrise, dusk, etc.
if (triggerDate > todaySunlight.sunrise && triggerDate < todaySunlight.sunset) {
WemoLightSwitch.attributeLsOnDiscrete.skip("Skipped during sunlight hours");
}
- If you want to use specific hours (i.e., not sunset/sunrise), here is an example of how that can be done. The
filter.js
code can be adapted to support any variation/combination you'd like.
var currentHour = Meta.currentUserTime.hour();
if (currentHour >= 20 || currentHour < 5 ) {
// add action here
}
- I experienced poor latency (up to 10 minutes in some cases) from IFTTT with this applet and moved on to other services
- There is a small bug in the Suncalc library, affecting the time calculation in some instances having to do with daylight savings time.
See: mourner/suncalc#107
- Create a new private applet on IFTTT Platform.
- Set up a new applet using this guideline.
-
Copy the raw TypeScript code into the
Filter code
box, and make any needed changes (see Description). -
Publish and test!
For bug reports and feature requests, open issues. 🐛
Have an idea? Found a bug? Contributions and pull requests are welcome.
I try to reply to everyone needing help using these projects. Obviously, this takes time. However, if you get some profit from this or just want to encourage me to continue creating stuff, there are few ways you can do it: