Cron time conditions - Intro and how to set them up

With our release of time conditions, we wanted to stay true to our tinkering roots and add an advanced time condition configuration through cron expressions. If you are familiar with these: this is exciting, right :star_struck:? And if you have never heard about them, don’t worry, as you can read more about them below and you’ll be using them in no time!

What’s a cron expression?

A cron expression is a string that represents a schedule when you want to execute a routine. For example in this image from crontab guru we are showing you that 5 8 * 4 6,7 means “At 08:05 on Saturday and Sunday in April.”

Click here to go to this example and have a play! https://crontab.guru/#5_8_*_4_6,7

Why are they powerful?

You are not limited by what you can setup in the UI, you can create a really customised time expression that will run your logic only at times of the day/week/month/year that you specify.

You can setup a condition that sets a schedule for your routine to only run on Saturdays in February, March and April. Or only run something the 15th of every month. You can be very specific with your cron expressions! :nerd_face: :alarm_clock:

In Apilio, you’ll be able to specify the cron expression plus a duration: this sets the length of the timeframe when you want your condition to be valid. For example, to allow a logicblock to operate every Monday at 9AM for 1 hour. This means that it will be allowed between 9AM and 10AM, on every Monday.

How do I set a time condition with a cron expression in Apilio?

These are a time condition, so head over to your condition section in Apilio:

  1. Go to https://app.apilio.com/conditions
  2. Choose new condition
  3. Choose type “time”
  4. From the dropdown, you’ll select “Advanced setup with cron”
  5. Fill in the details. You can use an external cron expression builder to write the expression. Enter a duration for your condition as well. Don’t forget to enter a name! You’ll be using this name in your logicblock to refer to this condition.
  6. Click save and you are done :slight_smile:

As is an advanced setup that is only available for our pro-plan users, and those of you who are on your trial (as you get to test everything Apilio can do for you).

Free cron expression builders

We have used crontab guru for these examples:

But there are many others out there:
http://www.cronmaker.com/

Any further questions?

If you have any other questions, please leave them below

:bulb: Want to learn more about conditions? Have a look at these articles:

1 Like

Is there a way to use duration with the Cron expressions? So if I did a cron statement like this, to run every 5 mins betweeen 3pm and 5pm, could that be understood by apilio?

Essentially, I want to do the “between” expression from cron instead of using the duration feature you used above.

Yes you can! Select “Time frame”, and the type of time condition is “Advanced setup with cron”. This lets you enter both a cron expression and a duration :slight_smile:

I’m only confused because I still have to enter a duration with the Apilio entry, instead of just via Cron.

I want to create a condition for winter months (Oct to March). This is my cron expression for winter months, but I still have to enter 23:59 for duration on Apilio. From what you know @anna.penamartinez, is this correct? I just want this condition to be true for any winter month

What is the duration setting used for?

My understanding is:

  • cron expression specifies an instant of time
  • duration specifies for how long the condition will be TRUE after that instant

So if you have a cron expression like “* /10 * * * *” that equals ‘at every 10th minute of the day’ (0:00, 0:10, 0:20, 
 23:40 and 23:50) and you set duration to 1 minute, the condition will be true from 0:00-0:01, 0:10-0:11, etc.

See this example

If you use the condition just as a trigger, then the duration is useless, and that’s why that option is not shown if you select ‘time event’ instead of ‘time frame’ as type o condition.

1 Like

It looks to me like they’ve removed the duration input textbox and it’s no longer an option, but thanks for the every 10 minute example. I used the brute force 10,20,30
 method. I like the shorthand better.

The duration input textbox appears when you select ‘Time frame’, but it is not there when you select ‘Time event’. That makes sense.

With regards to ‘cron expressions’ google for what you need and you wil most likely get the right cron expression in the first resut.

With regards to your question, since your cron refers to every minute, duration should be 60 seconds.

Aha! Thanks for the update. Time event actually works for me as I am checking the values of boolean variables every 10 minutes.

Hi @drdlund!

Just to add to what @teknofilo has explained:

Cron expressions can be set to a specific event or as a timeframe, like any other time condition.

Time events happen at a specific moment in time (for example, at 10AM), and they don’t need a duration. They are just an instant.

Time frames need durations, so you can setup how long you want your condition to be true for. For instance, you could setup a cron expression that is true every Monday, every hour, for 5 minutes. That’s when the duration comes in :slight_smile:

So in your case, you are checking a boolean every 10 minutes, you only need the time event as you are checking on that specific instant every 10 minutes, so all good! :+1:

1 Like

All good, thanks. It took a little trial and error, but I finally got things set up right. Your “let’s go for a walk” example helped a lot. By following it I could finally see how the apilio and ifttt interactions must be set up to work together.

This stuff is really cool! I just wish ifttt wasn’t $5 per month. That may be the deal breaker for me because I can do what I need to for free with Yolink native apps.

2 Likes

Maybe we could connect to the YoLink API? :thinking:

That would be cool, but it still wouldn’t solve my dilemma of choosing between a free solution and one that costs me $60/year for ifttt plus the much more reasonable subscription for apilio

1 Like

Yes, clearly it depends how much you use IFTTT :thinking: