Virtual switch no switching modes

(Matt Alter) #1

I created a virtual switch in the ide. It’s on my dashboard and I have a smart app called at home that that set to change mode to home. It never changes mode.

(Tim Slagle) #2

what app are you using. cna you post the code?

(Matt Alter) #3

Just created a virtual on off switch on the ide. Trying to use that as a trigger to set home or away mode.

(Tim Slagle) #4

Right, what app are you using the watch for the Virtual Switch change to process the mode change?

(Matt Alter) #5

Or maybe I need to better understand how I can use a virtual switch to set home or away mode.

(Matt Alter) #6

Android. trigger. But not using it now, just testing the virtual switch in the app. Either way it does not change the home or the away mode.

(Matt Alter) #7

Really simple, in the ST app, virtual on off switch, set home when on and set away when off.

(Tim Slagle) #8

Yeah you need to use an app to watch for the switch state to change. Use something like this:

 *  Big Switch for Hello Home Phrases
 *  Copyright 2014 Tim Slagle
 *  Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 *  in compliance with the License. You may obtain a copy of the License at:
 *  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
 *  on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
 *  for the specific language governing permissions and limitations under the License.
    name: "Big Switch for Hello Home Phrases",
    namespace: "tslagle13",
    author: "Tim Slagle",
    description: "Uses a virtual/or physical switch to run hello home phrases.",
    category: "Convenience",
    iconUrl: "",
    iconX2Url: ""

preferences {
	page(name: "selectPhrases")
    page( name:"Settings", title:"Settings", uninstall:true, install:true ) {
    section("Settings") {
    	label title: "Assign a name", required: false
    section(title: "More options", hidden: hideOptionsSection(), hideable: true) {
			def timeLabel = timeIntervalLabel()

			href "timeIntervalInput", title: "Only during a certain time", description: timeLabel ?: "Tap to set", state: timeLabel ? "complete" : null

			input "days", "enum", title: "Only on certain days of the week", multiple: true, required: false,
				options: ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]

			input "modes", "mode", title: "Only when mode is", multiple: true, required: false

def selectPhrases() {
	def configured = (settings.HHPhraseOff && settings.HHPhraseOn)
    dynamicPage(name: "selectPhrases", title: "Configure", nextPage:"Settings", uninstall: true) {		
		section("When this switch is turned on or off") {
			input "master", "capability.switch", title: "Where?"
        def phrases = location.helloHome?.getPhrases()*.label
		if (phrases) {
		section("Run These Hello Home Phrases When...") {
			log.trace phrases
			input "HHPhraseOn", "enum", title: "The Switch Turns On", required: true, options: phrases, refreshAfterSelection:true
			input "HHPhraseOff", "enum", title: "The Switch Turns Off", required: false, options: phrases, refreshAfterSelection:true


def installed(){
subscribe(master, "switch.on", onHandler)
subscribe(master, "", offHandler)

def updated(){
subscribe(master, "switch.on", onHandler)
subscribe(master, "", offHandler)

def onHandler(evt) {
log.debug evt.value"Running Light On Event")
sendNotificationEvent("Performing \"${HHPhraseOn}\" because ${master} turned on.")

def offHandler(evt) {
log.debug evt.value"Running Light Off Event")
sendNotificationEvent("Performing \"${HHPhraseOff}\" because ${master} turned off.")

private getAllOk() {
	modeOk && daysOk && timeOk

private getModeOk() {
	def result = !modes || modes.contains(location.mode)
	log.trace "modeOk = $result"

private getDaysOk() {
	def result = true
	if (days) {
		def df = new java.text.SimpleDateFormat("EEEE")
		if (location.timeZone) {
		else {
		def day = df.format(new Date())
		result = days.contains(day)
	log.trace "daysOk = $result"

private getTimeOk() {
	def result = true
	if (starting && ending) {
		def currTime = now()
		def start = timeToday(starting).time
		def stop = timeToday(ending).time
		result = start < stop ? currTime >= start && currTime <= stop : currTime <= stop || currTime >= start
	log.trace "timeOk = $result"

private hhmm(time, fmt = "h:mm a")
	def t = timeToday(time, location.timeZone)
	def f = new java.text.SimpleDateFormat(fmt)
	f.setTimeZone(location.timeZone ?: timeZone(time))

private hideOptionsSection() {
	(starting || ending || days || modes) ? false : true

private timeIntervalLabel() {
	(starting && ending) ? hhmm(starting) + "-" + hhmm(ending, "h:mm a z") : ""

Add this into the IDE as a custom smart app, publish it to yourself, and then you can call hello home phrases as much as you want :smiley:

(Matt Alter) #9

But the automatically perform at home, there is no option to use a virtual switch.

(Matt Alter) #10

ok, thanks for that. How do I use that app?

(Tim Slagle) #11

Add this into the IDE as a custom smart app, publish it to yourself, and then you can call hello home phrases as much as you want :smile:

(Matt Alter) #12

Not sure why I need that. Following that post that you help find about using iftt and presence,

First you want to go into the IDE and create a virtual on/off button. Simply do the following:

Go to
Go to Devices
click "New Device"
name it anything you like mines "Cory Mobile Presence"
Device Network ID: N/A
Type: On/Off Button Tile
Location: Home

Go into your app and create rules that change the mode to away or home based on if this switch is on, or off.

This last sentence. Can’t seem to find how do this?

(Tim Slagle) #13

You don’t have an app. You need to use the one i gave you to make this happen.

Go to the IDE>SmartApp>New smart app… Copy and paste what I gave you. publish it. install it from the mobile app.

Then… enjoy

(Matt Alter) #14

When I log into ide, I don’t have the option for smart apps.

(Matt Alter) #15

I can list my smart apps, but don’t see an option to create one

(Matt Alter) #16

Ok so I was not in developer mode. Got it figured out. How do I install the app, now that its published?

(Tim Slagle) #17

When you login you’ll see this click on my Smart Apps

Then click on “+ New Smart App”

(Tim Slagle) #18

Hit the “+” icon at the bottom of the screen and scroll all the way to the right. (in the mobile app)

(Greg) #19

also I think you need to log out of the mobile app and log back in to have my apps appear. or it used to be that way.

(Tim Slagle) #20

I’ve never had to do this, but ive seen it said here before