You are currently viewing the Homey Apps SDK v2 documentation. New apps should use Homey Apps SDK v3 ››

Devices

While devices look like seperate Flow-cards in the Editor, they are actually dynamically generated from your app's cards.

To make them show up, add at least one "type": "device" argument in a flow trigger, condition or action. Then add filter: "driver_id=my_driver" (replace my_driver with your driver's id) to transform the card to a separate icon in the Flow Editor's sidebar.

/app.json

{
  "id": "com.athom.example",
  ...
  "flow": {
    "triggers": [
      {
        "id": "turned_on",
        "title": {
          "en": "Turned on"
        },
        "args": [
          {
            "name": "my_device",
            "type": "device",
            "filter": "driver_id=my_driver"
          }
        ]
      }
    ]
  }
}

If your driver has a class that Homey already has support for, like light or socket, your custom card will be added to those cards. For example, if your driver supports a Light bulb that has a special disco mode, the user will see 'Turn on', 'Turn off', 'Dim', 'Set color', 'Disco mode'.

There are additional filter flags that can be applied for Z-Wave devices:

  • Target only multi channel node devices:
"filter": {
  "driver_id": "my_driver",
  "flags": "zwaveMultiChannel"
}
  • Target only root node devices:
"filter": {
  "driver_id": "my_driver",
  "flags": "zwaveRoot"
}

Triggering

Instead of creating a regular FlowCardTrigger instance, create a FlowCardTriggerDevice instance.

/drivers/my_driver/driver.js

class MyDriver extends Homey.Driver {

  onInit() {

    this._flowTriggerTurnedOn = new Homey.FlowCardTriggerDevice('turned_on')
      .register()

  }

  triggerMyFlow( device, tokens, state ) {
    this._flowTriggerTurnedOn
      .trigger( device, tokens, state )
        .then( this.log )
        .catch( this.error )
  }

}

/drivers/my_driver/device.js

class MyDevice extends Homey.Device {

  onInit() {

    let device = this; // We're in a Device instance
    let tokens = {};
    let state = {};

    this._driver = this.getDriver();
    this._driver.ready(() => {
      this._driver.triggerMyFlow( device, tokens, state );
    });

  }

}

Conditions and Actions

These are not different from regular Flow cards. The device's instance will be in args.my_device.