Custom Capability and CLI Developer Preview

looking at the " [SmartThings Schema connector]" tutorial, I really doubt that I need it.
I already have my device commands. They were working fine with the old ST app.
I just need buttons to bind to these commands on the new ST app.

The “push” event? Wouldn’t such a thing violate the capability schema?

I use Momentary in components but always in conjunction with other capabilities such as Button to provide the event.

You could use the List Display type and add the different options for the Coffee Machine there.

The capability presentation would be similar to this one

"detailView": [
        {
            "label": "List Element",
            "displayType": "list",
            "list": {
                "state": {
                    "value": "listElement.value",
                    "alternatives": [
                        {
                            "key": "espresso",
                            "value": "Espresso"
                        },
                        {
                            "key": "capuccino",
                            "value": "Capuccino"
                        }
                    ]
                },
                "command": {
                    "name": "setListElement",
                    "alternatives": [
                        {
                            "key": "espresso",
                            "value": "Espresso"
                        },
                        {
                            "key": "capuccino",
                            "value": "Capuccino"
                        }
                    ]
                }
            }
        }
    ]

In your DTH you can receive the event and the option selected as an argument.

def setListElement(argument){
    // call other functions
    //Update the capability value
	sendEvent(name: "listElement", value: "${argument}")
}
1 Like

thanks. that is a good idea. (if it works)
I will try in a few minutes.

can I add this list element to a switch ? (which will actually turn on/off the machine)
and a state which will show the last ordered coffee ?

and should I add any attributes or commands here when creating the capability ?
smartthings.exe capabilities:create
? Capability Name: coffeemachineselect
? Select an action
 (Use arrow keys)

Add an attribute
Add a command

Below is the capability definition from my example. During the capability creation, I added the attribute listElement and selected (Y) in "Add a setter command for this attribute?" (which is setListElement)

{
    "name": "List Disp",
    "attributes": {
        "listElement": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setListElement",
            "enumCommands": []
        }
    },
    "commands": {
        "setListElement": {
            "name": "setListElement",
            "arguments": [
                {
                    "name": "value",
                    "optional": false,
                    "schema": {
                        "type": "string"
                    }
                }
            ]
        }
    }
}

Do you mean if it’s possible to use the switch and list capability in the same device?
For the last ordered coffee, updating the list capability value, the last option selected will be shown.

I’ve added a new capability with name “faithboard04631.coffeemachineselect”

I used the following code as you suggested:

{
"detailView": [
        {
            "label": "Order Item",
            "displayType": "list",
            "list": {
                "state": {
                    "value": "listElement.value",
                    "alternatives": [
                        {
                            "key": "espresso",
                            "value": "Espresso"
                        },
                        {
                            "key": "capuccino",
                            "value": "Capuccino"
                        }
                    ]
                },
                "command": {
                    "name": "setListElement",
                    "alternatives": [
                        {
                            "key": "espresso",
                            "value": "Espresso"
                        },
                        {
                            "key": "capuccino",
                            "value": "Capuccino"
                        }
                    ]
                }
            }
        }
    ],
	    "id": "faithboard04631.coffeemachineselect",
    "version": 1
}

then I added this capability to my DTH:

capability "faithboard04631.coffeemachineselect"

and added the code for accepting command:

def setListElement(argument){
    // call other functions
    //Update the capability value
	sendEvent(name: "listElement", value: "${argument}")
}

but it does not display a selectable list.
all I see is this :

why isn’t it selectable ?

I added the attribute and command as in your example (actually I just updated my capability with the json you’ve supplied)

But I still don’t see a selectable list. It only displays the label I’ve given (Order Item) and a cloud icon.

Do you mean if it’s possible to use the switch and list capability in the same device?

yes, I want to use a switch capability. but what command will the default switch will call ?

is it a bug?

The Switch capability generates the commands on() and off(). You would need to add those commands in the DTH.

That can be because its presentation is not being read or the value wasn’t initialized. Make sure you updated the device presentation and sent the event to initialize the attribute:
sendEvent(name: "listElement", value: "espresso")
I can see correctly the capability:

ok. now it works.
but when I select an item, the button goes in a turning animation and after 15-20 seconds it says a network error has occured.

my command is just sending event at the moment:

def setListElement(argument){
	sendEvent(name: "listElement", value: "${argument}")
    sendEvent(name: "faithboard04631.coffeemachine.lastorder", value: "${argument}", isStateChange: true, displayed: true)
    log.debug "${argument}"
}

any idea why I get the “network error has occured” warning ?

what may be causing the network error ?

