Custom capability with list presentation is not shown

Hi,

I’m trying to create a custom capability with list displayType, however my capability is not shown in the App.
What am I missing? Any ideas would be greatly appreciated.

Thanks

Capability:

name: TestCap
attributes:
  type:
    schema:
      type: object
      properties:
        value:
          type: string
          enum:
            - t1
            - t2
            - t3
      additionalProperties: false
      required:
        - value
    enumCommands: []
commands: []

Capability Presentation:

dashboard:
  states:
    - label: '{{type.value}}'
      alternatives: null
  actions: []
detailView:
  - label: 'Test label'
    displayType: list
    list:
      state:
        value: type.value
        alternatives:
          - key: t1
            value: 'Type 1'
          - key: t2
            value: 'This is type 2'
          - key: t3
            value: 'Type 3'
automation:
  conditions: []
  actions: []

could you please share a link to your code, I think it would be beneficial to see what you already done

There is nothing to share unfortunately. This is just a test without any handlers to learn how to define custom capabilities

Hey, @ygerlovin

You’re missing the detailView.list.command attribute at the presentaiton. I recommend you to check the Presentations API the check the structure of the list display type.

1 Like

Thanks, @erickv .

Now I have another issue that once I change the list value I get the following error in the app:
“A network or server error occurred. Try again later”
and the value is not set.

What am I missing?

Based on the capability schema you shared above, the capability command (sorry if I didn’t notice it before).

You’ll need to define a setter command to your custom capability, for example:

name: TestCap
attributes:
  type:
    schema:
      type: object
      properties:
        value:
          type: string
          enum:
            - t1
            - t2
            - t3
      additionalProperties: false
      required:
        - value

    # setter association
    setter: setType
    enumCommands: []
commands:

# setter command
setType:
    name: setType
    arguments:
      - name: value
        optional: false
        schema:
          type: string

@erickv
I have a set function, I just didn’t know it is mandatory. I tried to keep the example as small as possible, but obviously, I’m doing something wrong, so I will post a complete example. I’m sorry, it is pretty long.

Any hints will be highly appreciated.

virtual-thing-type.yml

id: amberpiano10217.virtualThingType
name: Virtual Thing Type
attributes:
  type:
    schema:
      type: object
      properties:
        value:
          type: string
          enum:
            - switch
            - curtain_switch
            - momentary
            - dimmer
            - sensor_presence
            - sensor_contact
            - sensor_motion
      additionalProperties: false
      required:
        - value
    enumCommands: []
commands:
  setThingType:
    name: setThingType
    arguments:
      - name: value
        optional: false
        schema:
          type: string
          enum:
            - switch
            - curtain_switch            
ocfResourceType: x.com.st.d.remotecontroller
version: 1

virtual-thing-type-presentation.yml

dashboard:
  states:
    - label: '{{type.value}}'
      alternatives: null
  actions: []
  basicPlus: []
detailView:
  - label: 'Virtual Thing To Create'
    displayType: list
    list:
      command:
        name: setThingType
        alternatives:
          - key: switch
            value: 'Switch'
          - key: curtain_switch
            value: "Curtain Switch"
#          - key: momentary
#            value: 'Momentary Button'
#          - key: dimmer
#            value: 'Dimmer'
#          - key: sensor_presence
#            value: 'Presence Sensor'
#          - key: sensor_contact
#            value: 'Contact Sensor'
#          - key: sensor_motion
#            value: 'Motion Sensor'
      state:
        value: type.value
        alternatives:
          - key: switch
            value: 'Virtual Switch'
            type: active
          - key: curtain_switch
            value: "Curtain Switch"
          - key: momentary
            value: 'Virtual Momentary Button'
            type: inactive
          - key: dimmer
            value: 'Virtual Dimmer'
            type: inactive
          - key: sensor_presence
            value: 'Virtual Presence Sensor'
            type: inactive
          - key: sensor_contact
            value: 'Virtual Contact Sensor'
            type: inactive
          - key: sensor_motion
            value: 'Virtual Motion Sensor'
automation:
  conditions: []
  actions: []
id: amberpiano10217.virtualThingType
version: 1

The idea is to use this capability for virtual devices creator.
I plan to have a list of things to be created and a momentary button.
The user would first select a virtual device to create, then press momentary to actually create it.

It is not mandatory, as it is not required according to the documentation and it could be used as an informative drop-down. But, as its principal use-case depends on the ability to select available states/actions (and I think it is the case of your implementation), a capability schema command is necessary if you want to spread the event across the platform consistently.


In addition, you may need to add the setter attribute at your capability schema, to actually generate the attribute ↔ setter command association, i.e.:

    ...

additionalProperties: false
      required:
        - value
    enumCommands: []
    setter: setThingType
commands:
  setThingType:
    name: setThingType
    arguments:
      - name: value
    ...
1 Like

Great, thank you @erickv .

1 Like