Custom Capability and CLI Developer Preview

Hi @mrmrmrmr,

Our engineering department is working to have the pushButton element fixed ASAP. As an alternative, you could use other capabilities.


The picture shows a device I created using the SmartThings Schema connector where:

  • I used the capability “Momentary” to display buttons in different components and receive the “push” event.
  • I added a custom capability to show the last status
  • I included the display type TextField to receive an IP value as part of the device settings (this component’s command is not being triggered correctly, but if you send the commands through the API it shows the corresponding value. This could be an enhancement once the fix is released).

Below is the code snippet to get a similar result.

const connector = new SchemaConnector()
    .enableEventLogging(2)
    .discoveryHandler((accessToken, response) => {
      const d1 = response.addDevice('st-schema-buttons', 'ST schema Buttons', 'deviceProfileID')
      d1.manufacturerName('manufName');
      d1.modelName('modelName');
    })
    .stateRefreshHandler((accessToken, response) => {
      response.addDevice('st-schema-buttons', [
        {
          component: 'main',
          capability: 'capabilityID1',
          attribute: 'attrName',
          value: 'Current Status'
        },
        {
            component: 'main',
            capability: 'capabilityID2',
            attribute: 'attrName',
            value: '192.168.1.1'
        }
      ])
    })
    .commandHandler((accessToken, response, devices) => {
      for (const device of devices) {
        const deviceResponse = response.addDevice(device.externalDeviceId);
        for (const cmd of device.commands) {
          const state = {
            component: cmd.component,
            capability: cmd.capability
          };
          if (cmd.component === 'up' && cmd.command === 'push') {
            //HTTP request
            //...
            //Update current Status Label
            state.component='main'
            state.capability='capabilityID'
            state.attribute = 'attrName';
            state.value = 'Button UP pressed';
            deviceResponse.addState(state);
          } else if (cmd.capability === 'capabilityID2' && cmd.command === 'capabilityCommandName') {
            //receive commands to change the IP address value
            state.attribute = 'attrName';
            state.value = cmd.arguments[0];
            deviceResponse.addState(state);
          }  else {
            deviceResponse.setError(
                `Command '${cmd.command} of capability '${cmd.capability}' not supported`,
                DeviceErrorTypes.CAPABILITY_NOT_SUPPORTED)
          }
        }
      }
    });

And, this is the device profile configuration I used: