Simple Lighting question regarding multiple contacts

When selecting lights to turn on by doors opening and closing in Simple Lighting, it seems like it treats multiple contact sensors as "any" in both the on and off action.

For example, if I set up the following Simple Lighting app, the light will turn on when any of the 3 doors change to open, but it will also turn off when any of the 3 doors change to closed even if other doors are open. Would it make sense to have the On command work when any door is opened, and have the Off command run when all doors are closed?

@bravenel tagging you again, I'm assuming you wrote this one but not 100% sure...

I realize this is simple to do in RM, but I'm trying to move my simpler automations over to their purpose-built apps to cut my number of rules down to something more manageable.

A few thoughts:

(1) I don't know what the right answer is, as to all closed vs any closed. No doubt were I to change it to all closed someone will need any closed.

(2) That leads to adding options, which I'm very reluctant to do with Simple Lighting.

(3) This is a good example of why learning to write simple apps in Groovy makes sense. This would be a very simple app in Groovy. Before there was Rule Machine, I used to whip little things like this off for people because it would take maybe 10 minutes. Perhaps I'll do that, and give you the code here, in hopes that you'll add this concept to your quiver of automation solutions.

1 Like

I've often wondered why you didn't put in a toggle switch like in Rule Manager that indicated all or any. I agree that it would be nice. I'd use simple lighting a lot more. On the same token, perhaps creating a virtual switch and using one of the other managers out there to combine several sensors would be just as easy? Just more "things" to manage.

1 Like

No worries Bruce, I can just keep using RM for these kinds of things. Depending on use case, it could be either a bug or it could be by design, and I don't know the answer until I ask. So I will keep asking...but responses like yours here are always acceptable answers :slight_smile:

1 Like

Learn Groovy! 40 lines of code, of which only 10 are the actual code to do this. Challenge to the reader: modify this simple app to implement the any case instead of the all case (this one won't turn the lights off until all of the contacts are closed). Hint: It takes 2 lines less code to do any.

definition(
    name: "Lights On/Off from Contacts",
    namespace: "hubitat",
    author: "Bruce Ravenel",
    description: "Simple lighting automation for contacts",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: ""
)

preferences {
    section {
		input "lights", "capability.switch", title: "Select lights to turn on/off", multiple: true
		input "contacts", "capability.contactSensor", title: "Select contact sensors", multiple: true
    }
}

def installed() {
    initialize()
}

def updated() {
	unsubscribe()
    initialize()
}

def initialize() {
	subscribe(contacts, "contact.open", openHandler)
	subscribe(contacts, "contact.closed", closeHandler)
}

def openHandler(evt) {
	lights.on()
}

def closeHandler(evt) {
	def allClosed = true
	contacts.each {allClosed = allClosed && it.currentContact == "closed"}
	if(allClosed) lights.off()
}
2 Likes

Thought about it a few times, but haven't seen the need since I've been able to get RM to do everything I've wanted it to do. I'm not a programmer by education or profession...I've learned enough to hack my way through a few things on an as-needed basis, but I don't have strong fundamentals to draw on. So...I try to get creative with the tools that are given to me (Rule Machine) and ask a lot of questions :slight_smile: No need to reinvent the wheel in this case IMO.