Custom Capability and CLI Developer Preview

@jody.albritton Is it possible to show 2 elements with same displayType in detailView ? I cannot make it work.

I created custom capability MY-NMS.myDoubleMomentaryButton:

{
    "id": "<MY NMS>.myDoubleMomentaryButton",
    "version": 1,
    "status": "proposed",
    "name": "My Double Momentary Button",
    "attributes": {
        "lastRunningDate": {
            "schema": {
                "type": "object",
                "properties": {
                    "value": {
                        "type": "string"
                    }
                },
                "additionalProperties": false,
                "required": [
                    "value"
                ]
            },
            "setter": "setLastRunningDate",
            "enumCommands": []
        }
    },
    "commands": {
        "setLastRunningDate": {
            "name": "setLastRunningDate",
            "arguments": [
                {
                    "name": "value",
                    "optional": false,
                    "schema": {
                        "type": "string"
                    }
                }
            ]
        },
        "enable": {
            "name": "enable",
            "arguments": []
        },
        "disable": {
            "name": "disable",
            "arguments": []
        }
    }
}

along with capability presentation:

{
    "dashboard": {
        "states": [
            {
                "label": "{{lastRunningDate.value}}"
            }
        ],
        "actions": [
			{
				"displayType": "pushButton",
				"pushButton": {
					"command": "enable"
				}
			}
		],
        "basicPlus": []
    },
    "detailView": [
		{
            "label": "Turn ON",
            "displayType": "pushButton",
            "pushButton": {
				"command": "enable",
				"argument": "push"
			}
        },
		{
            "label": "Turn OFF",
            "displayType": "pushButton",
            "pushButton": {
				"command": "disable",
				"argument": "push"
			}
        },
		{
            "label": "Last run:",
            "displayType": "state",
            "state": {
				"label": "{{lastRunningDate.value}}",
			}
        }
    ],
    "automation": {},
    "id": "<MY NMS>.myDoubleMomentaryButton",
    "version": 1
}

Data Handler code:

metadata
{
     definition( name: 'My Double Momentary Button', namespace: '<MY NMS>', author: 'btrial', "mnmn": "SmartThingsCommunity", "vid": "............") {
        capability '<MY NMS>.myDoubleMomentaryButton'
        capability 'switch'
     }
}

def installed()
{	
	log.debug( 'installed')
    sendEvent( name: 'switch', value: 'off')
}

def updated()
{
	log.debug( 'updated')
}

def enable()
{
	log.debug( 'enabled' )
	sendEvent( name: 'switch',  value: 'on' )
	sendEvent( name: 'switch',  value: 'undefined' )
    setLastRunningDate(new Date().toString())
}

def disable()
{
	log.debug( 'disabled' )
	sendEvent( name: 'switch',  value: 'off' )
	sendEvent( name: 'switch',  value: 'undefined' )
    setLastRunningDate(new Date().toString())
}

def setLastRunningDate(String value) 
{
	sendEvent( name: 'lastRunningDate',  value: value )
}

def parse( String description )
{
    log.debug( 'parse', 'debug', description )
}

and device configuration:

{
    "type": "dth",
    "dashboard": {
        "states": [
            {
                "component": "main",
                "capability": "<MY NMS>.myDoubleMomentaryButton",
                "version": 1,
                "values": [],
                "patch": []
            }
        ],
        "actions": [
            {
                "component": "main",
                "capability": "<MY NMS>.myDoubleMomentaryButton",
                "version": 1,
                "values": [],
                "patch": []
            }
        ]
    },
    "detailView": [
        {
            "component": "main",
            "capability": "<MY NMS>.myDoubleMomentaryButton",
            "version": 1,
            "values": [],
            "patch": []
        }
    ],
    "automation": {
        "conditions": [],
        "actions": []
    }
}

and I can only see one push displayType element in smartthing New UI.
The state is also not being shown.

Is there any reason why my second push displayType and state label is not being shown ?

Hi, there! As I understand, your scenario is:

  • One button is to enable and the other to disable.
  • You set the value of the lastRunningDate based on those buttons

If this is correct, I suggest you separate these into two capabilities:

  1. A ToggleSwitch Capability (enable/disable)
  2. Another capability to save/display the lastRunningDate using the State display type.

This way, you can continue using the enable()/disable() commands to update the lastRunningDate. You’ll also have to update the toggle state, otherwise, you’ll receive a network error.

Note: Up to now, each capability can display one element, that’s why it is recommended they be single-attribute. If you want to display buttons with different functions, you’ll need to separate them as well.

@nayelyz

But I don’t want it to have as a toogle switch, but momentary buttons. That is the whole idea of it.

