SmartThings Community

Help with code that notifies of open windows/doors

(Jason) #1

Hello,

I have created some code that will check the state of a single contact sensor at a specified time of day and send a notification if it is open. I would like to allow the user to input multiple sensors to be checked. I know that I can just add “multiple:true” to allow the user to enter more inputs but I don’t know how to write the code to check the state of each sensor chosen by the user. Any tips?

Thanks

preferences {
  section("Monitor this door or window") {
    input "contact1", "capability.contactSensor", required: true, title: "Multi Sensor?"
  }
  section("When do you want to check the sensor?") {
    	input "time", "time", required: true
  }
	section( "Notifications" ) {
        input("recipients", "contact", title: "Send notifications to") {
            input "sendPushMessage", "enum", title: "Send a push notification?", options: ["Yes", "No"], required: false
            input "phoneNumber", "phone", title: "Send a text message?", required: false
        }
	}
//  section("Program active on these days") {
//        input "days", "enum", title: "Select Days of the Week", required: true, multiple: true, options: ["Monday": "Monday", "Tuesday": "Tuesday", "Wednesday": "Wednesday", "Thursday": "Thursday", "Friday": "Friday", "Saturday": "Saturday", "Sunday": "Sunday"]
//  }
//}
}

def installed() {
	initialize()
}

def updated() {
	unschedule()
    initialize()
}

def initialize() {
	schedule(time,notifyTime)
}

def notifyTime() {
//	log.trace "$evt.value: $evt, $settings"
	def contact1check = contact1.currentState("contact") //get contact1 state
    	if(contact1check.value == "open") {
			log.debug "$contact1 was left open, sending push message to user"
			sendPush("${contact1.label ?: contact1.name} was left open")
        }else{
        }
}
1 Like
(PPO16) #3

example below:

section("Select sensors") {		input "temp", "capability.temperatureMeasurement", title: "Temperature", required: true, multiple: true}

can be accessed through:

temp.each { eswitch ->
log.debug eswitch.currentTemperature
}