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 }
}
@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.
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”.
@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.
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
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.
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!
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:
Turn on selected on/off devices
Turn off selected on/off devices
Turn on selected dimming devices to a selected percentage
lock selected devices
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.
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!