Custom Capability and CLI Developer Preview

Hi, nayelyz,

This is a simple one that shows the behavior. (The issue exists with or without the inclusion of Actuator and Sensor, as well as with ocfDeviceType, DeviceType, DeviceTypeId of various values.)

metadata {
	definition (name: "Test Activity",
				namespace: "panelgreen44005", author: "JDCH", 
				vid: "34276cac-5f4e-3c3d-9ed7-fc6d97cbb2c3", mnmn: "SmartThingsCommunity") 
	{
		capability "Actuator"
		capability "Sensor"
        capability "panelgreen44005.activity"
	}
}

def installed() {
	log.debug "installed()..."	
	sendEvent(name: "activity", value: "inactive")
}
def updated() {
	log.debug "updated()..."
    installed()
}
def uninstalled() {
	log.warn "uninstalled()..."
}

def setActivity(String newValue) {
	log.info "setActivity to ${newValue}"
	sendEvent(name: "activity", value: newValue)
}
def activate() {
	log.info "activate"
	sendEvent(name: "activity", value: "active")
}
def deactivate() {
	log.info "deactivate"
	sendEvent(name: "activity", value: "inactive")
}

The only thing I can see that is any way exotic is the "group": "main" in the capability presentation for your custom capability.

ā€œThe group name to which this belongs. Some complex devices can be shown grouped in the dashboard card. This is used for grouping states and actions in the dashboard.ā€

Can’t say I am particularly enlightened by that description.

1 Like

Yeah, I agree with @orangebucket.
This property is used to group the states of the capabilities according to the given value and show them in the Dashboard View.
The picture below belongs to a device that shows the states of two different capabilities (VID: 7a763ca9-9c87-3fd2-81cb-edbe58a62f16):


If you want to show just one state, you have to remove the group property and update the capability presentation. Then, you need to re-generate the device presentation (the VID won’t change) and, as you’re using a DTH, I suggest you create a new one (with the same configuration) to avoid the caching process.

2 Likes

Thanks, @orangebucket and @nayelyz! This worked, although it still required a new device presentation and VID to avoid the cache issues (even after creating a new dth). No worries there, sort of routine to add bogus tweaks (oh, Actuator detailView) for fresh VIDs.

Another case of confusing documentation, as the ST API doc includes examples of single-attribute dashboards with the group:main setting. Thought it was strange, not nearly as clear as its usage in multiple-attribute devices (parent/child, etc.) … but I trusted the doc instead of my gut. Next time, I’m coming here sooner … everyone was great. Thanks.

1 Like

In controlling the state of the icon, can it be accomplished with the ā€˜switch’ capability alone? I’ve tried, and nothing ever changes, unless I have a custom capability with values and types set to active/inactive.

If my custom capability is just a message string, not indicating on/off information, but something different like this:
image

… then the icon does does not change status with the switch on/off events.
I’ve tried creating a third capability for a ā€œpowerStateā€ to change the status of the icon, but then my status string isn’t displayed like in the image; only the ā€œpowerStateā€ of On/Off is displayed.

1 Like

Hi! Up to now, the icon status can be controlled only through the Dashboard > States. If the capability used in this section does not have active/inactive alternatives, the icon will remain static.

I’m not sure I properly described what I am trying to do. I understand the controlling of the icon status by the dashboard>states, but what I would like to have is what you see in the first image of a dashboard, but I can only get what is in the second dashboard in controlling the icon status:
image

I want the state of the toggleSwitch (a custom capability in this case) to control the icon (on/off), but have my second capability’s status appear in the status line. So, regardless of the state of the icon (in this case the standby power of the device), the status line is to display some other information.

Again, in setting up the dashboard>state to control the icon, its value of ā€˜On’/ā€˜Off’ gets displayed, which is not what I want to accomplish. Cannot I have two capabilities for the dashboard, with one’s state controller the icon status?

So, I’ve been reading these threads and discussions, and thought I’d install the CLI, but I’m a little new to Github and forkin’ and stuff.

But, I’ll start with a simple question, and may come back with more unless there is a remedial developer thread somewhere that I’ve missed.

Anyway… starting with essentially a blank slate, what are the dependencies of the CLI. I sort of haphazardly installed the CLI, and added the path… verified permissions…before really thinking about the prerequisites.

any bit of help would be appreciated

Yeah, I understand you clearly but that’s not possible right now. However, you can send an email to build@smartthings.com and mention you’d like to make a Feature Request for the Use Case you posted above.

