Custom Capabilities do not display units correctly in detail view

Hi @nayelyz Don’t answer me today, enjoy the holiday!!

For quite some time some custom capabilities with displayType: “State” in the details view, stopped correctly displaying the units defined in the capability.

I have finally been able to see how to solve it and I want to share it and if it is an error it is corrected or if not it is documented correctly.

This is a capability with units = “%”

{
    "id": "legendabsolute60149.levelSteps",
    "version": 1,
    "status": "proposed",
    "name": "Level Steps",
    "ephemeral": false,
    "attributes": {
        "levelSteps": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "number",
                        "minimum": -30,
                        "maximum": 30
                    },
                    "unit": {
                        "type": "string",
                        "enum": [
                            "%"            #### Unit definition
                        ],
                        "default": "%"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setLevelSteps",
            "enumCommands": []
        }
    },
    "commands": {
        "setLevelSteps": {
            "name": "setLevelSteps",
            "arguments": [
                {
                    "name": "value",
                    "optional": false,
                    "schema": {
                        "type": "number",
                        "minimum": -30,
                        "maximum": 30
                    }
                }
            ]
        }
    }
}

The Capability presentation that always worked and stopped working a long time ago is this:

{
    "dashboard": {
        "states": [
            {
                "label": "{{levelSteps.value}}"
            }
        ],
        "actions": [],
        "basicPlus": []
    },
    "detailView": [
        {
            "label": "Last Step for Level Increment:",
            "displayType": "state",
             "state": {
                "label": "{{levelSteps.value}}",
                "unit": "levelSteps.unit"
            }
          }
    ],
    "automation": {
        "conditions": [
            {
                "label": "Level By External Steps",
                "displayType": "numberField",
                "numberField": {
                    "value": "levelSteps.value",
                    "unit": "levelSteps.unit",
                    "range": [-30, 30]
                }
             }
        ],
        "actions": [
            {
                "label": "Level By External Steps",
                "displayType": "numberField",
                "numberField": {
                    "command": "setLevelSteps",
                    "value": "levelSteps.value",
                    "unit": "levelSteps.unit",
                    "range": [-30, 30]
                }
             }
        ]
    },
    "id": "legendabsolute60149.levelSteps",
    "version": 1
}

The solution is to add the units field of the capability to the state.label

{
    "dashboard": {
        "states": [
            {
                "label": "{{levelSteps.value}} {levelSteps.unit}}" 
            }
        ],
        "actions": [],
        "basicPlus": []
    },
    "detailView": [
        {
            "label": "Last Step for Level Increment:",
            "displayType": "state",
             "state": {
                "label": "{{levelSteps.value}} {{levelSteps.unit}}", #### ### Added levelSteps.unit
                "unit": "levelSteps.unit"
            }
          }
    ],
    "automation": {
        "conditions": [
            {
                "label": "Level By External Steps",
                "displayType": "numberField",
                "numberField": {
                    "value": "levelSteps.value",
                    "unit": "levelSteps.unit",
                    "range": [-30, 30]
                }
             }
        ],
        "actions": [
            {
                "label": "Level By External Steps",
                "displayType": "numberField",
                "numberField": {
                    "command": "setLevelSteps",
                    "value": "levelSteps.value",
                    "unit": "levelSteps.unit",
                    "range": [-30, 30]
                }
             }
        ]
    },
    "id": "legendabsolute60149.levelSteps",
    "version": 1
}
2 Likes

Hi, @Mariano_Colmenarejo

Thank you for your report.
I’ll ask the team about it, I think it could be a bug, your solution is how it used to work when custom capabilities were released, then, it changed to add the unit field.

1 Like

Thanks @nayelyz

For the dashboard, this method is documented that it can be done like this.

Capability Presentations | Developer Documentation | SmartThings.

for detail view, some time ago it was supported to write units and it worked

"label": "{{levelSteps.value}} {%}}"

Now it is mandatory to write atributte.unit to show units

"label": "{{levelSteps.value}} {levelSteps.unit}}"