SmartThings Community

SwitchMania [UPDATED] - create 4 different kinds of virtual switches

smartapp_misc
childsmartapp
childdevice
virtualdevice

(Glen King) #43

Just a thought: if you need the virtual switch for programmatic purposes, such as “At sundown, light the front porch 30% and light the foyer 100% and start zone 2 of the sprinkler system” then definitely roll with the ST virtual switch. Also do it for instances that are not uniform. I do that with my music studio, which turns on some amps and dims some lights - then when we’re finished, I tell it to turn off the studio and it turns off the amps while brightening the lights.***

But if your objective is simpler, such as turning off all the downstairs lights when you go to bed, do it in an Alexa group. SImply put all the downstairs lights in the ‘Downstairs’ group, tell Alexa “turn off downstairs”, and all the lights in your group will turn off. Btw, this also works for dimmers as long as you expect uniform performance. I have a ceiling fan with two Cree bulbs, and those are in a group called “fan light”. I say “Alexa, turn on fan light 30%” and it turns on the bulbs at 30% brightness. If I say “Alexa, brighten the fan light” it brightens both bulbs.

***BTW, Alexa freaks out if the room is too loud. After two hours of the band at full blast, it became unresponsive. I had to unplug it and plug it back in. The solution is to hit the MUTE button until the band has finished playing.


(John Crighton) #44

Using virtual switches does have some advantages over an Alexa group. In my mind it’s a more tidy solution, as it’s recognised by both systems. If you wanted to flick the virtual switch (say, with a motion sensor), or you wanted to turn off all downstairs lights with a physical switch, a virtual ST switch gives you these options whilst still being recognisable by Alexa.


(Phil Panfili) #45

I am getting an error after installing everything. I cant get past the first screen in the app, when installing a switch. It just says unexpected error has occured.

I notice in your Githhub, under the momentary buttons device type, there is also another simulated presence sensor device type, but that one does not install, it gets an error that says

Org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: script1483024105718583285704.groovy: 1: unexpected token: * @ line 1, column 2. * Simulated Presence Sensor ^ 1 error


#46

I’ve installed SwitchMania and the associated apps and devices, but am having an issue.

My momentary switches turn on, but not off.

Any ideas?


(Tony - SmartThings Unpublished Contributor ) #47

My momentary switches turn on, but not off.

That’s normal behavior for a momentary switch. It will MOMENTARILY turn on, then back off. They are useful for triggering other actions.


#48

Maybe I wasn’t clear, or I don’t understand exactly how they work, but if I turn the switches on they stay on. I would think I turn it on, and it turns off shortly after?

Or are they in a constant “on” state in the “Things” overview but actually momentarily fire if they receive another On command?


(Tony - SmartThings Unpublished Contributor ) #49

Sorry - I misunderstood what you clearly wrote. :sunglasses:

What DTH are you using for the momentary switch?


#50

First, I used the code linked to earlier in this thread, then tried adding from template when that didn’t work right, but I’m pretty sure they’re the same thing – looks like Smartthings’ basic device handler, “Momentary Button Tile.”

Thanks for your help!


(Tony - SmartThings Unpublished Contributor ) #51

@calbruc

First, I used the code linked to earlier in this thread, then tried adding from template when that didn’t work right, but I’m pretty sure they’re the same thing – looks like Smartthings’ basic device handler, “Momentary Button Tile.”

You need to copy into the IDE the exact DTHs that you list in the SwitchMania smartapp (lines 56-66).

Example 1
If lines 56-66 of SwitchMania are:

if (!existing) {
if (switchType == “On/Off Button Tile”) {
def childDevice = addChildDevice(“smartthings”, “On/Off Button Tile”, deviceId, null, [label: switchLabel])
} else if (switchType == “Momentary Button Tile”) {
def childDevice = addChildDevice(“smartthings”, “Momentary Button Tile”, deviceId, null, [label: switchLabel])
} else if (switchType == “Dimmer Switch”) {
def childDevice = addChildDevice(“smartthings”, “Virtual Dimmer”, deviceId, null, [label: switchLabel])
} else if (switchType == “Simulated Presence Sensor”) {
def childDevice = addChildDevice(“infofiend”, “Simulated Presence Sensor”, deviceId, null, [label: switchLabel])
}
}
}

In this case, the 4 DTHs you need are:
(1) SmartThings’ default “On/Off Button Tile” DTH,
(2) SmartThings’ default “Momentary Button Tile” DTH,
(3) SmartThings’ default “Virtual Dimmer” DTH, and
(4) infofiend’s “Simulated Presence Sensor” DTH.

