Triggering a rule in every First of a month/year at 0:00

How do I trigger a rule on every first of a month at 0:00. And on every first of a new year at 0:00. Is there any other way than a cronjob??


Why would a cron Time solution not suffice?

rule "Every first of the month "
	Time cron "0 0 0 1 * ? *"
	// do something


rule "Every first of January "
	Time cron " 0 0 0 1 JAN ? * *"
	// do something

Is this reliable???


When I update my rule with a cron job statement in it somtimes it started the cronjob somtimes i need to restart openhab2 completely??? Why? how can I force to start the cron job??

I’m not sure if that is related to the cron statement or something completely different altogether. My cron statements work fine without exceptions.

For this you could make to switches:

Switch Force1stMonth "Force first day of the month routine"
Switch Force1stYear "Force first day of the year routine"

And then change the rules:

rule "Every first of the month "
	Time cron "0 0 0 1 * ? *" or
	Item Force1stMonth received command
	// do something

(and similar for the other one)

If i Switch the switch on the cron is then restarted???

Either, Time cron or Item Force1stMonth receiving a command with fire the rule. The cron doesn’t restart, it does nothing until that specified time.

Is there any possibility to check the cron task???


What are you referring by cron task, when it executes a rule?

This is my rule head

rule "dailytotalenergy"                                                         
        Time cron "0 0/1 * * * ?"

And I write the date every minute into the log. But sometimes suddenly it stopped. Then I need to restart and delete the whole cache directory to restart this rule again.

Now I am afraid that if I didn’t check it regularly this stopped and my system isn’t working any more.

Then you should work on finding out why it stopped, and you shouldn’t be looking for ways to work around the fact that it stops.

1 Like

Yes that’s clear but how because in the log is nothing

There is multiple ways to do that, for example:

  • Set up logging for all your rules, so that you can see better when rules stop working.
  • Set up higher log levels for your bindings.
  • Disable all bindings, and then enable them one by one until the error pops up again.


What version of OH are you running?

How many cron triggered Rules do you typically have running at exactly the same time?

How long does it take for the Rules that are cron triggered to finish running?

For awhile there was a bug in the cron scheduler but that has been long since fixed. Cron triggered Rules should be reliable.

Only one…for the time being it is solved…I reinstalled openhab and also I installed oracle java 8 instead of openjdk…

OpenJDK is known to have some issues with OH. If you are running on an RPi in particular or on Linux in general, the Zulu JDK is the preferred Java to use. It is the one that has been tested the most and the one all the developers appear to use. It is also the Java that comes in the Docker containers and gets installed by openHABian.

If you are on Windows then Oracle is probably best.

I had Zulu installed but got some issues with the Amazon dash button…changed over to openjdk found later the issue with the cron now I am on oracle java 8…I am running rpi3…so Zulu is the best?

From the docs:

Zulu is currently the recommended Java platform for openHAB.

My finding so far is…

evrything is running fine but if i do this calculation in my rule it stopps

var String local_string_yesterday = now.minusDays(1).toString("yyyy-MM-dd") + "T23:59:00.0000" 
var Number local_number_wallplug2dailytotalenergy = (Z_way_number_WallPlug2_totalpower.state as DecimalType) - (Z_way_number_WallPlug2_totalpower.historicState(parse(local_string_yesterday)).state as DecimalType)

any Idea ??? @rlkoshak

Errors in openhab.log?

I do recommend casting to Number instead of DecimalType but that wouldn’t cause problems.

For new problems like this it is better to post a new thread.