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

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.

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?

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

What DTH are you using for the momentary switch?

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!

@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.

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.

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

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

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?

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.

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

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

image

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

Thanks

I also cannot find it

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

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).

1 Like

After about 10 minutes of manually creating a virtual device I do indeed conclude that SwitchMania nothing more than a waste of time.

Not for me. It has worked from day one and creating virtual devices has never been easier.

YMMV

2 Likes

For those that want to use this smart app but are discouraged by it not working - I just installed it and it worked fine, but does appear to require a tiny bit of tweaking. Here are the steps I used:

  1. Log into the smartthings IDE @ https://account.smartthings.com [edited]
  2. Go to infofiend’s repository and install everything you can.
  3. In the IDE go to ‘device handlers’ and ‘+ create new device handler’ and select ‘from code’
  4. From infofiends respository, paste the code in for the following device types:
    4a. Device One: ‘Momentary-Button-Tile.groovy’ then select “Create” --> ‘Publish’ -> ‘For me’
    (repeat step 3)
    4b. Device Two: ‘simulated-presence-sensor.groovy’ then select “Create” -->‘Publish’ -> ‘For me’
    (repeat step 3)
    4c. Device Three: ‘virtual_dimmer’ then select “Create” --> ‘Publish’ -> ‘For me’

…but wait, you need 4 devices! The 4th device can be pulled direct from smartthings IDE.

  1. Device Handlers --> Create New Device Handler --> From Template
  2. Select On/Off Button Tile. select “Create” --> ‘Publish’ -> ‘For me’

Next its onto the smart apps. Similar procedure, but under ‘My Smart Apps’

  1. ‘My Smart Apps’ --> ‘+New SmartApp’ --> ‘From Code’
    8a - 8c. Paste in, create, and publish the code for the following items in the infofiend repository:
    a. my-switch-calls-routines-app.groovy
    b. my-virtual-switch-creator.groovy
    c. switch-mania.groovy

the ‘trick’. What made it finally all work for me was making one minor tweak to the code.

  1. Under ‘My SmartApps’ --> ‘My Virtual Switch Creator’ on lines 56 - 64 it lists the different switch types you installed. However, it lists the ‘Momentary Button Tile’ switch as “MichaelStruck”. I don’t have that version, for whatever reason - that’s not what was in the infofiend repository (at least that I installed). So you have to change that line to “smartthings” as follows:

def childDevice = addChildDevice(“smartthings”, “Momentary Button Tile”, deviceId, null, [label: switchLabel])

Blockquote

Make that change and hit publish. App seems to be working. Haven’t done a full test with everything, but it at least creates the switches without errors as others previously reported.

That’s all I know. Hope this helps.

1 Like

FYI: don’t direct people here. This is only a portion of people’s shard and doesn’t redirect them correctly.

When logging into SmartThings, use:

https://account.smartthings.com

Then they are directed appropriately to their shard (graph.api… na04-east1)

3 Likes