Example 2
However, say you don’t like SmartThings’ default DTHs for the Momentart Button and the Virtual Dimmer, and you prefer Michael Struck’s versions. Then lines 56-66 of SwitchMania should be:

if (!existing) {
if (switchType == “On/Off Button Tile”) {
def childDevice = addChildDevice(“smartthings”, “On/Off Button Tile”, deviceId, null, [label: switchLabel])
} else if (switchType == “Momentary Button Tile”) {
def childDevice = addChildDevice(“MichaelStruck”, “Momentary Button Tile”, deviceId, null, [label: switchLabel])
} else if (switchType == “Dimmer Switch”) {
def childDevice = addChildDevice(“MichaelStruck”, “Virtual Dimmer”, deviceId, null, [label: switchLabel])
} else if (switchType == “Simulated Presence Sensor”) {
def childDevice = addChildDevice(“infofiend”, “Simulated Presence Sensor”, deviceId, null, [label: switchLabel])
}
}

In this case, the 4 DTHs you would need are:
(1) SmartThings’ default “On/Off Button Tile” DTH,
(2) Michael Struck’s “Momentary Button Tile” DTH,
(3) Michael Struck’s “Virtual Dimmer” DTH, and
(4) infofiend’s “Simulated Presence Sensor” DTH.


#52

I was having the same issue as ‘calbruc’.

My switch was acting like an on/off instead of momentary. It didn’t matter whether I used the Michael Struck version, the SmartThings public version in github, or the SmartThing’s version in the Switch Mania github (using copy/paste since I got errors trying to use github integration). I did edit the appropriate lines in ‘My Virtual Switch Creator’ source file. I wasn’t seeing any errors in the logs. Further debugging and I realized that the issue was that I was first creating an on/off version of the switch and then went back & changed it to momentary. Looking at the code, the type really only matters when you first create it; it doesn’t matter in updates (the type internally really doesn’t change). Also, the Michael Struck version doesn’t seem to initialize properly at all, so that added to the confusion. I’m not totally sure what is wrong with the Michael Struck version; the symptoms are when the switch is created as a momentary, it gets changed to an on/off during the creation and its name gets changed to ‘MyVirtualSwitch’. You can go back & edit it to make things correct, but since it has already been created, it really stays on/off internally. Hope this helps future users.


Alexa / WebCore Integration
(Tutorial) PC on/off and Activity Monitor with SmartThings
Disable/Pause a SmartApp temporally?
Looking to Disarm ST Home Monitor but 1 motion sensor still active with notificationx
(D) #53

I would like to know what virtual items are and what they are used for. How do I search these forums to find an answer to that and other questions as such that I may have regarding SmartThings and programming it? The answer to what a virtual item would be great, but teaching me how to find that answer within these walls. Thanks in advance


(Mark) #54

There’s a magnifying glass icon at the top of the page that can be used to search for keywords as well as user handles. The search function isn’t all that great, but try “virtual” + “FAQ” and you should find a topic that’s pretty helpful.

You’d also likely be interested in the community wiki if you haven’t checked it out yet.

http://thingsthataresmart.wiki/index.php


#55

I just installed the 3 smart apps (switchmania, virtual switch, switch calls routine) & 3 Device Handlers (presence, dimmer, momentary) but when i try to create a “On/Off Button Tile” or “Momentary Button Tile” I get “an unexpected error occured”. I can only create the “virtual dimmer” or “Simulated presence sensor.” Am i missing something?


#56

having same issue as @Jrrobertson3

@infofiend Where can I get the (1) SmartThings’ default “On/Off Button Tile” DTH ??

I have the other dth published
(2) Michael Struck’s “Momentary Button Tile” DTH, this DTH shows up as ‘smartthings’ definition (name: “Momentary Button Tile”, namespace: “smartthings”, author: “SmartThings”) not sure if this would break the code or not
(3) Michael Struck’s “Virtual Dimmer” DTH, and
(4) infofiend’s “Simulated Presence Sensor” DTH.


(Devesh Batra) #57

having the same error trying to create a Virtual switch… thanks


(Lewis) #58

I get the error as well. Any fix to this? Here are my DTH’s and SmartApps:

image


(Lewis) #59

What am I missing? Also could you suggest where I may find it?

Thanks


(Lewis) #60

I also cannot find it


(Lewis) #61

I am missing the SmartThings’ default “On/Off Button Tile” DTH can someone advise where I can get this please?


(Lewis) #62

Well, SwitchMania doesn’t work thats my conclusion. I have spent x3 evenings pissing about with this thread and im getting nowhere fast.

So I have found this: FAQ: Creating a virtual Device

Manually creating vSwitches is going to be easier than getting SwithMania to work (which you probably won’t be able to).