Rules not triggered after several rule-edits

Hi all,

I’m having this issue already for quite some time (months). I always ignored it, but it is starting to bug me.

Sometimes, when I edit a .rules-file, the rules in that file are not triggered anymore. It doesn’t happen after one edit, but when I edit the file like 4/5 times (because of troubleshooting). The only “workaround” I’ve found is to restart OH.

I don’t think it depends on the complexity of the rule. I could simulate it with a rule file (test.rules) that has this rule in it:

rule "test"

when   
    Item  TEST_Trigger changed from OFF to ON
then
	logInfo("test","Test rule triggered ABC")
end

The system allows me to trigger this rule after a first edit. But after a few changes, I can’t get this rule triggered anymore until a restart. I don’t see errors in my log.

I do edit my rules via Notepad++ (Samba share), which means I get these errors:

2017-11-21 19:41:37.089 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'test.rules'
2017-11-21 19:41:37.092 [WARN ] [el.core.internal.ModelRepositoryImpl] - Configuration model 'test.rules' is either empty or cannot be parsed correctly!
2017-11-21 19:41:37.259 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'test.rules'

But I always had them, and I learned to ignore them.

What I also tried after a .rules-file is frozen: log on via SSH and touch the file. The log shows that the file is being refreshed. But it is not triggered anymore.

Has anyone encountered this before?

Sorry, cannot help you with your frozen rules, but the error messages you are seeing:

Are a well-known issue and not related to your problem. You can search the forum for more eloquent descriptions of this issue, but in essence, the files are getting read while still be written, which causes the warning. OH2 than reads the files again, once the write process has ended and all is well. It is connected to Java watching files for updates.

I remember this problem. I think it was related to the Eclipse Editor and/or the file access. How do you access the files and which tool do you use for edit?

I’ve not seen the error myself nor have I seen it reported before now. Give you can reliably reproduce it I recommend filing an issue on the ESH repo.

And like Lipp mentions, the refresh error is because of how Samba works and not related to your problem. Particularly since you see the file being loaded after your problem starts.

I’ve noticed this since upgrading to OH2 two months ago (apt-get install). Very frustrating. Using nano to edit rules.

Thanks, good to know I’m not the only one. And since you are using nano, I think we can exclude edits via Samba shares as the cause.

I’ll create an issue, like Rich is suggesting.

[EDIT]
Issue:

I’ve had some similar non rule firing experience. At first I thought it was maybe my lack of experience writing rules, using OH and such but over time I came to the same conclusion that edits can cause issues. Unfortunately I didn’t see it as distinct as you, normally the rules I was/am editing carry on working but I’d lose other rules later. So I changed my habits to do more service restarts, it only takes me a minute or so :slight_smile:

Mine is based on OH2.1 standard edition, running on Ubuntu and using webmin to edit 95% of the time and nano the rest. Couldn’t reproduce it consistently enough to log it, very hard to track a ‘my rule’ didn’t fire sort of failure other than users complaining “the lights aren’t on again”.

My system is in quite some state of production (although live in the house) therefore sees a fair few changes and I’ve now got two daily cron triggers doing restarts at hopefully quiet times of day. I was thinking of upgrading to a snapshot and removing the cron restarts before I got serious on saying it’s a bug because I’m not sure how I can help a dev reproduce it.

Hi,

i had the same issue.

I fixed it for me by the following change:

rule "test"

when   
    Item  TEST_Trigger changed 
then
   if (TEST_Trigger.state==ON) {
	logInfo("test","Test rule triggered ABC")
   }
end

I know that it is not the same as changed from OFF to ON, but when it changed, the only possible state is ON or OFF :wink:

Hi Stefan,

I don’t think it is related to a specific rule. The rule I shared is just one specific example. But all rules in the same rule file stop working.

I’m not sure that is correct. A switch can also be NULL. When OH starts, every item will have NULL as a state. This can be changed by a RestoreOnStart (or by just flipping the switch). In your case, the rule will also be triggered when OH starts (from NULL to ON).

In my case it was only rules with changed from OFF to ON

Yes you are true with state Null, but I use persitence and restore on restart.
My switch could only have ON or OFF.
When I restart my openhab, so the rules had not fired.

I also have non firing rules, in my case it has nothing to do with editing.

I had a rule that was working, suddenly it stopped working, while nothing changed.

I my case, the rules are saved (and edited) on github.
When I add a space (in github) and do a pull on the openhab machine, the rule reloads
I get a Refreshing model 'xxx.rules’
and then after a while it works. (a while a few minutes)

I do wonder is there a maximum of time a rule stays in memory, are there a maximum of rules that stay in memory?

Anything else?
I’m working on openHAB 2.2.0 Build #1003