Lookup two sensors on preference call from same multi


(Nick M ) #1

I am writing an app that turns on my porch lights when the garage door moves (active). But I am also trying to make sure the lights stay on as long as the door is open. Currently I have this working and it seems to be working well. The only thing that bothers me is that I had to require two doors in the preference section of the app. These two doors in the example code below will always be the same two doors (same multi too) so I wanted to combine them. The only problem is I do not know how to look up both the acceleration sensor and the contact sensor. Anyone know how to do this?

section("When this door moves") {
    	// TODO: I want to be able to combine these into one.
        input name: "activeSensor", type: "capability.accelerationSensor", title: "Active?", multiple: false, required: true
        input name: "multiSensor", type: "capability.contactSensor", title: "Open?", multiple: false, required: true
    } 

(C Chen) #2

I don’t know how to combine capabilities, but if it will always be a SmartSense Multi, you can do

input name: "iMulti", type: "device.smartSenseMulti", title: "Multi", multiple: false, required: true

(Nick M ) #3

@stepchen cool that helps a lot I put that into one of my apps last night and it is working well.

After some more searching I also found this https://gist.github.com/danlieberman/5623547.

def latestContactValue = sensor1.latestValue( "contact" )

This line of code was the key because then i can just declare the acceleration Sensor and the above line of code looks up if it is opened or closed inside the handler. For my garage door app I decided to try this out and it is working great.

Thanks for the help on that.