and is it possible to use a custom icon ?
seeing a presence sensor for a coffee machine is not nice

Hi again,

I’ve retried to create a presentation with a slider for MyVirtualZone DTH.
Now, I can see that the slider is part of the presentation (see json excerpt below, last item at the bottom).

I’ve updated the DTH with the new vid, but still, I cannot see the slider in the detailed view when I click on the device (after forcing a cache refresh by changing the device type)


What’s wrong?

"C":\caps>smartthings presentation XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -j{
"manufacturerName":"SmartThingsCommunity",
"presentationId":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"mnmn":"SmartThingsCommunity",
"vid":"XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
"iconUrl":null,
"dashboard":{
    "states":[
        {
            "label":"{{temperature.value}} {{temperature.unit}}",
            "alternatives":[
                {
                    "key":"C",
                    "value":"°C",
                    "type":"active",
                    "iconUrl":null,
                    "description":null
                },
                {
                    "key":"K",
                    "value":"°K",
                    "type":"active",
                    "iconUrl":null,
                    "description":null
                },
                {
                    "key":"F",
                    "value":"°F",
                    "type":"active",
                    "iconUrl":null,
                    "description":null
                }
            ],
            "group":null,
            "capability":"temperatureMeasurement",
            "version":1,
            "component":"main",
            "visibleCondition":null
        }
    ],
    "actions":[
        
    ],
    "basicPlus":[
        
    ]
},
"detailView":[
    {
        "capability":"temperatureMeasurement",
        "version":1,
        "label":"___PO_CODE_SMARTTHINGS_DREAM_SAC_TMBODY_TEMPERATURE",
        "displayType":"slider",
        "toggleSwitch":null,
        "standbyPowerSwitch":null,
        "switch":null,
        "slider":{
            "range":[
                -20,
                50
            ],
            "step":null,
            "unit":"temperature.unit",
            "command":null,
            "argumentType":null,
            "value":"temperature.value",
            "valueType":"number"
        },
        "pushButton":null,
        "playPause":null,
        "playStop":null,
        "list":null,
        "textField":null,
        "numberField":null,
        "stepper":null,
        "state":null,
        "multiArgCommand":null,
        "component":"main",
        "visibleCondition":null
    },
    {
        "capability":"switch",
        "version":1,
        "label":"___PO_CODE_SMARTTHINGS_DREAM_SAC_TMBODY_POWER",
        "displayType":"standbyPowerSwitch",
        "toggleSwitch":null,
        "standbyPowerSwitch":{
            "command":{
                "name":null,
                "on":"on",
                "off":"off"
            },
            "state":{
                "value":"switch.value",
                "on":"on",
                "off":"off",
                "label":"{{switch.value}}",
                "alternatives":[
                    {
                        "key":"on",
                        "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_ON_T_SAMSUNG_CONNECT",
                        "type":"active",
                        "iconUrl":null,
                        "description":null
                    },
                    {
                        "key":"off",
                        "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_OFF_T_SAMSUNG_CONNECT",
                        "type":"inactive",
                        "iconUrl":null,
                        "description":null
                    }
                ]
            }
        },
        "switch":null,
        "slider":null,
        "pushButton":null,
        "playPause":null,
        "playStop":null,
        "list":null,
        "textField":null,
        "numberField":null,
        "stepper":null,
        "state":null,
        "multiArgCommand":null,
        "component":"main",
        "visibleCondition":null
    },
    {
        "capability":"contactSensor",
        "version":1,
        "label":"___PO_CODE_SMARTTHINGS_DREAM_SAC_TMBODY_CONTACT_SENSOR",
        "displayType":"state",
        "toggleSwitch":null,
        "standbyPowerSwitch":null,
        "switch":null,
        "slider":null,
        "pushButton":null,
        "playPause":null,
        "playStop":null,
        "list":null,
        "textField":null,
        "numberField":null,
        "stepper":null,
        "state":{
            "label":"{{contact.value}}",
            "alternatives":[
                {
                    "key":"open",
                    "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_OPEN",
                    "type":"active"
                },
                {
                    "key":"closed",
                    "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_CLOSED",
                    "type":"inactive"
                }
            ]
        },
        "multiArgCommand":null,
        "component":"main",
        "visibleCondition":null
    },
    {
        "capability":"motionSensor",
        "version":1,
        "label":"___PO_CODE_SMARTTHINGS_DREAM_SAC_TMBODY_MOTION_SENSOR",
        "displayType":"state",
        "toggleSwitch":null,
        "standbyPowerSwitch":null,
        "switch":null,
        "slider":null,
        "pushButton":null,
        "playPause":null,
        "playStop":null,
        "list":null,
        "textField":null,
        "numberField":null,
        "stepper":null,
        "state":{
            "label":"{{motion.value}}",
            "alternatives":[
                {
                    "key":"active",
                    "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_MOTION_DETECTED",
                    "type":"active"
                },
                {
                    "key":"inactive",
                    "value":"___PO_CODE_SMARTTHINGS_DREAM_SAC_SBODY_NO_MOTION",
                    "type":"inactive"
                }
            ]
        },
        "multiArgCommand":null,
        "component":"main",
        "visibleCondition":null
    },
    {
        "capability":"XXXXXXXXXXXXXXXXX.setZoneSetpoint",
        "version":1,
        "label":"Set ZoneSetpoint",
        "displayType":"slider",
        "toggleSwitch":null,
        "standbyPowerSwitch":null,
        "switch":null,
        "slider":{
            "range":[
                0,
                100
            ],
            "step":1,
            "unit":"zoneSetpoint.unit",
            "command":"setZoneSetpoint",
            "argumentType":"integer",
            "value":"zoneSetpoint.value",
            "valueType":"integer"
        },
        "pushButton":null,
        "playPause":null,
        "playStop":null,
        "list":null,
        "textField":null,
        "numberField":null,
        "stepper":null,
        "state":null,
        "multiArgCommand":null,
        "component":"main",
        "visibleCondition":null
    }
],

Here is my custom capability definition:

"C":\caps>smartthings capabilities "id":"XXXXXXXXXXXXXXXXX.setZoneSetpoint" - j {
"id":"XXXXXXXXXXXXXXXXX.setZoneSetpoint",
"version":1,
"status":"proposed",
"name":"Set Zone Setpoint",
"attributes":{
    "zoneSetpoint":{
        "schema":{
            "type":"object",
            "properties":{
                "value":{
                    "type":"integer",
                    "minimum":0,
                    "maximum":100
                }
            },
            "additionalProperties":false,
            "required":[
                "value"
            ]
        },
        "setter":"setZoneSetpoint",
        "enumCommands":[
            
        ]
    }
},
"commands":{
    "setZoneSetpoint":{
        "name":"setZoneSetpoint",
        "arguments":[
            {
                "name":"value",
                "optional":false,
                "schema":{
                    "type":"integer",
                    "minimum":0,
                    "maximum":100
                }
            }
        ]
    }
}

}

any idea on these ?

To change the device icon, you need to add the properties ocfDeviceType and deviceTypeId in your DTH. For example, the values for a RemoteController icon would be:

  • ocfDeviceType:“x.com.st.d.remotecontroller”
  • deviceTypeId: “RemoteController”

You can see the available categories here.

I got the values of my example by creating a device profile in the developer workspace and selecting the category I wanted. Then I got the profile’s JSON with the CLI (they are located in the “metadata” section):

smartthings deviceprofiles deviceprofileID -j

About this, I changed my capability presentation to use the same configuration as yours, it works correctly, but using your capability in my DTH I see the error you mentioned, perhaps when updating your capability, something occurred (I’m investigating more about it, please don’t delete it).

To fix this, work with another capability, one that already exists, and update the definition and presentation. This is because the creation of a new capability presentation is not available yet.

thanks.
I got it. I had to use the Dryer type, as in the icon image it seemed close to a Coffee Machine.
So I used the following value pair in the device definition:
ocfDeviceType: "oic.d.dryer", deviceTypeId: "Dryer"

But before that, I tried “Water heater” with these values:
ocfDeviceType: "x.com.st.d.waterheater", deviceTypeId: "Water heater"

that one didn’t work.

is it possible to use any custom icons btw ?

I didn’t understand that.
I don’t know how how to edit a capability that already exists.
In fact, I didn’t understand what you mean by that. I only have the capabilities that I created for this device. Since I created them all , they are all in same condition.

and what do you mean by :
“creation of a new capability presentation is not available yet.”

isn’t this what I am trying to do ?

The feature to use custom icons is not available yet. Our team is working to support this in a future release, however, there’s no ETA that we can share at this point.

Sorry for the confusion. What I meant is that you can use a capability that is not included in another device but has its presentation already created with smartthings capabilities:presentation:create because this function is being fixed by the engineering department.
These commands are used to update the definition and presentation of the capability

smartthings capabilities:update capabilityID 1 -j -i capabilityDef.son 
smartthings capabilities:presentation:update capabilityID 1 -i capabilityPres.son

any update on the roadmap? if your managers are keeping you from sharing it just blink twice :wink:

2 Likes