I saw @philh30 tried doing the same, but he ended up, splitting pushButtons to seperate capabilities. That is insine !

What do you mean by Up to now, each capability can display one element ? Do you mean of same type, or in general (capability can have only one element in totall and that is all) ?

I meant one device card/tile in general, it cannot show more even if they are of the same display type. As your buttons are used to trigger different commands, that’s why they should go separated, also from the lastRunningDate. I suggested the Toggle Switch because you’d only need one capability to change between the enabled/disabled states instead of two.

@nayelyz Thank You for explanation.
I need to stick to push buttons, instead of toggle switch as I don’t want to hold the switch state pernamently, as I want to use it like an IR remote control for AVR or TV, where you don’t know if someone have turned it off or on physically.

One more question, what is going to be shown in “dashboard” if I create couple of different capability presentations (for different capabilies), where each specifies what should be shown at “dashboard”, and I use more than one such different capabilities in one DTH ?

This is defined with the device presentation, you set the capability that will be shown in the Dashboard View. Even if all your capabilities have this view configured at their presentation, the device will only show the one specified at the VID.
For example, both switch and temperatureMeasurement have configured the Dashboard View but this device will only show switch.

{
    "type": "dth",
    "dashboard": {
        "states": [
            {
                "component": "main",
                "capability": "switch",
                "version": 1,
                "values": [],
                "patch": []
            }
        ],
        "actions": []
    },
    "detailView": [
        {
            "component": "main",
            "capability": "switch",
            "version": 1,
            "values": [],
            "patch": []
        },
        {
            "component": "main",
            "capability": "temperatureMeasurement",
            "version": 1,
            "values": [],
            "patch": []
        }
    ]
}

Thanks to @nayelyz tips (Thank You very much :slight_smile: ) , I was at last able to create couple of Momentary Button(s) device handlers using new smarthing capabilities which renders fine in New Smartthings app.

The purpose of those data handlers, was to create ON/OFF functionality without preserving ON/OFF state to be able to control devices witch do not hold such state, like remote controls, broadlink device etc…

All DTH expose ON/OFF functionality to webcore. Whenever enable/disable is pushed from app, there will be ON/OFF switch event send first, and then it goes back to “Undefined” state.

A list of momentary capabilities, presentations and DataHandlers for New Smartthings APP.

DataHandlers expose ON/OFF switch events (to webcore too), but they do not keep ON/OFF state, but get back to "undefined" switch state imediatelly in order to be able to push momentary press again.

1. momentaryButtonEnable - momentary capability and presentation for enable tile
2. momentaryButtonDisable - momentary capability and presentation for disable tile
3. lastRunningDateTime - capability and presentation for last running dateTime tile
4. singleMomentaryButton - single momentary button DTH using 1) 3) for on/lastRun tiles
5. doubleMomentaryButton - double momentary button DTH using 1) 2) 3) for on/off/lastRun tiles
6. doubleBroadlinkMomentaryButton - double momentary button DTH using 1) 2) 3) for on/off/lastRun tiles, to control Broadlink devices
7. doubleHTTPMomentaryButton - double momentary button DTH using 1) 2) 3) for on/off/lastRun tiles, to send HTTP requests

Installation:
* create new DataHandler in Smartthings IDE using one code from one of dataHandler.txt files from 4) 5) 6) 7)
OR
* create your new DataHandler using capabilitie and presentation from 1) 2) 3)

If anyone is interested fill free to use it and let me know if it works for you:

Just keep in mind, those are my first new smartthings datahandlers/capabilities/presentations so be forgiving if something doesn’t work :slight_smile:

Any upgrades, as merge requests higly appreciated.

@nayelyz is it somehow possible to add push icon animation in dashboard and detailView, when clicking on it ? In dashboardView the icon highlights when pushed, but in detailView it is totally static.

4 Likes

The option to customize the device UI (custom icon, images, etc.) is not available yet. I installed one of your devices and I can see a loading icon when I press the button in Detail View before the last run value is updated.

1 Like

Thank you for info and trying it out. I cannot see any animation on my mobile phone (xperia xz2) when I press enable or disable, so I guess it is a matter of phone or android version or something. It is not a big problem anyway.

Are the Momentary Buttons working because that bug was finally fixed or is it because that’s not a hub connected device?

Are the momentary buttons working on both the dashboard and detailView?

1 Like

Hi, there! In this case, he added another command aside the setter, for example momentaryButtonDisable here.
This command is triggered correctly from the device in the mobile app, so you can use this method as a workaround for the pushButton display type.
Nice going, @btrial! Thank you. :ok_hand:

Yes, but on dashboard you can have only one visible. So in case of double push button on dashboard i have enable one, and in detail i have both.

1 Like