Conflicting Rules

I tried searching and didn’t see this mentioned anywhere else but I may have missed it.

I’m trying to write some rules for my lighting system and I’m using Insteon keypads. What I’d like to accomplish is pressing one button activates a scene, or a mode which adjusts the lighting, thermostat, and a few other devices, and then turns off any scene or mode buttons that should not be on. I’ve been testing this without attaching to hardware but just creating some switch items in OpenHAB and creating rules operating on them.

This is the code I have so far:
    rule "Dinner Time"
when
	Item LivingRoomKeypadButtonB changed
then
	logDebug("LIVINGROOM","Livingroom Keypad Button B Pressed")
	if (LivingRoomKeypadButtonB.state == ON){
		logDebug("LIVINGROOM", "Keypad Button B ON")
		gLivingRoom.members.forEach(item|{
			logDebug("LIVINGROOM", "LivingRoom Memebers Item: " + item.name)
			if(item.groupNames.contains("gLights")){
				logDebug("LIVINGROOM", "Item " + item.name + " in gLights group")
				if(item.state != DinnerSceneOnLevel){
					logDebug("LIVINGROOM", "Item " + item.name + " set to " + DinnerSceneOnLevel.toString)
					item.sendCommand(DinnerSceneOnLevel)
				}
			}
		})
		LivingRoomKeypadButtonE.sendCommand(OFF)
	} else {
		logDebug("LIVINGROOM", "Keypad Button B OFF")
		gLivingRoom.members.forEach(item|{
			logDebug("LIVINGROOM", "LivingRoom Memebers Item: " + item.name)
			if(item.groupNames.contains("gLights")){
				logDebug("LIVINGROOM", "Item " + item.name + " in gLights group")
				if(item.state >= 0){
					logDebug("LIVINGROOM", "Item " + item.name + " turned off.")
					item.sendCommand(OFF)
				}
			}
		})
	}
end

rule "Movie Time"
when
	Item LivingRoomKeypadButtonE received command
then
	logInfo("LIVINGROOM","LivingRoom Keypad Button E (Movie Scene) Button Pressed - Movie Mode Started")
	
	if (LivingRoomKeypadButtonE.state == ON){
		logInfo("LIVINGROOM","LivingRoom Keypad Button E (Movie Scene) Button State==ON")
		logDebug("LIVINGROOM","Starting to parse through living room group members...")
		gLivingRoom.members.forEach(item|{
			logDebug("LIVINGROOM", item.name + " found...")
			if(item.groupNames.contains("gLights")){
				logDebug("LIVINGROOM", item.name + " is of group gLights")
				if(item.state != MovieSceneOnLevel){
					logDebug("LIVINGROOM",item.name + " set to Movie Scene On Level: " + MovieSceneOnLevel.toString)
					item.sendCommand(MovieSceneOnLevel)
				} else {
					logDebug("LIVINGROOM", item.name + " is not of group gLights, no command sent")
				}
			}
		})
		LivingRoomKeypadButtonB.sendCommand(OFF)
	} else {
		logInfo("LIVINGROOM","LivingRoom Keypad Button E (Movie Scene) Button State==OFF")
		logDebug("LIVINGROOM","Starting to parse through living room group members...")
		gLivingRoom.members.forEach(item|{
			logDebug("LIVINGROOM", item.name + " found...")
			if(item.groupNames.contains("gLights")){
				logDebug("LIVINGROOM", item.name + " is of group gLights")
				if(item.state != MovieSceneOnLevel){
					logDebug("LIVINGROOM",item.name + " set to OFF")
					item.sendCommand(OFF)
				} else {
					logDebug("LIVINGROOM", item.name + " is not of group gLights, no command sent")
				}
			}
		})
	}
end

The issue I have is when I turn on the movie scene it turns off the button for the dinner scene, and then all the dinner lights turn off. Is there a way to avoid this?

Any suggestions are appreciated.

Thanks,
Matt

The problem as I see it is that each button has a state (ON or OFF) and it keeps that state until you press another button at which time it turns off the previous button and turns on the new button.

This appears to be how the device itself is implemented so unless there is some sort of configuration you can make on the device itself you need to work around this and it isn’t going to be easy.

What happens when you press a button (lets say Dinner) and then press it again? Do you get an OFF or another ON?

If I assume you get an OFF in that situation then I’m not sure there is any way around your problem because there really is no reliable way to distinguish between an OFF caused by pressing the button again (i.e. you really want the scene to be OFF) and an OFF sent because you activated a different scene.

On-the-other-hand, if I assume you get another ON then you can rewrite your rules to ignore the OFFs entirely and have the ON logic toggle the devices rather than explicitly set them ON.

Ultimately, the behavior of this scene controller is going to make your desired implementation difficult to achieve.

You assumed correctly, that one press toggles it on, the next toggles it off. There’s always a way around it with enough thought and good code implementation :wink:

I was hoping someone had some prior experience with this situation and could give some pointers but I guess people are just implementing differently than I am. If anyone using Insteon keypads has some advise on the topic I’d be all ears. Otherwise I suppose I will put some effort into figuring out the best approach.

Thanks!