Cron Rule Help

  • Platform information:

    • Hardware: RPi 3B
    • OS: Openhabian 2.5
    • openHAB version: 2.5
  • Issue of the topic:
    I am looking for a solution for controlling Shelly relays and having the ability to turn them on and off in 5 minute intervals per hour. I need to be able to run a fan for 5 minutes at a time and shut it off for a period of time before I run it again. The problem is I need to do this at least 1 time per hour. Shelly devices don’t allow you to put in more than so many entries to their internal scheduler.

I set up and configured the Time Line Picker program for Openhab and it appears to be working correctly. I’m just looking at being able to break my timeline down to 5 minute intervals instead of 15 minute intervals as it is by default.

I couldn’t decipher the rules file to figure out what I needed to change in order to do this nor could I find where it was already explained on the forum.

Any help is greatly appreciated!!



@tose – I did see your responses about this but I have not seen anything stating that this is not possible or what would need to be modified to make this happen.

Do you have any suggestions for me here?



Unfortunally no. The main concept of timeline picker is the fixed division of the day into intervals.
My approach is 96 intervals (15min). I think this is a good compromise to make the usage clear and to serve as many scenarios as possible. Changeing this approch is a big task and needs a new possibility for setting up. For 5min intervalls the day has 288. This is not so nice in the UI.

I have applications that need to be more precise. In this case I use the timeline picker and the associated item as a gate to control my real items with another rule that is triggered when the associated item is changed. Is this a way for you?

My way:
fan_gate_item = ON
–> triggered a rule: fan.item = ON for 5min, OFF for 5min, ON for 5min, … (loop in a rule)
fan_gate_item = OFF
–> triggered the same rule as befor: stop the loop, fan.item = OFF

In a real scenario i would look how often the the fan is running. This example is blocking a task and in case of a restart of OH …? It’s quick but perhaps its better to run a rlue every 5min and look for the fan_gate_item. You can store the last switch point for your real fan item in an object. This is more complex but i think it’s clear.

Thanks for the quick response! I couldn’t agree with you more about the current time interval for most folks and the case use in the UI. That makes a lot of since.

I am very green with OH programming and have been out of programming for quite some time outside of OH. But that logic does make since to me.

So I just looked at my records and I need this to be triggered to run every 15 minutes but for only 5 minutes at a time 24 hrs per day 7 days a week. I grow gourmet mushrooms and they need proper air exchange which requires running a fan. I could run the fan constant but that really is over kill. That’s where this rule comes into play. :slight_smile:

What would that logic look like in OH? Is that simpler to do via CRON?

Thanks for your help!


Well after a little digging on this end on the forum I think I came up with a solution… I can use the built in Auto Off from the Shelly device to turn the fan off after 300 seconds and use the following rule to trigger the fan On with Cron.

rule “Grow Room Fan”  
Time cron “0 0/12 0 ? * * *”
logInfo("Grow Room Fan", "The rule triggered")

Any advice on if this will work is appreciated.

Thanks again for all of your work on the Time Line Picker add on. It is a great addition to OH!


I think whis is a better aproach for this static usecase.

Is Channel13 your defined item? I myself set quotes in sendCommand and you must substitute the 12 with 15 for 15 minutes in your trigger line.

sendCommand("Channel3", ON)

Channel3 is the defined item. I actually made another adjustment to 12 minutes instead of 15. Forgot to update this.

Thanks for checking that!!


Well, I can’t seem to figure out why my rule isn’t running. I don’t have any entries relating to the rule in my error logs either.

Any ideas are appreciated!



So here is a log file I get from my rule…

2020-07-05 11:23:55.122 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'GrowRoomFan.rules' has errors, therefore ignoring it: [8,6]: no viable alternative at input '“'

Here is my updated rules file:
mport org.joda.time.*
import org.openhab.core.library.types.*
import org.openhab.core.library.types.PercentType
import org.openhab.core.library.items.SwitchItem
import org.openhab.model.script.actions.*
import org.openhab.model.script.actions.Timer

rule “Growroom fan”
Time cron “0 0/12 0 ? * * *”
logInfo(“Growroom”, “The rule triggered”)
sendCommand(channel3, ON)

Here is my items file:

Group gTimepicker
Group gTimepickerObserver
String TimelineHelper “[%s]” (gTimepicker)
String TransferItem1 “[%s]” (gTimepicker)


Number:Temperature Growroom_BMS_T “Growroom Temperature [%.1f °F]” <temperature$
Number:Dimensionless Growroom_BMS_H “Growroom Humidity [%.1f %unit%]” <humidity$
Switch channel1 “Humidifier” { channel="mqtt:topic:openhab:relays:ch$
Switch channel2 “Intake Fan” { channel="mqtt:topic:openhab:relays:channe$
Switch channel3 “Exhaust Fan” { channel="mqtt:topic:openhab:relays:chann$
Switch channel4 “Channel4” { channel=“mqtt:topic:openhab:relays:channel4” }


So after reviewing this one more time I figured it out…

If anyone stumbles accross this down the road…

When I created my rules, I copied and pasted in a few things in quotation marks… By deleting everything that was in quotation marks and hand typing in things, it is now working. Crazy!


That’ why we ask people to use code fences in this forum.
These look the same -
rule “Growroom fan”
rule “Growroom fan”


rule “Growroom fan”
rule "Growroom fan"

They are not the same, and only one works properly.

1 Like