Rules are flaky

I have two sets of similar rules. When I first set them up, they didn’t work (mostly typical typos and such). But when I got them working, I found that they would stop or stop working every time I did something with the files.
For instance, I would modify one file, and the other set of rules would stop working.

One set of rules turns a frog night light on or off in response to a button press (B3) on an X10 controller (through an Insteon PLM). The other set does the same thing but in response to B4.

frog_nightlight_b3.rules

rule "turn on frog"
when 
	// Item x10SwitchB3 received command ON
	Item x10SwitchB3 changed from OFF to ON
then
	master_frog_nightlight.sendCommand(ON)
	logInfo("rules", "frogb3 on")
end
rule "turn off frog"
when 
	// Item x10SwitchB3 receieved command OFF
	Item x10SwitchB3 changed from ON to OFF
then
	master_frog_nightlight.sendCommand(OFF)
	logInfo("rules", "frogb3 off")
end

frog_nightlight_b4.rules

rule "turn on frog"
when 
	// Item x10SwitchB4 received command ON
	Item x10SwitchB4 changed from OFF to ON
then
	master_frog_nightlight.sendCommand(ON)
	logInfo("rules", "frogb4 on")
end
rule "turn off frog"
when 
	// Item x10SwitchB4 receieved command OFF
	Item x10SwitchB4 changed from ON to OFF
then
	master_frog_nightlight.sendCommand(OFF)
	logInfo("rules", "frogb4 off")
end

From my log:

2017-10-26 17:51:13.618 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'frog_nightlight_b3.rules'
2017-10-26 17:51:13.830 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'frog_nightlight_b3.rules'
2017-10-26 17:51:17.490 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'frog_nightlight_b4.rules'
2017-10-26 17:51:17.721 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'frog_nightlight_b4.rules'
2017-10-26 17:51:17.918 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'frog_nightlight_b4.rules'
2017-10-26 17:51:39.158 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.3 to ON
2017-10-26 17:51:41.286 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.3 to OFF
2017-10-26 17:51:43.191 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.3 to ON
2017-10-26 17:51:45.093 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.3 to OFF
2017-10-26 17:51:46.725 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.4 to ON
2017-10-26 17:51:48.437 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.4 to OFF
2017-10-26 17:51:48.618 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 off
2017-10-26 17:51:50.260 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.4 to ON
2017-10-26 17:51:50.270 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 on
2017-10-26 17:51:52.292 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.4 to OFF
2017-10-26 17:51:52.306 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 off
2017-10-26 17:51:53.844 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.4 to ON
2017-10-26 17:51:53.854 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 on
2017-10-26 17:51:55.540 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.4 to OFF
2017-10-26 17:51:55.549 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 off
2017-10-26 17:51:57.267 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.3 to ON
2017-10-26 17:51:59.459 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.3 to OFF
2017-10-26 17:52:01.059 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.3 to ON
2017-10-26 17:52:02.850 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.3 to OFF
2017-10-26 17:52:04.275 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.3 to ON
2017-10-26 17:52:05.618 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.4 to ON
2017-10-26 17:52:05.630 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 on
2017-10-26 17:52:06.979 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.4 to OFF
2017-10-26 17:52:06.989 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 off
2017-10-26 17:52:08.129 [INFO ] [onplm.internal.device.MessageHandler] - X10OnHandler: set X10 device B.4 to ON
2017-10-26 17:52:08.137 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 on
2017-10-26 17:52:09.361 [INFO ] [onplm.internal.device.MessageHandler] - X10OffHandler: set X10 device B.4 to OFF
2017-10-26 17:52:09.370 [INFO ] [eclipse.smarthome.model.script.rules] - frogb4 off

As you can see from the debugging log, even though both sets of rules are there and should work, only (right now) the B4 rules work.

Something tells me this is something simple, but if it is, I’m not seeing it. I don’t think it’s the fact that both sets of rules are controlling the same item, because there was a point yesterday when both sets worked at the same time.

Any suggestions would be greatly appreciated.

Paul

if you modify /update /save the rules, rule file need to be reload and it takes a while,
it can less to few seconds and up to few minutes

speed is depends on your openhab server speed and how long you have mess up with your system.
eg, if you keep make changes to rules/things/items, reload time may turn longer and longer.
reboot server may make it better.

I knew it was something simple. I copied the rules from one file to another, and then modified them. But the rule names were the same in both. Changing the rule names to make them unique keeps them from overwriting one another.

I’m still having one minor problem. Since this is a test, I’m not too worried about it, but still:
My conditions are when x10SwitchB3 (or x10SwitchB4) goes from off to on, or from on to off, the condition is triggered. But if the light is turned on with B3 (B3 goes from OFF to ON), the light can’t be turned off by pressing B4 off. Instead, you have to press B4 on, then off. That satisfies the condition of "Item x10SwitchB4 changed from ON to OFF."
To make this work correctly, I think it needs to check what the switch is putting out, and not worry about the previous condition. I’m just not sure how yet.

Paul

And going from

Item x10SwitchB3 changed from OFF to ON

to

Item x10SwitchB3 received update ON

took care of my last problem.

Paul

You should also be able to use

Item x10SwitchB3 changed to ON

It doesn’t need the from -part.

Reading your code I wouldn’t expect your observed behaviour.
I sounds to me as if the frog-light is somehow “linked” to one of the switches, however I have no idea how.
If it was me I would rather have both switches be able to switch independently AND both show the actual state.

I dropped the “from” part, but it didn’t help. It turned out that it was the “changed” part that was causing me trouble. “Changed” requires an actual state change, while “received update” will trigger even if the state doesn’t change.

That is very true! It obviously won’t change to ON, if it already is.