Do you mean if you need other software to use the CLI?
It can depend on the OS you’re using because you might need to install some dependencies, but you can do it using NPM and for that you have to install NodeJS. (Here’s a guide you can follow to do so)
Generally, you just need to make sure of having:

  • The CLI’s last release (you need to access to this file from the terminal, go to its directory when you want to execute commands like smartthings ...
  • The config.yaml file with your Personal Access Token

If you run a simple command like the one below and the result is the list of devices you have registered in your account, then, it’s working correctly:

smartthings devices

1 Like

I appreciate the reply, Nayelyz. It’s been a while since I have worked with command lines, other than telnet, device configuration etc…

Yes, and It’s Windows 10. I did download Node.JS and attempted to perform those steps, however I’m starting to believe there may be a corrupt installation.

So, I think I will attempt to uninstall and reinstall Node.JS. and have another look at the link you provided.

Thanks, and I will followup.

1 Like

As always, thank-you for help. If it wasn’t for you and the others, we all definitely wouldn’t be getting anywhere since the official docs are barely ā€œadequateā€ at this point in time…

2 Likes

Can anyone provide working example jsons of the capability and presentation for a ā€˜state’ where the each of the possible values for the state can be used on the if side of an automation

I’m not entirely sure I have what you want, but perhaps look at circlemusic21301.sthmStatus. You can pull the JSON using the CLI.

In the Automations View only the display types ā€œsliderā€, ā€œlistā€, ā€œnumberFieldā€ and ā€œtextFieldā€ are supported for the condition section.
As I understand, you have a capability that uses the state display type in Detail View and you don’t have a determined list of values, is this correct?
If so, you can use the textField display type in the Automations View, so you can type the value you want the condition to match. Here’s an example:

{
    "dashboard": {
        "states": [
            {
                "label": "{{attr.value}}"
            }
        ],
        "actions": [],
        "basicPlus": []
    },
    "detailView": [
        {
            "label": "Current text value",
            "displayType": "state",
            "state": {
                "label": "{{attr.value}}"
            }
        }
    ],
    "automation":{
        "conditions":[
            {
                "label": "Text value condition",
                "displayType": "textField",
                "textField": {
                    "value": "attr.value"
                }
            }
        ],
        "actions":[
            {
                "label": "Text value action",
                "displayType": "textField",
                "textField": {
                    "command": "setAttr",
                    "range": [
                        0,
                        10
                    ]
                }
            }
        ]
    }
}

that’s kinda nifty. I didn’t even know if was possible to have a text field condition in an automation IF.

I can’t seem to get it to work right.

I ran smartthings capabilities:create and named my capability binstatus
I gave it the attribute binStatus, and said yes to make the setter command setBinStatus. I made a ā€˜state’ presentation json based on what orange bucket shared earlier:

{
    "dashboard": {
        "states": [
            {
                "label": "{{binStatus.value}}",
                "alternatives": [
                    {
                        "key": "full",
                        "value": "Full",
                    },
                    {
                        "key": "normal",
                        "value": "Normal",
                    }
                ]
            }
        ],
        "actions": [],
        "basicPlus": []
    },
    "detailView": [
        {
            "label": "Bin Status",
            "displayType": "state",
            "state": {
                "label": "{{binStatus.value}}",
                "alternatives": [
                    {
                        "key": "full",
                        "value": "Full",
                    },
                    {
                        "key": "normal",
                        "value": "Normal",
                    }
                ]
            }
        }
    ],
    "automation": {
        "conditions": [
            {
                "label": "Bin Status",
                "displayType": "list",
                "list": {
                    "alternatives": [
                        {
                            "key": "full",
                            "value": "Full",
                        },
                        {
                            "key": "normal",
                            "value": "Normal",
                        }
                    ],
                    "value": "binStatus.value"
                }
            }
        ],
        "actions": []
    },
    "id": "circlefield05082.binstatus",
    "version": 1
}

I successfully uploaded it and created a device config and got the capability to display.

HOWEVER, when I do
sendEvent: (name: 'binStatus', value: 'normal')
it doesn’t work.

What am I doing wrong here? I just want the UI to display ā€˜Full’ or ā€˜Normal’ inside the Bin Status area.

this is what I got from smartthings capabilities:create

{
    "id": "circlefield05082.binstatus",
    "version": 1,
    "status": "proposed",
    "name": "binstatus",
    "attributes": {
        "binStatus": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setBinStatus",
            "enumCommands": []
        }
    },
    "commands": {
        "setBinStatus": {
            "name": "setBinStatus",
            "arguments": [
                {
                    "name": "value",
                    "optional": false,
                    "schema": {
                        "type": "string"
                    }
                }
            ]
        }
    }
}

@nayelyz @jking
Any updates regarding this issue?
I’m trying to create a new presentation for my nearly created capability and I’m getting the same error.:confused:

"error":{"code":"4030000"
,"message":"Only certain users are allowed to modify standard Capabilities","details":[]}}

yeah, when you create a new presentation, you need to add the id and version properties at the bottom, for example:

{
    "dashboard": {
        ...
    },
    "detailView": [
        ...
    ],
    "automation":{
        ...
    },
    "id": "namespace.capabilityName",
    "version": 1
}

Once you add them, you should be able to create the presentation.

That could be causing the error, it should be something like:

sendEvent(name: 'binStatus', value: 'normal')

If you get the device status and the current value of binStatus is null, it means the event is not being sent correctly.