I have numerous cron jobs in my OH2 rules, but one of them (and only one) always fires twice:
Time cron "59 0/30 * * * ?"
usually the second job fires 100-104 milliseconds from the first
Before anyone asks, it’s definitely not a duplicated rule (and the ‘59’ is intentional - I stagger different cron jobs slightly, so they don’t all fire at once and it makes logs/debugging clearer)
I used to have the same problem.
It was caused by problems in the rules file, in my case it were “escape characters” in a string, removing those solved it.
A simple workaround was to just "re"save the rule after OH was started, that caused a reload of the file and the misbehaviour was gone.
Interesting. This is a pretty simple rule - runs scripts to extract the current CPU utilisation and temperature (I appreciate it would be neater to use a binding, but - as far as I know - there’s no binding to get CPU temperature except with a Raspberry Pi):
// Refresh CPU utilisation every 30 mins, after 59 seconds
rule "Update CPU utilisation"
when
Time cron "59 0/30 * * * ?"
then
var String output1
var String output2
var String output3
logInfo("SYSTEM", "Getting CPU utilisation and temp")
output1 = executeCommandLine("/etc/openhab2/utils/cpu_utilisation.sh", 2000)
sendCommand(CPU_utilisation,output1)
output2 = executeCommandLine("/etc/openhab2/utils/cpu_temp.sh", 2000)
sendCommand(CPU_temp,output2)
output3 = output1 + "%/" + output2 + "C"
sendCommand(CPU_stats,output3)
logInfo("SYSTEM", "CPU utilisation/temp {}",output3)
end
My rule file was working before with no problems. On the change to a new snapshot the errors started. However this error was gone if the rule file was reloaded (i.e. just re-saved while OH2 was running), so the rule had no “real” problem.
As said, in my case it was a character ("") in a string, I could nail just to that. Using the rule without that removed the error completly.
You are using some strings, for a test I would try to use a the rule with the var output3 without the “%”. Yes, that way the sendCommand would most probably not work, but you could check if that is the problem!