Cron time trigger for rules?

Hi folks, I have a few Cron time triggers already and they all work great (single time trigger every day, i.e. 5am etc).

I now want to trigger a rule every X minutes, but it doesn’t seem to work. Rule triggers at exactly midnight each night though…

var power24

    rule "24hr_power"
    when
    	Time cron "0 0/15 0 ? * * *"
    then
    	var Number power24 = Solar_Power.sumSince(now.minusDays(1), "rrd4j")
    	Solar24Power.postUpdate((power24 / 144 * 24).intValue)
    end

According to the Cron time generator that i’m using : “0 0/15 0 ? * * *” should be ‘every 15 minutes’, but it doesn’t trigger the rule, except at midnight… Does OH not accept these minute repeating Cron triggers?

Cheers!

The cron generater I just gives this for every 15 mins 0 0/15 * 1/1 * ? * so I guess the 1/1 means something

http://www.cronmaker.com/?1

openHAB uses quartz scheduler
https://www.freeformatter.com/cron-expression-generator-quartz.html
and the expression seems correct.

What makes you think the rule only runs at midnight?

Without testing I would say your cron statements triggers at 00:00, 0015, 00:30 and 00:45! The third figure fixes it to the first hour of the day!

Thanks for the feedback guys!

I was using the https://www.freeformatter.com/cron-expression-generator-quartz.html generator.

You are right, when i look at it, i selected ‘Every 15 minutes’, however, when i ask to see ‘next execution’, it is just 00:00, 00:15, 00:30, 00:45.

Here is my Log:
2020-04-22 00:00:00.990 [vent.ItemStateChangedEvent] - Solar24Power changed from 267 to 151
2020-04-22 00:00:30.552 [vent.ItemStateChangedEvent] - Dusk_Time changed from 2020-04-21T20:06:00.000+0100 to 2020-04-22T20:08:00.000+0100
2020-04-22 00:00:30.560 [vent.ChannelTriggeredEvent] - astro:sun:home:morningNight#event triggered START
2020-04-22 03:30:00.004 [vent.ChannelTriggeredEvent] - astro:sun:home:morningNight#event triggered END
2020-04-22 03:30:00.007 [vent.ChannelTriggeredEvent] - astro:sun:home:astroDawn#event triggered START
2020-04-22 04:24:00.008 [vent.ChannelTriggeredEvent] - astro:sun:home:nauticDawn#event triggered START

As you can see, the rule triggered at 00:00 and the value was updated. It may be that the rule triggered at 00:15 etc as well, but the value didn’t update as there was no power draw at that time.

I just saw that on the ‘hours’ tab, the default on that generator is ‘00:00’ hour only, changed it to ‘Every hour’ and the new cron is 0 0/15 * ? * * *

I will try that!

Cheers!

2 Likes

For testing purposes the use of a logInfo line would help.

Yes, just added that. Will see what happens!

I updated the Cron expression to “0 0/15 * ? * * *”, but still not seen any updates. Will look to see what the Log says now that i’ve put an loginfo line into the rule.

Thanks All! This is working now. The Cron trigger was only for every 15 minutes during the first hour of the day, good spot! Also, the tip about adding the loginfo really helped in identifying what was happening

Many thanks! :slight_smile:

1 Like