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??
Thanks
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??
Thanks
Why would a cron Time solution not suffice?
rule "Every first of the month "
when
Time cron "0 0 0 1 * ? *"
then
// do something
end
and
rule "Every first of January "
when
Time cron " 0 0 0 1 JAN ? * *"
then
// do something
end
Is this reliable???
Because
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 "
when
Time cron "0 0 0 1 * ? *" or
Item Force1stMonth received command
then
// do something
end
(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.
What are you referring by cron task, when it executes a rule?
This is my rule head
rule "dailytotalenergy"
when
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.
Yes that’s clear but how because in the log is nothing
There is multiple ways to do that, for example:
No.
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.