Custom capability with List presentation got errors after switching screens

Hello, I am encountering an issue with a custom capability I’ve created for controlling sound volume on a device using the SmartThings Edge Driver. The capability is intended to allow users to select between three sound volume levels: Low, Medium, and High. The device takes integers 0, 1, 2, and I map integers to three levels in the list presentation under alternatives.

The weird thing is that the Sound Volume capability always works correctly when first accessed after selecting the Edge Driver for the device. However, when I navigate away from the device screen and then return, the list presentation for Sound Volume no longer functions and results in an error “A network or server error occurred. Try again later”. I did some searching regarding this error and found this post. But since I have configured the “setter” for the attribute and it works fine the first time I use it after installation. The causes for this may be different than those in the post I found.

Furthermore, I replace the list presentation with the slider presentation, and the slider works without any issues, even after switching screens. So I guess the problem is most likely in the List presentation, but I couldn’t figure it out. Below are the JSON files of the capability and the both presentations.

SoundVolume.json

{
    "name": "Sound Volume",
    "attributes": {
        "SoundVolume": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 2
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setSoundVolume",
            "enumCommands": []
        }
    },
    "commands": {
        "setSoundVolume": {
            "name": "setSoundVolume",
            "arguments": [
                {
                    "name": "soundVolume",
                    "optional": false,
                    "schema": {
                        "type": "integer",
                        "minimum": 0,
                        "maximum": 2
                    }
                }
            ]
        }
    }
}

list_presentation.json

{
    "dashboard": {
        "states": [],
        "actions": []
    },
    "detailView": [
        {
            "label": "SoundVolume",
            "displayType": "list",
            "list": {
                "command": {
                    "name": "setSoundVolume",
                    "alternatives": [
                        {
                            "key": 0,
                            "value": "Low"
                        },
                        {
                            "key": 1,
                            "value": "Medium"
                        },
                        {
                            "key": 2,
                            "value": "High"
                        }
                    ],
                    "argumentType": "integer"
                },
                "state": {
                    "value": "SoundVolume.value",
                    "valueType": "integer",
                    "alternatives": [
                        {
                            "key": 0,
                            "value": "Low"
                        },
                        {
                            "key": 1,
                            "value": "Medium"
                        },
                        {
                            "key": 2,
                            "value": "High"
                        }
                    ]
                }
            }
        }
    ],
    "automation": {
        "conditions": [],
        "actions": []
    },
    "id": "cloudchapter42122.soundVolume",
    "version": 1
  }

slider_presentation.json

{
    "dashboard": {
        "states": [],
        "actions": []
    },
    "detailView": [
        {
            "label": "SoundVolume",
            "displayType": "slider",
            "slider": {
                "range": [
                    0,
                    2
                ],
                "command": "setSoundVolume",
                "argumentType": "integer",
                "value": "SoundVolume.value",
                "valueType": "integer"
            }
        }
    ],
    "automation": {
        "conditions": [],
        "actions": []
    },
    "id": "cloudchapter42122.soundVolume",
    "version": 1
}

Has anyone had a similar problem? Any help with this would be greatly appreciated!

Hello @xshawnx, I’m from the developer support team, I was testing the issue and I was able to replicate it. Please let me share this with the team on charge to see what is happening and what is the solution. I will get back to you as soon as they find something.

Hi @Ivan_Luis_Falleau , thank you for the reply. I am looking forward to the update on this issue.

Hi @xshawnx, we noticed that the attribute is typed as an integer. But list capability presentation key values are strings, as they must be according to the API docs. So, by changing the attribute to a string with enum values I was able to use the capability without a problem.
Capability:

{
    "name": "Sound Volume",
    "attributes": {
        "SoundVolume": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string",
                        "enum": [
                            "0",
                            "1",
                            "2"
                        ]
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setSoundVolume",
            "enumCommands": []
        }
    },
    "commands": {
        "setSoundVolume": {
            "name": "setSoundVolume",
            "arguments": [
                {
                    "name": "soundVolume",
                    "optional": false,
                    "schema": {
                        "type": "string",
                        "enum": [
                            "0",
                            "1",
                            "2"
                        ]
                    }
                }
            ]
        }
    }
}

Presentation:

{
    "dashboard": {
        "states": [],
        "actions": []
    },
    "detailView": [
        {
            "label": "SoundVolume",
            "displayType": "list",
            "list": {
                "command": {
                    "name": "setSoundVolume",
                    "alternatives": [
                        {
                            "key": "0",
                            "value": "Low"
                        },
                        {
                            "key": "1",
                            "value": "Medium"
                        },
                        {
                            "key": "2",
                            "value": "High"
                        }
                    ],
                    "argumentType": "integer"
                },
                "state": {
                    "value": "SoundVolume.value",
                    "valueType": "integer",
                    "alternatives": [
                        {
                            "key": "0",
                            "value": "Low"
                        },
                        {
                            "key": "1",
                            "value": "Medium"
                        },
                        {
                            "key": "2",
                            "value": "High"
                        }
                    ]
                }
            }
        }
    ],
    "automation": {
        "conditions": [],
        "actions": []
    },
    "id": "yourCapabilityId",
    "version": 1
  }

Hope this may help you.

Hi @Ivan_Luis_Falleau, thanks a lot! Changing “integer” to “string” did solve the problem.

Since I only found some code examples in the API documentation, it was of limited help during the development. Just my two cents, it would be nice if the API documentation could be fleshed out a bit more, with more detailed explanations or requirements/constraints on how to create valid presentations for various use cases. Also, it would be helpful for debugging if Presentation errors could be displayed somewhere (e.g., via smartthings edge:drivers:logcat).

1 Like

Hi @xshawnx, I’m glad to be helpful. And thank you for your comments I will let the on-charge team know to improve that part.

1 Like