Simple cron in rules files for Openhab
In this post i explain how to schedule task from rules file using cron.
Rules are triggered based on the what you specify in the “when” part.
It can either trigger by update of item or in specific time. For time scheduling is used Unix-like job scheduler called cron.
Create rules files in the Openhab configuration folder inside folder “rules”
Extension for this files is *.rules .File will look like this “example.rules”
Bellow are some examples what is the standard format of this file
Examples from my rule files.
Open Rollershutter every day 7:30 except winter months
rule "Morning Shutter" when Time cron "0 30 6 ? 3-10 *" then logInfo("rule Morning Shutter", "triggered") dinning_roller.sendCommand(95) get_state_dinningroller.postUpdate(dinning_roller.state.toString) end
Here is another example where i scheduled the task every day at 1AM or by clicking switch.
rule "Daily energy charts" when Item manualruletrigger received update or Time cron "0 1 0 * * ?" then .... end
And another to trigger rule every five minutes
rule "Every 5 minutes" when Time cron "0 */5 * ? * *" then .... end
Very good cron generator for Openhab expected format
Some versions of cron does not starts with seconds as Openhab format and also accepts “*” for day of the week which Openhab version does not accept. Have to use “?”