Virtual model change not working


(Jeremy Whittaker) #1

Wondering if someone can help me out or offer any insight. I’m trying to use an NFC sticker>SMS>IFTTT>Virtual switch on>mode change. This way when I go to bed at night I can simply place my phone on the NFC sticker and put my ST hub in “alarm” mode. I have it working to this point NFC sticker>SMS>IFTTT>Virtual switch on but for whatever reason I cannot get this switch to work with this smart app to change the mode. Any suggestions would be great.

I created a virtual on off switch with the following settings:

Sleep mode Device Sleep mode

Name Sleep mode
Label Sleep mode
Type Switch Capability
Device Network Id VirtualSleepMode
Status INACTIVE
Hub Home
Last Activity At 3 Mar 2014 05:43:31
Date Created 3 Mar 2014 04:23:54
Last Updated 3 Mar 2014 05:28:41
Data No data found for device
Current States No states found
Events List Events

I then used the sample code to make this mode change when the switch was turned on. It is below:

preferences {
	section("Select Switch to monitor"){
		input "theSwitch", "capability.switch"
	}
}

def installed() {
	log.debug "Installed with settings: ${settings}"
    initialize()
}

def updated(settings) {
	log.debug "Updated with settings: ${settings}"
	unsubscribe()
    initialize()
}

def onHandler(evt) {
	log.debug "Received on from ${theSwitch}"
    if(location.mode != "Sleeping") {
        setLocationMode("Sleeping")
    } else {
    	log.debug "Already Sleeping - ignoring"
    }
    theSwitch.off()
}

def offHandler(evt) {
	log.debug "Received off from ${theSwitch}"
}

def initialize() {
	subscribe(theSwitch, "switch.On", onHandler)
    subscribe(theSwitch, "switch.Off", offHandler)
    }