"Press" SmartApp Icon?

I just tried to write my own app that respond a virtual momentary switch, but it doesn’t work… can someone point me in right direction? It seems to install correctly, but never gets the “push” event from the virtual momentary switch.

/**
 *  The Big Off Switch
 *
 *  Author: steve
 *  Adapted from "the big switch" by SmartThings
 *
 *  Date: 2013-05-01
 */
preferences {
	section("When this switch is pushed") {
		input "master", "capability.momentary", title: "Where?"
	}
	section("Turn off all of these switches") {
		input "switches", "capability.switch", multiple: true, required: false
	}
}

def installed()
{
	subscribe(master, "momentary.push", offHandler)
}

def updated()
{
	unsubscribe()
	subscribe(master, "momentary.push", offHandler)
}

def offHandler(evt) {
	log.debug evt.value
    log.debug offSwitches()
	offSwitches()?.off()
}

private offSwitches() {
	log.debug "Got Here!"
    if(switches && offSwitches) { switches + offSwitches }
    else if(switches) { switches }
    else { offSwitches }
}

I’m on my phone so I can’t verify, but wasn’t the event called “pushed”? I think the function was push and the event was pushed.

Twack

@twack - I’ll try that. How does one find that out? I looked at the “example” code for a Z-Wave momentary contact switch, but all I see is a “push” or an action in the simulator that says “momentary.push”

When I call the device’s supportedCommands method, I get [refresh, on, off, push] - so I tried subscribing to “push” and “momentary.push” - neither of which works. when, I press the virtual momentary switch, I see “push command sent to virtual off switch” in the bottom-of-the-screen log in the iPhone.

Any clues?

I assumed you were using the "momentary button tile. The code in that which shows the events is:

def push() {
	sendEvent(name: "switch", value: "on", isStateChange: true, display: false)
	sendEvent(name: "switch", value: "off", isStateChange: true, display: false)
	sendEvent(name: "momentary", value: "pushed", isStateChange: true)
}

The ZWave momentary contact switch the events are are “on” or “off”. I think you may be confusing commands with states or attributes. Its easy to do because many devices have the same names for states and commands. Like “on” or “off” for a switch. As I explained in my last post the function is called “push” but the event drives a state changes to the attribute “momentary” called “pushed”.

Try changing your virtual device to the “Momentary Button Tile” and have the app subscribe to “momentary.pushed”. You can then check the states of the “switch” which are “on” or “off”.

HTH,
Twack

@twack - THANK YOU. This worked. I installed a “Momentary Button Tile” on my home page in the app. Then I made my own smart app with the code below. Does exactly what I wanted it to. I’m including the code here to help others learn.

preferences {
	section("When this switch is pushed") {
		input "master", "capability.momentary", title: "Where?"
	}
	section("Turn off all of these switches") {
		input "switches", "capability.switch", multiple: true, required: false
	}
}

def installed()
{
	subscribe(master, "momentary.pushed", offHandler)
}

def updated()
{
	unsubscribe()
	subscribe(master, "momentary.pushed", offHandler)
}

def offHandler(evt) {
	//log.debug evt.value
    log.debug "Turning off: " + switches
	switches?.off()
}

Glad it worked for you. Virtual switches sure make it nice to control several devices at once doesn’t it? Reduces the number of button pushes too.

Just one question though, why are you subscribing to “momentary.pushed”.off? I think you only need to subscribe to" momentary.pushed". Unless I don’t understand your use case or logic.

Twack

Wow…thanks for the example. Since I’m not a developer how could I change this code to toggle off/on with the virtual tile?
Thanks,
Scott
@twack
@stevesell

@Steve28,

My bad, I was originally looking at the post on my phone which cut off the right side of your code which said “off” but really was “offhandler”. LOL
I do not like this forum software.

twack

Ok, I figured it out. I made a device type (On/Off Tile). Then changed the code to include On/Off

/**
 *  On/Off Tile
 *
 *  Author: scottjones67@gmail.com
 *  Date: 2013-10-16
 */
