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

Tokens

Tokens (Tags for the user) are variables available in the Flow Editor to pass information between cards.

There are two types of tokens: trigger tokens and global tokens.

Trigger Tokens

When triggering a Flow, some information might be useful to use in that Flow. For example, when it starts raining, the mm/hour could be a token.

Tokens have a pre-defined type, which can be either string, number, boolean or image. If the type is not defined, the token is assumed to be of type string.

Tokens are drag-and-dropable by the user. They can be dropped in compatible fields, such as a text field for String tokens, or in a special droptoken field (read below in the section about Arguments). This way, the user can make advanced flows with variables.

Example

To add tokens to a trigger, just add a property tokens to your /app.json.

/app.json

{
  "id": "com.athom.example",
  ...
  "flow": {
    "triggers": [
    {
      "id": "rain_start",
      "title": {
        "en": "It starts raining"
      },
      "tokens": [
        {
          "name": "mm_per_hour",
          "type": "number",
          "title": {
            "en": "mm/h"
          },
          "example": 5
        },
        {
          "name": "city",
          "type": "string",
          "title": {
            "en": "City"
          },
          "example": {
            "en": "Amsterdam"
          }
        }
      ]
    }
  }
]

And when firing your trigger, add them as second argument:

/app.js

let rainStartTrigger = new Homey.FlowCardTrigger('rain_start');

let tokens = {
  'mm_per_hour': 3,
  'city': 'New York'
}

rainStartTrigger
  .register()
  .trigger( tokens )
    .catch( this.error )
    .then( this.log )

Global Tokens

A token can also be registered globally, which makes it accessible in any Flow and does not require the app to trigger the Flow. For example a weather app could expose the current temperature as a global token.

By default a device's capability are registered as global tokens.

Example

/app.js

let myToken = new Homey.FlowToken( 'my_token', {
  type: 'number',
  title: 'My Token'
});
myToken.register()
  .then(() => {
    return myToken.setValue( 23.5 );
  })
  .catch( err => {
    this.error( err );
  });

Child Topics