Make any handler a virtual device?

Is there a way to take a non-simulated or virtual device handler and convert it into a simulated device? I’m trying to find a way to take the acceleration sensor handler that’s in the IDE and make it a simulated acceleration sensor for use in webCoRE. Tried already and there aren’t any commands to make it active/inactive.

Yes … If you modify the source code. But you have to find the source code so that you can add Commands to set its Attributes.

Here is where you can find the source for Multi:

Ok so I found the one I’m looking for but not sure what to do with it. Looks short and simple compared to some other ones I’ve seen though.

Remember the one for the switch where you took out action? Try the reverse for this one.

So my first attempt didn’t work out. This was what I removed from the simulated switch to get rid app control

action: “switch.on”

So I didn’t know what to use for the handler I’m trying to create whether it’s still the same:

action: “switch:on”

But I’m getting this error

A Sensor (acceleration) won’t have any Tiles for you to enable or disable; but you can create Tiles if you want to trigger it manually.

But you will have to create Commands and methods for each Command to initiate Activity.

Are you just looking for Activity or for specific orientation (e.g., like a Tilt sensor)?

Active and Inactive is all I’m looking for.

So… I prefer not to try to code via Forum Post … My time is worth more than that.

I don’t know how familiar you are with DTH Groovy coding though.

You need to add:

command "setActive"
command "setInActive"

def setActive() {
    sendEvent( ... blah, blah)

def setInActive {
   sendEvent( ... blah, blah)

That’s pretty much sufficient. The command Methods (def …) should be similar to what you can find in other Virtual / Simulated DTHs like Contact, etc… - If you can find the code for them anywhere, or SmartThings GitHub.

For further assistance, PM me for my tutorial or consulting fee rate.

1 Like

So I tried a couple things but guess I’m in over my head. Looked at this simulated motion sensor and saw what you’re talking about and basically added this section and changed motion to acceleration.

Motion Handler:

My Attempted Handler:

And then added this up at the top.

But still get this error. Line 15 is the line with the name so I’m not sure what I’m even doing wrong there since all I did was change name and that’s never caused problems before with edits I’ve made.

Go to My Device Types and start brand new.

Paste your raw code from here:

This compiles fine for me (save & publish). I haven’t tried executing it.

1 Like

The error messages and your code appear to be littered with ‘smart quotes’ instead of bog standard straight double quotes. If that is indeed what you have it would cause the error shown.

Oh and the ‘command’ lines need to be inside the ‘definition’ section and not the ‘simulator’.

1 Like

My apologies - that code there was just what I was using as a model for what simulated devices should look like.

So… Please put your current non-functiona full DTH code into GitHub or a Gist or Pastebin so that we can actually see where the error might be.

Screenshots of code aren’t helpful, unfortunately.

Throughout your code, these fancy (6699) quotes break everything. Be sure to use a real code editor (Notepad++ for example) when … coding.

1 Like

Are those supposed to be single quotes or…? Understand what you’re saying and will have to probably try on my desktop, but literally copied that from GitHub and then just made edits like you suggested and changed the name. I’ve tried in Clone and Working Copy. Thanks.

They are supposed to be simple double quotes. Your editing program, source file, or paste tool is messing them up.

Only copy from raw text sources.

"good quotes" 
“bad quotes”

Download and use Notepad++ or another good coding editor.

1 Like

So I tried again with a different editor on my iPhone just to see if something else would work and no errors this time. All I need to do now is add the action like @eibyer suggested? Also should the “motion” be changed to acceleration in this section? Thanks again for your help.

The Attribute name is acceleration.

1 Like

And check line 45 is spelling.