Capabilities - is there a way to display custom status of a sensor?

Hi @ all!

Now I’m writing on the next driver stumbling over the same issue. That’s why I want to start continuing the discussion from Help needed: st.zigbee.cluster_base understanding here.

I want to create a custom capability like the ActivitySensor. It has only one defined attribute that can have a list of enumerated states. These states are changed only by the driver script and not by the app tiles.

In my last issue I tried to solve this by adding a “setter” to the attribute and a command to set the states, but then the app tile was adjustable, which indeed makes no sense here.

cap.json:

{
    "name": "Valve Operation State",
    "attributes": {
        "valveOperationState": {
            "schema": {
                "type": "object",
                "additionalProperties": false,
                "properties": {
                    "value": {
                        "type": "string",
                        "enum": ["flow", "stopped"]
                    }
                },
                "required": ["value"]
            },
            "type": "ENUM",
            "values": ["flow", "stopped"]
        }
    },
    "commands": {}
}

cap_pres.json:

{
  "dashboard": {
      "states": [],
      "actions": []
  },
  "detailView": [
    {
        "label": "{{i18n.label}}",
        "displayType":"state",
        "state": {
            "value": "valveOperationState.value",
            "valueType": "string",
            "alternatives": [
                {
                    "key": "flow",
                    "value": "{{i18n.attributes.valveOperationState.i18n.value.flow.label}}"
                },
                {
                    "key": "stopped",
                    "value": "{{i18n.attributes.valveOperationState.i18n.value.stopped.label}}"
                }
            ]
        }
    }
  ],
  "automation": {
      "conditions": [],
      "actions": []
  },
  "id": "preparestream40760.valveOperationState",
  "version": 1
}

log:

2022-05-17T12:55:31.773099765+00:00 INFO Valve  <ZwaveDevice: d036d2bd-b1d8-4333-8984-3be33ef5ab0d 
[12] (Valve)> emitting event: {"attribute_id":"valveOperationState","capability_id":"preparestream40760.valveOperationState","component_id":"main","state":{"value":"flow"}}

in the app tile “Water flow” the status is empty:

under my.smartthings.com it’s shown:

Btw. the same problem is with the default refresh capability.

Thank you in advance.

It seems that the capability in the app and my.smarttings.com has different title “water flow” and “Valve Operation State”.
Have you tried to clear the cache of the app if it is android and reboot the hub?

The refresh capability is not shown in the app. It is executed by sliding your finger down in the details view and you see the refresh command sent in the log

1 Like

Yes several times … no change.
“Water Flow” is ok, that’s the en - lable :wink:

cap.json:

{
    "name": "Valve Operation State",
    "attributes": {
        "valveOperationState": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string",
                        "enum": ["flow", "stopped"]
                    }
                },
                "required": ["value"],
                "additionalProperties": false
            },
            "enumCommands": []
        }
    },
    "commands": {}
}

pres.json:

{
  "dashboard": {
      "states": [],
      "actions": []
  },
  "detailView": [
    {
        "label": "{{i18n.label}}",
        "displayType":"state",
        "state": {
            "value": "valveOperationState.value",
            "valueType": "string",
            "alternatives": [
                {
                    "key": "flow",
                    "value": "{{i18n.attributes.valveOperationState.i18n.value.flow.label}}"
                },
                {
                    "key": "stopped",
                    "value": "{{i18n.attributes.valveOperationState.i18n.value.stopped.label}}"
                }
            ]
        }
    }
  ],
  "automation": {
      "conditions": [],
      "actions": []
  },
  "id": "preparestream40760.valveOperationState",
  "version": 1
}

en.json:

{
    "tag": "en",
    "label": "Water Flow",
    "attributes": {
        "valveOperationState": {
            "label": "Water Flow",
            "displayTemplate": "{{attribute}} of {{device.label}} is {{value}}",
            "i18n": {
                "value": {
                    "stopped": {
                        "label": "stopped"
                    },
                    "flow": {
                        "label": "active"
                    }
                }
            }
        }
    },
    "commands": {}
}

de.json:

{
    "tag": "de",
    "label": "Wasserdurchfluss",
    "attributes": {
        "valveOperationState": {
            "label": "Wasserdurchfluss",
            "displayTemplate": "{{attribute}} von {{device.label}} ist {{value}}",
            "i18n": {
                "value": {
                    "stopped": {
                        "label": "gestoppt"
                    },
                    "flow": {
                        "label": "aktiv"
                    }
                }
            }
        }
    },
    "commands": {}
}

Closing the valve - log:

