Make any handler a virtual device?

:roll_eyes:

I can’t believe we’re debugging typos. C’mon @GRClark … you gotta do your part :wink: !

2 Likes

Ok trying again. Sorry for the typo. I’ve corrected spelling and added the action. Updated device which changed the look of it in app and it gives the haptic feedback like you’d get when switching stuff on/off in SmartThings app but it’s not actually changing the setting from inactive to active.

https://pastebin.com/4eR6Fys6

Please read your code carefully. The Tile is still calling SWITCH off and on.

    tiles {
        standardTile("acceleration", "device.acceleration", width: 2, height: 2) {
            state("inactive", label:'${name}', action: "switch.off", icon:"st.motion.acceleration.inactive", backgroundColor:"#cccccc")
            state("active", label:'${name}', action: "switch.on", icon:"st.motion.acceleration.active", backgroundColor:"#00A0DC")
        }

I was wondering if that was supposed to stay the same since I wanted it to be switched on and off. Thanks. It should be acceleration then right?

Still no joy. Won’t switch back and forth.

https://pastebin.com/We5ey0X1

You are not using the right syntax in the Tile for calling the ad hoc added Commands.

Please read the documentation and more example virtual / Simulated devices like Virtual Contact, etc.

Ok I see how it’s supposed to work I think - action needs to be the opposite state of what it is. So active’s action should be inactive right? I got it to switch state from inactive to active but it immediacy switches back on its own. There’s no smartapps or automations associated with device so it’s gotta still be the code. Sorry for being a pain.

https://pastebin.com/gcJTaNvX

The action needs to be the Command to call.

I think it’s device.commandname but you’re going to have to look it up in docs or another example DTH.

This is where I abandon you - but PM for paid consulting available.

1 Like

The ‘action’ is the command you want to run when you press the button on the mobile app. If you are currently ‘inactive’ you want the button to run the command to make you become ‘active’ so the action is “SetActive” in your case.

Don’t be tempted to write “acceleration.SetActive”. That form only works for commands that are standard for capabilities. For custom commands you just use the command name as used in your device handler.

1 Like

Guess I’m not following you. You seemed to have predicted my thought process because in the first praragraph it made me want write exactly what you told me not write in the second paragraph. I tried it anyway and definitely doesn’t work. It’s just weird how with the most recent version I’ve done that it’ll switch for a brief second and then it goes right back. I’ve tried reading some of the documentation and it’s like reading a foreign language right now. Oh well.

I can understand the confusion. I find nothing is ever quite explained fully enough in the documentation and some things you see are probably for back compatibility.

The bottom line is when you click on a button in the mobile app you end up running a method in your device handler. The ‘action’ parameter specifies which one it is. Just specify the name of that method in double quotes. For example action: "on" or action: "beep". In your case you have the methods SetActive() and SetInactive() so your possible actions are action: "SetActive" or action: "SetInactive".

Those will work, I tried them by editing your code a few hours ago. I’m mystified by the switching back you experienced, unless you have an automation getting involved already.

1 Like

No there weren’t any smartapps associated with the device. Tried what you’re saying and still no luck. Won’t even switch momentarily. :man_facepalming:

https://pastebin.com/cceaEbiT

I just pasted the code linked from your post into my IDE to create a new handler, published it, created a device using it, went to the Classic app on my phone and it worked fine for me.

1 Like

Just went back into SmartThings app and it works. Thanks so much. I really appreciate your help. I know I’ve been a pain on this post and appreciate people not just having given me the code. I want to learn and this hopefully will help me in the future as I’m off to try doing another one. Thanks again @eibyer, @tgauchat and @orangebucket!

3 Likes

Not wanting to create a whole new port but have another question. Removed the action from this simulated switch handler and wondering where in here does the labels get changed for on/off in this screenshot? I’d like them to either be “Armed” for on and “Disarmed” for off.

Open the handler and search for OFF and ON, I bet you’ll only have a few places to edit to find which one will do the job :slight_smile:

As far as I am aware that screen uses the labels from whatever was selected as the ‘main’ tile in each of the device handlers. The labels may say something like state: "on", label: '${name}' but it can be e.g. state: "on", label: "Armed" or anything you like really.

Since the labels used currently are capitalized in app I thought I’d find a spot in handler where they’re also capitozled, but none. I see the labels but they’re using a variable - should I replace variable with what I’d like for labels? And do I kee the single quotes or change to double quotes?

I assume they just fold the labels to upper case for cosmetic reasons. You can choose anything for the label really and you might as well use double quotes to match the other stuff though it isn’t going to make any difference in this particular case.

In Groovy "${name}" would normally substitute the value of the variable name into the string and '${name}' would literally include ${name}. The latter form is used because they do actually want to have a variable substitution eventually, but they want the mobile app to do it.

As you would guess, ${name} is the name of the value of the attribute: ‘on’, ‘off’ etc. In this particular device handler its not really gaining you a lot as you could just as easily type the values in.

Still no luck. I’ve done this before that’s why it’s frustrating.

Here’s what I just did with this one

Here’s one I did before for a Contact Sensor changed to be a doorbell sensor and changed the labels

image

https://pastebin.com/B1gYL0R9