[ST Edge] Custom capabilities presentation

Hi,
I’m trying to add a custom capabilities to switch edge driver.
I’m looking at standard energyMeter, powerMeter, voltageMeasurement and temperatureMeasurement and basically trying to create similar custom capabilities, for example currentMeter.

The capability definition (current-capability.json):

{
    "id": "xxx.currentMeter",
    "version": 1,
    "status": "proposed",
    "name": "Current Meter",
    "attributes": {
        "current": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "number",
                        "minimum": 0,
                        "maximum": 16
                    },
                    "unit": {
                        "type": "string",
                        "enum": [
                            "A"
                        ],
                        "default": "A"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "enumCommands": []
        }
    },
    "commands": { }
}

Capability presentation (current-capability-presentation.yml)

dashboard:
  states:
    - label: '{{current.value}} {{current.unit}}'
      alternatives: null
  actions: []
  basicPlus: []
detailView:
  - label: 'Current Meter'
    displayType: slider
    slider:
      range:
        - 0
        - 16
      step: null
      unit: current.unit
      value: current.value
      valueType: number
    state: null
automation:
  conditions:
    - label: 'Current Meter'
      displayType: numberField
      numberField:
        value: current.value
        valueType: number
        unit: current.unit
  actions: []
id: xxx.currentMeter
version: 1

I create the capability like this:

smartthings capabilities:create -i current-capability.json
smartthings capabilities:presentation:create xxx.currentMeter 1 -y -i=current-capability-presentation.yml

The presentation looks very similar to energy and power Meter.
However, it looks quite different:

  1. It doesn’t have historical button like energy, power and temperature
  2. It has a different slider
  3. It is modifiable, while the stock capabilities are read only

What am I missing?
Thank you

A short update.
I think I’ve got the answers in another thread from @nayelyz (thank you very much) for the first 2 questions:

  1. Historical button is not available for custom capability (not sure if there is any roadmap for that)
  2. The color slider for stock capabilities is also not available for custom capabilities

That leaves only 3rd question unanswered:
How can I make custom capability to be read-only?
The electrical current measurement is received from the device, there is no sense to allow user to modify it.
Thanks

The state display type has no widgets to change the value and it’s used only to show the capability values. Or do you mean at an API level?

Thanks @nayelyz,
I mean in the APP. If I double click on slider, the popup appears and I can change the current value.

Is it possible to make slider read only?
The device has amperage rating, so I think it is good to show visually how far from the max rating the electrical current measurement is.

Would be absolutely awesome if the slider would be with colors, then readings something above 80% the max ratings could be red, 50-80 yellow and others green

You can use the VisibleCondition property of the device-configuration. This “disables” the capability and you cannot longer click on it to open the widget. You could set a condition that would always be evaluated to FALSE so the capability stays greyed out. For example:

"visibleCondition": {
    "capability": "namespacep.vacation",/*compared capability*/
    "version": 1,
    "component": "main", /*device's component where the capability is located*/
    "value": "vacationMode.value", /*reference to which attribute will be compared*/
    "operator": "DOES_NOT_EQUAL",
    "operand": "enabled" /*value assigned to the attribute compared in this condition*/
}

This means that whenever the attribute “Vacation Mode” value is NOT EQUAL to “enabled”, the capability (where this condition was set) will be enabled, otherwise, it will be greyed and unusable in the device UI.

visibleCondition_20210329 (1)

1 Like

Perfect, thank you very much for your help

1 Like