You can add filter code to any Applet to include a cooldown period, where it won't fire for a specific time after running.
For example, let's say you have an Applet which sends you a notification whenever you enter or exit your home:
To prevent the Applet from running again if you need to go back inside to collect something, we will add a 15 minute cooldown period during which the Applet will not fire.
Adding Filter code
Filter code is additional JavaScript logic which gives you much more control over the functionality of your Applets. To add Filter code, click the + below your trigger and click Filter code.
Start by adding the following filter code:
if (Meta.triggerTime && Meta.previousTriggerTime) {
const minutesSinceLastRun = Meta.triggerTime.diff(Meta.previousTriggerTime, 'minutes');
if (minutesSinceLastRun < 15) {
Service.action.skip();
}
}
Now, you will need to update the following line so it matches the action you are using.
Service.action.skip();
In our Location -> Notification example, we need to enter the function which will skip our notification action. This can be found in the right side of the filter code editor, under Actions. It is the function ending in skip()
:
After inserting this line, our final filter code becomes:
if (Meta.triggerTime && Meta.previousTriggerTime) {
const minutesSinceLastRun = Meta.triggerTime.diff(Meta.previousTriggerTime, 'minutes');
if (minutesSinceLastRun < 15) {
IfNotifications.sendNotification.skip();
}
}
Note: If you're using another action, this line should be different and reflect your action.
Changing the cooldown period
In our example above, we have a 15 minute cooldown period, however we can alter this by changing the value in the following line:
if (minutesSinceLastRun < 15) {
If we want a cooldown period of 1 hour, this would become:
if (minutesSinceLastRun < 60) {
If we want a cooldown period of 3 hours, this would become:
if (minutesSinceLastRun < 180) {
Learn more about Filter code on our How to Add Filter Code article.