preferences {
	section("When this virtual switch is pushed") {
		input "master", "capability.switch", title: "Where?"
	}
	section("Turn On/Off all of these switches") {
		input "switches", "capability.switch", multiple: true
	}
}

def installed()
{
	subscribe(master, "switch.On", switchOn)
    subscribe(master, "switch.Off", switchOff)
}

def updated()
{
	unsubscribe()
	subscribe(master, "switch.On", switchOn)
	subscribe(master, "switch.Off", switchOff)
}

def switchOn(evt) {
	//log.debug evt.value
    log.debug "Turning on: " + switches
	switches?.on()
}

def switchOff(evt) {
	//log.debug evt.value
    log.debug "Turning off: " + switches
	switches?.off()
}

Thanks,
Scott

@twack
@stevesell

@av8,

I’m not at a place to able to test but try this:

preferences {
	section("When this switch is pushed") {
		input "master", "capability.momentary", title: "Where?"
	}
	section("Turn off all of these switches") {
		input "switches", "capability.switch", multiple: true, required: false
	}
}

def installed()
{
	subscribe(master, "momentary.pushed", switchHandler)
}

def updated()
{
	unsubscribe()
	subscribe(master, "momentary.pushed", switchHandler)
}

def switchHandler(evt) {
  if(master.on){
    switches?.off()
    master.off()
  }
  else{
    switches?.on()
    master.on()
  }
}

Hey @chrisb , I’m still pretty new to all of this and was hoping you could help me figure out how to create a “press to activate app” you referenced in this string. I tried looking around here in the forums but can’t seem to find any literature that helps. I’d like it to have the capability to control each of my devices (lights [on, off, specific brightness %'s], door locks [lock, unlock], etc.).

I see you mentioned it’s easily doable from within the SmartThings app, but I can’t figure it out. Any help is much appreciated!

Are you looking to control these things individually or together all at once?

all at once with the push of the app button.

Okay… so basically you want an app that, when you press the app button (in the SmartApps section of the SmartThings mobile App), it will:

  1. Turn on selected on/off devices
  2. Turn off selected on/off devices
  3. Turn on selected dimming devices to a selected percentage
  4. lock selected devices
  5. unlock selected devices

Is this correct? I just want to understand exactly what you are looking for. Have you done any coding before? Are you looking for help with writing your own SmartApp?

Precisely! Coming from Vera I’ve been used to having individual “scenes” in which to control a bunch of my connected devices all at once by actively running the scene. For example, I have one for when I want to watch a movie. It sets certain lights to specific levels, locks a door, and a few other things when I hit the button (or use my voice by way of Tasked/AutoVoice/AutHomation).

Well, I do have some experience with coding, but I’m pretty novice when it comes to the coding language used for SmartApps. However, I was mainly hoping there was one already created that would allow me to do all this from one app without having to get into the code.

Hey @chrisb, just thought I’d check back in on this. Any ideas of how to create a “press to activate” smartapp to control a bunch of my devices all at once with the push of its smartapp play button without having to code? Is there not already one available that I could use as a template?

Okay… Gotcha… I think I understand that you’re looking for now… and yes, I believe there is an easy way to do this.

You could tackle it by writing and SmartApp (or having someone else do it)… it wouldn’t be too complicated. However, I think there’s an even easier way:

In the mobile app, tap on the little quote bubble at the top right of the screen. Here you can change modes and do other stuff. At the bottom right there is settings box where you can add new modes/behaviors. Tap on this and then tap on ‘Add new Action’ Give it a name, such as ‘Movie Night.’ After this you have lots of options as far as tweaking your devices to the desired results.

@triggertact In the initialize section use:

subscribe(app, appTouch)

Then make a function like:

def appTouch(evt) {
log.debug "appTouch: $evt"
}

And the code you want to execute will go there. This will give that little “play” icon in the smart app. I’ve been using it for testing something else

Edit: It’s similar to the “Big Turn Off” app… or any other example app that has the play icon when in use.

Thanks guys. I actually just ended up using the Make It So SmartApp. Allows me to adjust all the devices I need to and can touch the play button on it in the apps section. Thanks again!

Does anyone have the fully working of this smart app. The copying/pasting messed with “”.