Rules executed twice

I’m running OH2 on RaspberryPi. While developing my rules I found in log file that rules seems to be executed several times.It look likes as the old version stays still in the configuration, even if the new version has the same name. Restart of OH2 or RaspPi also not helps.
Here e.g. my rule trigger:

rule "Shutters OG Triggers"
System started or
Time cron "0 15 1 1/1 * ? *"

than some computation of times and finally definition of timers via createTimer

In the Log file I found:

2017-01-20 01:15:04.673 [INFO ] [.model.script.Shutter_FF_ChildW_Dark] - Set Timer Command DOWN
2017-01-20 01:15:04.889 [INFO ] [.model.script.Shutter_FF_ChildW_Dark] - Set Timer Command UP
2017-01-20 01:15:04.894 [INFO ] [.model.script.Shutter_FF_ChildW_Dark] - Set Timer Command DOWN
2017-01-20 01:15:05.110 [INFO ] [.model.script.Shutter_FF_ChildW_Dark] - Set Timer Command UP

So timers are defined twice. Also some additional debug messages from rule is written twice.

Is there a way to

  • show active rules
  • delete old rule versions

Thanks a lot.

I don’t know of any way.

Are these multiple instances of a Rule running a result of editing the rules file or does it just happen over time?

When did that start? I observed that about 2 month ago, it was overcome whenever I just (re)saved the rule without a change.
My problem was due to a special character in a string, after deleting that the problem was gone in toto.

1 Like

Yes had the same problem before Xmas - traced it back to a syntax error in a rule-(missing bracket in my case) - this caused all cron rules to run twice. Have a good look at your rules - try commenting 1/2 out at time and see if that fixes it - note to test you need to restart OH2 as the problem seems to be related to the rules being loaded twice at startup.

…or post your code in here and try to get other opinions.

I now have exactly the same problem and keep debuging it on a rule that only runs once a day 10 min to midnight, so might time some time.

I found a solution in my case

Thanks a lot for all your proposals. Today I spend some time to investigate more detailed. No I cleaned up the file from a lambda definition I was not longer using and build up the rule file again by copying step by step parts from the old file. No it seems that at least the trigger st start up is only fired once. This night rule will be fired by the cron trigger condition. I will report tomorrow if this has solved the problem.

Now I got some other of my rules fire twice :frowning: So my claim of the solution was premature.

It is really strange behavior, after some days it starts firing agani twice or even three times. Inbetween the Raspi was reseted. So maybe something remains in the karaf containers. But I also tried to clean it at start up, without success.
If than I save my rule file again, than it stops firing twice (at least for the next day)

My guess the restart was the cause for the rules running twice. (Re)saving the rules file while OH is running stops that faulty behaviour.
I had the same ,in my case a special character in a string was causing it.

The rules keep firing twice and I do not know why. However today a much stranger thing has happen.
I had a super simple motion sensor rule trigger one light in a wardrobe. Today I have edited that rule to change a light relay and switch other light instead. What was my surprise to find out that now both lights come up.
There is no error in the rule, it is super simple send one command to the light relay. relays are not mixed as I can swith them both from WEB GUI separately just fine

The only explanation I came up that this is that the old version of this rule is still getting executed. I did reboot the problem still exists. single default rules file.
I’m paranoid as my OH2 home has a ghost of the past.

@rlkoshak how can I debug that?

-------- some other observations.

when I save a rule OH2 logs refreshing twice: is that the same on your installs?

2017-02-12 00:29:58.525 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'
2017-02-12 00:29:59.239 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'default.rules'

That hapens only if I save over SMB if I nano the rules file over the SSH it update only one but still executes the old version as well as the new.

If I delete a rule from the file. the old version will still work. the new is not working as it is not there.

Are you by chance using atom to edit your rules? I think atom saves the previous version of the file as hidden file that ends in .rules. As a result OH sees and loads two versions of that file.

An alternative explanation is that atom generates two for changed events every time it saves a file. These events happen so close together that OH loads the rule twice at the same time resulting in two copies of the rule in memory.

This doesn’t fully explain your behavior but it is the closest thing I’ve seen on this forum.

I use notetab++ to edit rules, but there is no additional hidden file there and for sure that does not explain why OH2 is executing an unknown past version of the rules files that was overwriten many time since then.

    [19:35:47] pi@rpi-openhab2:/etc/openhab2/rules$ ls -la
    total 32
    drwxrwxr-x  2 openhab openhab  4096 Jan 30 12:21 .
    drwxr-xr-x 13 openhab openhab  4096 Nov 15 15:08 ..
    -rwxrw-rw-  1 openhab openhab 17800 Feb 12 00:38 default.rules
    -rw-rw-r--  1 openhab openhab   222 Oct 20 03:10 readme.txt
    [19:35:52] pi@rpi-openhab2:/etc/openhab2/rules$

This is one step away from a nuclear option, but you can try deleting your userdata/cache and userdata/tmp folders. You will lose any settings or bindings that we installed through PaperUI but it should give you close to a clean slate. Make a backup copy just in case it doesn’t help so you can restore without needing to rebuild everything.

Ok I’m cloning the SD card and do that. Will I loose all the zwave config done in habpanel as well?
Will the bindings from addon.cfg reinstall on their own?

Yes and yes.

However, you will have the opportunity to set the name of the serial device Thing that represents the controller. If you change the random mane to what it was before all of your auto discovered things will get the same name and you won’t have to change your Items if you have items in .Items files.