Change modes via REST API?

Is it possible to change modes via the https api urls? I have created a number of tasker items that shut down my house at night when I tap an NFC tag on my nightstand. I would like to be able to change to night mode at the same time so I can arm my foscam. Is this possible? If not, anyone have any other suggestions that doesn’t involve opening the smartthings app, clicking the circle at the top, then clicking on dashboard, then clicking the bubble icon, then selecting the little arrow, then tapping Good Night?.. lol. Call me lazy, but it’s just way to many steps. - This is supposed to be automation - right? :slight_smile:

A timed based app doesn’t really work for me as I go to sleep at various times. I have considered getting a z-wave remote and programming that, but I would rather stick with tasker and NFC if possible.

One possible work-around is to set up a virtual switch. Have a mode changing app subscribe to the switch state. Then have your tasker app turn the switch on or off and the mode should follow.

HTH
Twack

@twack - this will work perfect - thanks! Can anyone assist me with code for this? I looked through the current shared code and tried to piece something together that would change mode based on a switch being on or off, but I had no luck. I’m not much of a developer :(.

Thanks in advance for anyone willing to assist.

Create an “On/Off Button Tile” device (My Devices > New Device). Fill out the following -

Device Settings

You can use whatever you want for the Device Network Id.

Then create a new smartapp with the code provided below. The switch to monitor will be the new On/Off button tile switch you just created. It subscribes to the ‘on’ event and in the case of the code below will change to Night mode unless already in Night mode.

/**
 *  Night Mode Toggle
 *
 *  code borrowed from @stevesell
 *
 *  Date: 2014-04-17
 */
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 != "Night") {
        setLocationMode("Night")
    } else {
    	log.debug "Already Night - ignoring"
    }
    theSwitch.off()
}

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

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

@nelemansc - Thank You!!! :slight_smile:

I modified this slightly so it will activate home mode when toggled off. This way, I can tap the NFC again in the morning to enable home mode.

/**
 *  Night Mode Toggle
 *
 *  code borrowed from @stevesell
 *
 *  Date: 2014-04-17
 */
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 != "Night") {
        setLocationMode("Night")
    } else {
    	log.debug "Already Night - ignoring"
    }

}

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

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

I’ve been trying to set something up like this too. I set up my on/off button and the app as posted by nelemansc. The only thing I edited was the name of the mode “night” to the name of the mode I created. when I push the on off button the button goes on then off by itself and nothing happens. Any suggestions?

/**
 *  open house monitor Mode Toggle
 *
 *  code borrowed from @stevesell
 *
 *  Date: 2014-04-17
 */
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 != "Open House Monitor") {
        setLocationMode("Open House Monitor")
    } else {
    	log.debug "Already Night - ignoring"
    }
    theSwitch.off()
}

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

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

@greg - Is SmartThings already in “Open House Monitor” mode when pressing the button? If so, no changes will be made as it looks for the current mode here:

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

No, it’s in Home mode. my activity log reads

open house monitor switch is on
Open house monitor sent off command to open house monitor
Open house monitor switch is off.

Ok - it seems to be working although I didn’t change anything, But how can I make the virtual on/off stay on?

@greg glad to hear it’s working. Just remove theSwitch.off() from the onHandler and it will keep the switch on.

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

perfect. I appreciate the help nelemansc. and I’m sorry if I highjacked this thread.

The above is something I was looking for to run mode changes via my Pebble Watch so thanks everyone for your advice…

Couple of questions -

I have created the App and Published it to my device and it works well most of the time.

One thing is that when I use the https request via the pebble to switch on or off the virtual tile I created it changes the mode but that mode change isn’t reported in the SmartThings App Hello, Home Dialogue on the iPhone App (when I change modes using the App it gives me a nice message). Is that down to something missing in the code I am using?

Early days for me with virtual tiles and coding some apps but loving getting into it so any advice appreciated!

@kylefitzgerald,

If you want to change/build on what you already have, here is a couple of things I did with Tasker and SmartThings:

  1. Start raising the lights in the bedroom from 0 to 100% starting a few minutes before alarm went off. I used a simple loop that had the setlevel command inside.
  2. At the same time, the lights started rising, turned on Pandora to nature sounds station
  3. At the same time, turned on outlet that coffee maker was hooked to.
  4. When alarm went off, had Tasker voice say "good morning" and read the weather forcast.
  5. Then it displayed my emails and said "here are your new emails, sir".
  6. Then it turned off Pandora and then turned on iHeart radio to a news station.

One of the things that I never got around to is having it trigger good night when I set it in the charger on the nightstand. This would be in lue of the NFC tag trigger and then have it turn off the radio when I took it out of the charger if it was on an alarm day. You could do so many things with Tasker/SmartThings. Its cool stuff.

Looking forward to seeing what you guys do with it,
Twack

1 Like