Cron time seconds?

Hi Everyone

Is it possible too run a cron time in seconds i have tried but cant get it too work

say i wanted a rule to fire every 30 seconds

rule "Test"
when
    Time cron "0/10 0 0 ? * * *" // Every 10 seconds
then
    logInfo("TEST RULE RAN", "TEST")
end
1 Like

I have one 30 second cron which is working fine in my file for testing rule stuff.

Try this expression:

Time cron "0/30 0/1 * 1/1 * ? *"

Edit:

Free Online Cron Expression Generator and Describer - FreeFormatter.com says it does the following:

Every 30 seconds starting at second 00, every minute starting at minute :00, every hour, every day starting on the 1st, every month

I am not sure about the minute stuff.

0/30 0 0 ? * * * should theoretically work too, but that’s the syntax you mentioned above as not working.

1 Like

0/30 0 0 ? * * *
or
0,30 * * ? * * *

I think i have read somewhere about a problem with the comma syntax in rules some time ago.
If i find the topic again, i will ink it here.

Edit:

I was wrong. The rpoblem was with more than one cron expression as a rule trigger. Reference: Multiple Cron expressions - #6 by FrankR

1 Like

@Confectrician

That’s for that your version worked I had mine off a cron maker site (the one you linked actually) normally works fine

@hr3

Thanks for that I will also try your version

1 Like

@hr3

I also tried

Time cron "0 0,30 0 ? * * *"

for a rule too fire on 00 and 30 minutes does not work

but

Time cron "0 0/30 * 1/1 * ? *"

Seems too work

I have updated my answer about the comma syntax.
The problem i had in mind was different.
Comma should work theoretically. (Not tested tough)

You also have the hour (= 0) specified, which means it triggers every night at 0:00 and 0:30

If you want to trigger everry 30 minutes, you can specify these cron triggers:

Time cron "0 0,30 * ? * * *"

which means every hour with minute 0 and minute 30

or

Time cron "0 0/30 * ? * * *"

which means every hour with minute 0 and then every 30 minutes

If you specify with 10 minutes, the difference is more visual:

“0 0,10 * ? * * *” means every hour with minute 0 and 10 (0:00, 0:10, 1:00, 1:10,…)
“0 0/10 * ? * * *” means every hour with minute 0 and then every 10 minutes (0:00, 0:10, 0:20, 0:30, 0:40, 0:50, 1:00, 1:10,…)

2 Likes

Thanks for this well explanation. :slight_smile:

It mostly isn’t that difficult, but i have to dig into it myself everytime i have to do some cron stuff.
It’s a challenge every time if you don’t work frequently with it. (At least thats my impression. :smile: )

That generator just produces bogus results. There is one star too many, this is the one you need:

“0/10 * * ? * *”

The examples on the site do look right. It’s only 6 fields: seconds, minutes, hours, days, months, years. The generated expression has 7.

You are wrong here. openHAB uses Quartz cron and not the normal Linux/GNU/Bash cron.
Thus the generator is producing correct output. We need 7 fields.