2022-05-23T13:59:26.866914019+00:00 INFO Valve  <ZwaveDevice: e70df73e-0e5b-4c29-9d0c-f947847a0a3e 
[15] (Valve)> received Z-Wave command: {args={alarm_level=0, alarm_type=0, event="VALVE_OPERATION", event_parameter="\x05", notification_status="ON", notification_type="WATER_VALVE", v1_alarm_level=0, v1_alarm_type=0, z_wave_alarm_event=1, 
z_wave_alarm_status="ON", z_wave_alarm_type=15, zensor_net_source_node_id=0}, cmd_class="NOTIFICATION", cmd_id="REPORT", dst_channels={}, encap="S2_AUTH", payload="\x00\x00\x00\xFF\x0F\x01\x01\x05", src_channel=0, version=3}
2022-05-23T13:59:26.894316352+00:00 TRACE Valve  Found ZwaveDispatcher handler in aquascope_bvs
2022-05-23T13:59:26.903828019+00:00 DEBUG Valve  ### cmd.args table={
  _reflect={
    event=function: 0x13af7e0,
    notification_status=function: 0x13af780,
    notification_type=function: 0x13af7c0,
    z_wave_alarm_event=function: 0x1287130,
    z_wave_alarm_status=function: 0x12870a8,
    z_wave_alarm_type=function: 0x1287110,
  },
  alarm_level=0,
  alarm_type=0,
  event=1,
  event_parameter="\x05",
  notification_status=255,
  notification_type=15,
  v1_alarm_level=0,
  v1_alarm_type=0,
  z_wave_alarm_event=1,
  z_wave_alarm_status=255,
  z_wave_alarm_type=15,
  zensor_net_source_node_id=0,
}
2022-05-23T13:59:26.910417352+00:00 INFO Valve  <ZwaveDevice: e70df73e-0e5b-4c29-9d0c-f947847a0a3e 
[15] (Valve)> emitting event: {"attribute_id":"valveOperationState","capability_id":"preparestream40760.valveOperationState","component_id":"main","state":{"value":"stopped"}}

still no change in the app tile…

Aaah indeed! :sweat_smile: :+1:t6:

Maybe my “custom capability work flow” is not correct?

  1. update/create capability (presentation+translation)
  2. update profile
  3. generate presentation from profile
  4. create presentation from this generated file
  5. add new vid to profile
  6. update profile
  7. build new package/push it to the channel/install on hub

Where the status does not appear is in the tile(Dashboard) or in the detail view?

If it is in the tile (Dashboard), the reason could be that the presentation of your capability do not have what it has to show in the Dashboard, states:

{
  "dashboard": {
      "states": [],
      "actions": []
  },

In my custom capability: attribute.value

{
    "dashboard": {
        "states": [
            {
               "label": "{{fanCyclicMode.value}}",
               "unit": null
            }
        ]
    },

My experience with the modifications of the custom capabilities is that they are not displayed correctly and what I do is delete it and create a new one, with some change in the name, -1,-2…

With the translation of capabilities I have no experience

@Mariano_Colmenarejo

It seems I got it to work :smiley:

But yeah, presentation cache in combination with custom capabilities is still annoying …

If I understand correctly, ST assumes that each presentation is “needed” and caches them to avoid duplications? But not on the hub but in the cloud? But firing presentation:device-config:create should overwrite the existing device presentation right?

Does the VID change even if I only change the custom capability presentation but not the device presentation from the profile? I can’t really understand this at the moment …

Anyway, I tinkered a bit with my presentation and now it fits, even with translation.

pres.json:

{
  "dashboard": {
      "states": [],
      "actions": []
  },
  "detailView": [
    {
        "label": "{{i18n.label}}",
        "displayType":"state",
        "state": {
            "label": "{{valveOperationState.value}}",
            "alternatives": [{
                "key": "flow",
                "value": "{{i18n.attributes.valveOperationState.i18n.value.flow.label}}"
            },
            {
                "key": "stopped",
                "value": "{{i18n.attributes.valveOperationState.i18n.value.stopped.label}}"
            }]
        }
    }
  ],
  "automation": {
      "conditions": [],
      "actions": []
  },
  "id": "preparestream40760.waterFlow",
  "version": 1
}
1 Like

In fact, if you look at the API, the presentation is updated, but the modification is not shown in the app, I don’t know how long it takes to update everything, nor does deleting the cache fix it, I have never been able to wait to see if it updates on its own. I don’t have that much patience.

You only need to create new vid if you want to show any modification to the presentation of the already profile existing cabilities, like modifying a range or hiding a capability in any of the views…

The VIDs is updated correctly when you make changes, they generate another new vid normally.
Some time ago, many changes did not generate new VID and if you had made a spelling mistake, for example, it was impossible to fix it without adding or removing cabilities or changing some range. Now it works much better

1 Like

Meanwhile I’ve removed the meta:vid/mnmn from the profile … seems to work better now.
As I understand it is just necessary if I want to adopt the default generated presentation, right?

Btw. is there a documentation what all the keys of each property are for and what can be adjusted?
So far I’ve only found it from time to time in the ST community or in other github repos :sweat_smile:

You do not need to create a vid if you are going to use the default presentations of the profile capabilities

In this, @nayelyz can help you better

These are the points to consider when working with custom capabilities and custom presentations:

Note: I included some things mentioned by @Mariano_Colmenarejo as he’s correct.

  • The VID remains the same if you use the same capabilities (currently, the order is not taken into consideration).
  • The VID’s configuration should update automatically every 12 hrs.
    • If you updated a custom capability presentation, it should update at that point.
    • We force the refresh by executing the smartthings presentation:device-config:create command.
      • However, in the app, mainly in iOS devices, the presentation is cached, that’s why after executing this command and confirming it has the correct configuration, we can clear the cache in Android devices.
  • In Edge and ST Schema devices, we only create manually the device configuration in case we want to add custom functionality (change ranges or enums available, visibleCondition, etc.).
  • We can get more info about the fields in the device-config in the API reference (Presentation > Create a Device Configuration).
    • Note: not all fields can be modified. If you have doubts about any of them, ask away! :smiley:
1 Like

@Mariano_Colmenarejo, @nayelyz thanks for the support!

I didn’t even think about looking there. Maybe a hint on this page would be useful:
https://developer-preview.smartthings.com/docs/devices/device-presentations-and-configurations :wink:

1 Like

Thanks for sharing! I’ll create a ticket for the documentation team.