@rossko, (thanks for the NULL tip, you are correct, a Item state cannot be null, but NULL, I have used a sendCommand in the init to force default boot state to OFF for the Item, and removed the “NULL” piece of code).,
The experiment worked fine, as you suspected, this due to the fact that I forgot to disable a older rule, that uses several executeCommand’s (each as a timer, wrapped in a main timer code loop) with return and timeout set to 1 second apiece.(there are currently 5 of them = 5 seconds total + whatever processing time with no reschedule on each execCommand timer). The main timer containing the exeCommand timers then loops every 10 seconds. various techniques of triggering applied varying from crom, system start as init.
Basically the executeCommand’s grep’s a text file for various key words (one key word per executeCommand) and returns the first matching value (-m 1) of each unique keyword, assigns it to a variable string, which the code in each executeCommand timers code loop (within hours of a day schedule) then uses to sendCommand in order to change a Item.state to ON.
Then there is a timer rule that then turns the Item off.
The timer rule works fine as when the Item received a ON command it uses two other Item.states to prevent multi firing of the timer rule. (The “autoTimer” rule is not included here, just the “motionDetect” ruke )
The issue appears to be the same as in the post “Why do my rules stop running” basically the quartz thread pool where available threads are used up by the odd executeCommand that fails to return a value in time or a failure of the system to process said backlog.
Having read all the posts it appears that (especially Rich) tries every way possible to address avoiding the need to run code in this fashion ranging from reducing rule execution time to alternative methods such as having the executeCommand run the rule with no return that fires a script that then returns the value to openHAB via LSB, MQTT or REST.
There is no real answer for resolving this relating to bug fixes or better error handling from openHAB’s side, however older versions of openHAB (2.1) appear to have had better error handling and been more resilient.
The ultimate question I have is what are the true limmitations in openHAB relating to executeCommand, Quartz and thresholds?
below I have attached the code for reference.
var Timer timer1 = null
var Timer timer2 = null
var Timer timer3 = null
var Timer timer4 = null
var Timer timer5 = null
var Timer motionDetect = null
rule “motionDetect” when
System started // Use Startup or
//Time cron "0/10 * * * * ?" //Every 10 seconds using cron
then
if(motionDetect === null){
motionDetect = createTimer(now, [|
if(timer1 === null){
timer1 = createTimer(now, [ |var readValue_Front_Garages = executeCommandLine(" sudo /bin/grep -m 1 \"Front_Garages\" /path/text.file",1000)
if (readValue_Front_Garages == ''){if(Front_Garages.state !== OFF){sendCommand(Front_Garages, OFF)}} else {if(Front_Garages.state !== ON){sendCommand(Front_Garages, ON)>
var Number hour = now.getHourOfDay
if(readValue_Front_Garages == ''){} else { if(hour >= 19 || hour <= 05){if(Driveway_Floodlight.state !== ON){sendCommand(Driveway_Floodlight, ON)}}}
])} else {if(timer1 !== null){timer1.cancel timer1 = null}}
if(timer2 === null){
timer2 = createTimer(now, [ |var readValue_Front_House = executeCommandLine(" sudo /bin/grep -m 1 \"Front_House\" /path/text.file",1000)
if (readValue_Front_House == ''){if(Front_House.state !== OFF){sendCommand(Front_House, OFF)}} else {if(Front_House.state !== ON){sendCommand(Front_House, ON)}}
var Number hour = now.getHourOfDay
if(readValue_Front_House == ''){} else { if(hour >= 19 || hour <= 05){if(Driveway_Floodlight.state !== ON){sendCommand(Driveway_Floodlight, ON)}}}
])} else {if(timer2 !== null){timer2.cancel timer2 = null}}
if(timer3 === null){
timer3 = createTimer(now, [ |var readValue_Patio_Courtyard = executeCommandLine(" sudo /bin/grep -m 1 \"Patio_Courtyard\" /path/text.file",1000)
if (readValue_Patio_Courtyard == ''){if(Patio_Courtyard.state !== OFF){sendCommand(Patio_Courtyard, OFF)}} else {if(Patio_Courtyard.state !== ON){sendCommand(Patio_Cour>
var Number hour = now.getHourOfDay
if(readValue_Patio_Courtyard == ''){} else { if(hour >= 19 || hour <= 05){if(Patio_Floodlight.state !== ON){sendCommand(Patio_Floodlight, ON)}}}
])} else {if(timer3 !== null){timer3.cancel timer3 = null}}
if(timer4 === null){
timer4 = createTimer(now, [ |var readValue_Rear_House = executeCommandLine(" sudo /bin/grep -m 1 \"Rear_House\" /path/text.file",1000)
if (readValue_Rear_House == ''){if(Rear_House.state !== OFF){sendCommand(Rear_House, OFF)}} else {if(Rear_House.state !== ON){sendCommand(Rear_House, ON)}}
])} else {if(timer4 !== null){timer4.cancel timer4 = null}}
if(timer5 === null){
timer5 = createTimer(now, [ |var readValue_Side_House = executeCommandLine(" sudo /bin/grep -m 1 \"Side_House\" /path/text.file",1000)
if (readValue_Side_House == ''){if(Side_House.state !== OFF){sendCommand(Side_House, OFF)}} else {if(Side_House.state !== ON){sendCommand(Side_House, ON)}}
var Number hour = now.getHourOfDay
if(readValue_Side_House == ''){} else { if(hour >= 19 || hour <= 05){if(Patio_Floodlight.state !== ON){sendCommand(Patio_Floodlight, ON)}}}
])} else {if(timer5 !== null){timer5.cancel timer5 = null}}
motionDetect.reschedule(now.plusSeconds(10)) //Reschedule when System start is used, this line disabled when cron is used.
])} else {if(motionDetect !== null){motionDetect.cancel motionDetect = null}}
end