SmartThings Multisensors - how can you set multiple capabilities


(Andrea Kealy) #1

Hi all,

I’m trying to code event handlers to detect contact events and changes in temperature using the SmartThings multisensors. My code works for both capabilities separately but doesn’t work for both together as I can only apply the sensor to one capability in the preferences section when coding in the MySmartApps section. Can anyone tell me how to set two capabilities for one device in the preferences section?

I’ve trawled through the forum and all smart apps that I think would help me find a solution to no avail so any help would be gratefully received!

Andrea


(Tim Slagle) #2

which “capability” are you using?


(Andrew Urman) #3

also post the code please


(Andrea Kealy) #4

I’m trying to use the capability.temperatureMeasurement and capability.contactSensor for my living_room_sensor_multisensor but I can’t assign two capabilities to the same device name and can’t attach different device names to one device…

Here’s the code I’m using:

preferences {
    section("When the temperature changes...") {
        input "living_room_sensor_multisensor", "capability.temperatureMeasurement"
        
    } 
    section("When the door opens/closes...") {
        input "living_room_sensor_multisensor", "capability.contactSensor"
    }
}

def installed() {
    subscribe(living_room_sensor_multisensor, "temperature", livingRoomTemperatureHandler)
    subscribe(living_room_sensor_multisensor, "contact", livingRoomContactHandler)
}

def updated() {
    unsubscribe()
    subscribe(living_room_sensor_multisensor, "temperature", livingRoomTemperatureHandler)
    subscribe(living_room_sensor_multisensor, "contact", livingRoomContactHandler)
}

def livingRoomTemperatureHandler(evt){
    log.debug "$evt.doubleValue"  
    log.debug sensor_name 
}


def livingRoomContactHandler(evt){
    log.debug "$evt.value"  
    log.debug sensor_name 
}

(Barry) #5

You just need to use different variable names for the two (lists of) sensors…

preferences {
    section("When the temperature changes...") {
        input "temperatureSensor", "capability.temperatureMeasurement"

} 
        section("When the door opens/closes...") {
            input "contactSensor", "capability.contactSensor"
        }
    }
    
    def installed() {
        subscribe(temperatureSensor, "temperature", livingRoomTemperatureHandler)
        subscribe(contactSensor, "contact", livingRoomContactHandler)
    }

(Tim Slagle) #6

What he said.



(Andrea Kealy) #7

That’s working perfectly - thank you so much!