Is there any capability that can display a single choice from the list (dropdown)?
I am looking to create a DHT for a light strip that has animation presets.
So users can choose color and animation on the device page
Is there any capability that can display a single choice from the list (dropdown)?
I am looking to create a DHT for a light strip that has animation presets.
So users can choose color and animation on the device page
A list display type is used to present the user with more than one option to send a new value to the device.
However, you can create a custom capability using this display type with only one option but you need to consider the following:
{
"name": "OneItemInlist",
"attributes": {
"itemValue": {
"schema": {
"type": "object",
"properties": {
"value": {
"type": "string",
"enum": [
"itemOne",
"itemTwo",
"itemThree",
"itemFour"
]
}
},
"additionalProperties": false,
"required": [
"value"
]
},
"setter": "setItemValue",
"enumCommands": []
}
},
"commands": {
"setItemValue": {
"name": "setItemValue",
"arguments": [
{
"name": "value",
"optional": false,
"schema": {
"type": "string"
}
}
]
}
}
}
{
"dashboard": {
"states": [
{
"label": "{{itemValue.value}}",
"alternatives": [
{
"key": "itemOne",
"value": "Item One",
"type": "active"
},
{
"key": "itemTwo",
"value": "Item Two",
"type": "active"
},
...
]
}
],
"actions": [],
"basicPlus": []
},
"detailView": [
{
"label": "Status",
"displayType": "list",
"list": {
"command": {
"name": "setItemValue",
"alternatives": [
{
"key": "itemOne",
"value": "Item One",
"type": "active"
}
],
"argumentType": "string"
},
"state": {
"value": "itemValue.value",
"valueType": "string",
"alternatives": [
{
"key": "itemOne",
"value": "Item One",
"type": "active"
}
]
}
},
"state": null
}
],
"automation": {
"conditions": [
{
"label": "Status",
"displayType": "list",
"list": {
"alternatives": [
{
"key": "itemOne",
"value": "Item One",
"type": "active"
},
{
"key": "itemTwo",
"value": "Item Two",
"type": "active"
}
],
"value": "itemValue.value",
"valueType": "string"
}
}
],
"actions": [
{
"label": "Arm Alarm",
"displayType": "list",
"list": {
"alternatives": [
{
"key": "itemOne",
"value": "Item One",
"type": "active"
}
],
"command": "setItemValue",
"argumentType": "string"
}
}
]
}
}
so profiles/lamp.yaml
name: lamp
components:
- id: main
capabilities:
- id: switch
version: 1
- id: list??
version: 1
- id: refresh
version: 1
- id: battery
version: 1
categories:
- name: RemoteController
You need to create the custom capability with the corresponding commands (see below).
When you create it, an ID is generated automatically, which you need to include in your device profile.
//to create capability
smartthings capabilities:create //-i capability.yaml
//Note: if we don't use a file as input, the assistant to create the capability is executed
//to create its presentation
smartthings capabilities:presentation:create [ID] [VERSION]
I suggest you take a look at this sample using custom capabilities:
Also, here’s an interesting discussion about it:
too much code for a simple drop-down list =(
Do you mean in the capability presentation?
The sample I shared includes the configuration for all the views (Dashboard, Detail and Automation).
If you don’t need to have the capability in the Automations tool for example, you can skip that section.
Perhaps, you can take a look at the device preferences which are also used to get input from the user and are simpler.
The legacy platform (Groovy) had the same options but the syntax was different. Take a look at the published DTHs as a reference:
Also, several light strips are generally divided into components, please, check the specifications of the device and consider them while creating your handler.
it’s just too many lines of code just to show a simple list of max 10 presets.
also you might not notice but presentation docs does not contain any image.
That’s why preferences are a good alternative, you don’t have to interact with the API to create them, you only add them to the device metadata. Eg. These are the preferences included in the handler of the SmartThings multipurpose sensor:
Do you mean samples of each display type UI?
it would be strange to have color on the main page and preset hidden in the settings. But I understand your point.
Is it possible to populate settings dynamically from the json response?
Up to now, preferences are read-only, so their value cannot be modified from within the driver.