Rules disappear when Items are reloaded

Rules are being removed on reload of Items.

Create one Item in test.items:

Switch Test_Switch “Test Switch”

And one Rule in test.rules:

rule “Switch Changed”
when
Item Test_Switch changed
then
logInfo("", “Test_Switch changed”)
end

Add a space to test.items and save.

Logs:
2021-01-21 21:05:55.140 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test.items’
2021-01-21 21:07:10.739 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test.rules’
2021-01-21 21:07:37.524 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model ‘test.items’

Look at the rules and “Switch Changed” has disappeared.

  • Platform information:
    • Hardware: VM
    • OS: Debian Stretch
    • Java Runtime Environment: OpenJDK Server VM Zulu11.43+55-CA (build 11.0.9.1+1-LTS, mixed mode)
    • openHAB version: 3

Similar behavior has been reported. An issue is open. It doesn’t seem to be consistent and it won’t be all the rules in the .rules file.

The issue is here

and I’ve linked to this thread, as you seem tohave a simple demo. Is it repeatable, consistent?

Tested it, and that did exactly as descibed! As soon (instant!) as I saved [test.items] the rule disappeared in main UI (these files, test.rules and test.items already existed in my setup). So that’s related!

I refreshed the main UI page and as you would expect that didn’t show the rule. I will leave those files alone next couple of hours and see what happens in the main UI. I got the feeling sometimes it will refresh after a period.

I’ve seen a suggestion that similar file naming like test.xxx is involved. But that was never confirmed.
Been trying to think of a test - how about another copy of your rule, with a different rule name, in test2.rules

Tested it with a different item / rules setup as you suggested rossko57:

I created in my test.items an extra test item, so I have there:

Switch      TestLed                     "Test LED"                                  [ "Switchable" ]
Dimmer      TestDimmer                  "TestDimmer"
Number      OutputPreset                "Preset audio apparaat"
String      OutputName                  "Uitvoer apparaat" 
Switch      Testschakelaar              "Alleen voor test"                                          <siren>
Switch      Testschakelaar2             "Alleen voor test"                                          <siren> 

I created an extra test2.rules file, so I have test.rules and test2.rules. In both rules files I use items from test.items and test2.items. And both rules files have multiple rules which use items from test and test2.

Tested a couple of situations:

  • change and save the test2.items file (Only testschakelaar2 item exist in this file)
    > result > only the rules from test2.rules disappear >> This time I did NOT use testschakelaar2 in test.rules

  • change and save the test2.items file (Only testschakelaar2 item exist in this file)
    > result > only the rules from test2.rules disappear >> I DID use testschakelaar2 in test.rules

  • change and save the test.items file (testschakelaar item and others exist in this file)
    > result > only the rules from test.rules disappear >> I DID use some items in test2.rules

So for me it’s clear. If the items filename is the same as the rules filename and the items file is changed if only an extra space, ALL the rules from the file with that same name are deleted from the main UI. They come back when the rule file is saved and loaded again. I tested this with my normal setup and when I save an item file with the same name as a rules file, all my rules disappear in the main UI.

I didn’t notice earlier that all the rules where gone, but that’s not very strange I think. A lot of my item files don’t change, so those rules (files) don’t get messed up. A lot of my item files have different name then the rules files so there is also nothing going wrong. Some item files have the same names but mostly when I change something in my setup, I first add the item due to the loadtimes which are a bit long on a Raspberry pi 4b. While i’m coding everything is loading, after that i’m saving the rules file, everthing is good. But sometimes I change an item because of a typo in the label, another icon, adding to a group, etc. That item file is the same as a rules file, but I didn’t do anything with those rules that day, so it feels like it’s random when rules disappear but it isn’t :slight_smile:

I’m gona rename my xxxx.rules files to xxx_ma.rules. for the simple reason I’m currently building a master slave setup and I want to use some of the files from the master on the slave but with minor changes (if master is down > then execute, kind of stuff). I know i’m gonna copy a lot of files upcoming weeks so it’s better to have different names because of a f*ckup overwrite :slight_smile:

[something different I encountered]
while testing with 2 items, 2 item files, 2 rules files and total of 4 rules. The system just doesn’t like the same rules copied with different titles. I’m sure nobody has exactly!! the same rules copied with different titles, but it’s strange. 2 Of them load, 2 other identical (except title) didn’t load.

1 Like

Thanks for putting in so much effort to reproduce and narrow the problem down.

Someone who knows the internals will no doubt leap on the solution but I’ll speculate that the items and rules are stored in hashes with the basename of the file as the key. So removing all entries with the same key removes both items and rules.

1 Like

Looks like this filename thing was identified and a fixed a couple of weeks ago

I’m guessing fix only available in snapshot versions until 3.1 stable release.

1 Like

Thanks Rossko,

I’m happy to wait but might grab a snapshot and test it.

Just chiming in to confirm: I saw exactly this behavior yesterday: items file and rules file with the same name, I changed the contents of the items file, and the rules dropped off until I reloaded the items file. I am running 3.0.1 release.

1 Like