SmartThings virtual devices using CLI

Now it’s possible to make virtual devices using CLI

Following commands are added to CLI

smartthings virtualdevices [ID]
smartthings virtualdevices:create
smartthings virtualdevices:create-standard
smartthings virtualdevices:delete [ID]
smartthings virtualdevices:events [ID] [NAME] [VALUE] [UNIT]
smartthings virtualdevices:update [ID]

More information from
GitHub - SmartThingsCommunity/smartthings-cli: Command Line Interface for the SmartThings APIs.

I made one using command

$ smartthings virtualdevices:create-standard # interactive mode

Virtual switch in IDE

3 Likes

Interesting!

@TAustin @ygerlovin

1 Like

Typical, I’ve been avidly watching and waiting for these to go live, and then as soon as I finally get hit by the dreaded lurgy out they pop.

1 Like

smartthings virtualdevices:create-standard

You can create a device from one of the standard prototypes

Select a device prototype. 3
────────────────────────────────────────────────────

Name Id

────────────────────────────────────────────────────
1 Switch VIRTUAL_SWITCH
2 Dimmer Switch VIRTUAL_DIMMER_SWITCH
3 Button VIRTUAL_BUTTON
4 Camera VIRTUAL_CAMERA
5 Color Bulb VIRTUAL_COLOR_BULB
────────────────────────────────────────────────────
6 Contact Sensor VIRTUAL_CONTACT_SENSOR
7 Dimmer (no switch) VIRTUAL_DIMMER
8 Garage Door Opener VIRTUAL_GARAGE_DOOR_OPENER
9 Lock VIRTUAL_LOCK
10 Metered Switch VIRTUAL_METERED_SWITCH
────────────────────────────────────────────────────
11 Motion Sensor VIRTUAL_MOTION_SENSOR
12 Multi-Sensor VIRTUAL_MULTI_SENSOR
13 Presence Sensor VIRTUAL_PRESENCE_SENSOR
14 Refrigerator VIRTUAL_REFRIGERATOR
15 RGBW Bulb VIRTUAL_RGBW_BULB
────────────────────────────────────────────────────
16 Siren VIRTUAL_SIREN
17 Thermostat VIRTUAL_THERMOSTAT
────────────────────────────────────────────────────

Hmm, this is indeed interesting. I think I can see where they are going but I am not totally sure.

I would describe the virtual devices as being like a wrapper for capabilities. Something like the standard virtual switch has the switch and refresh capabilities with the usual switch attribute and on and off commands so works rather like we are used to. However the standard virtual presence only has the presenceSensor and refresh capabilities so there aren’t any commands to set the presence attribute. The only way to do that seems to be to use the API to send the events (and I found that I had to be the Location owner for those to work). So that isn’t what we are used to, but why should it be?

I haven’t looked to see if the commands implemented are limited to enum and setter commands, which obviously have a direct correspondence with certain attributes. I guess there could be more fancy command mapping to come. Similarly I’d imagine there will the a cloud v local option in future.

On iOS, I can get this with these virtual devices: when I create one, it may show up right away in the mobile and you can tap on it to go into device Controls, but I may get nothing but a blank page - not even a way to navigate back out. The only option is to shut down the app and restart. I repeated this procedure several time last evening then gave up. Today, the device is properly displaying and functional. :face_with_diagonal_mouth:

Here’s a bit of an anomoly: if you create a refrigerator virtual device, it uses the thermostatCoolingSetpoint capability in both the main and freezer components. However that capability only allows you to set it to a low of freezing (32 degrees F / 0 degrees C). Not very useful for a freezer thermostat where you typically have it a few degrees BELOW freezing.

@nayelyz FYI.

1 Like

Have you checked if changing the range in the device-config helps? The capability definition allows a range of -460 - 10000 but I know this and heatingSetpoint are a little tricky, specially related to the unit used in the location and the events.

How would I do this? I see the range in the device presentation and I don’t know how to change that short of creating a custom capability and presentation.

What are you referring to here? An option would be to create a custom capability but remember those are not supported in some third-party integrations like Alexa.

To change the range of a capability (this affects only the presentation, not the definition), you need to do something like this in the device-config to create a custom presentation:

{
    "component": "main",
    "capability": "thermostatCoolingSetpoint",
    "version": 1,
    "values": [
      {
        "key": "coolingSetpoint.value",
        "range": [
          -4,
          80
        ],
        "step": 1
      }
    ]
}

Note: The value in step depends on the β€œjumps” you want to allow for the - and + symbols. This way, the value will increase/decrease in that amount. For example,if it’s 0.5, the value will change between 12.0 to 12.5

You showed me something new! I did not know you could do that. Thank you!

2 Likes

Hi @nayelyz

Since you mention it, I think there are other thing that must have been broken with the app updates.

The temperature steps work by clicking on the β€œ+” or β€œ-”, but if you want to enter a value directly with the keyboard it does not work well.

In steps of 0.1Β° is empty and impossible enter a value.
In 0.5Β° steps you can enter them, but it doesn’t show the current value, it’s empty too

I see that Isabelle has created a pull request for a Virtual Switch driver (covers switch, dimmer and dimmer-switch). Looks stateless to match the DTH. Interesting.