State

When a Flow is triggered and the trigger has Arguments, an event is fired for you to validate the arguments, for each Flow that has this trigger. This is a chance to validate the user's value for the trigger's arguments.

For example, we expand on the rain example with a 'Location' field for the user to choose.

/app.json

{
    "id": "com.athom.hello",
    ...
    "flow": {
        "triggers": [
            {
                "id": "rain_start",
                "title": {
                    "en": "It starts raining"
                },
                "tokens": [
                    {
                        "name": "mm_per_hour",
                        "type": "number",
                        "title": {
                            "en": "mm/h"
                        },
                        "example": 5
                    }
                ],
                "args": [
                    {
                        "name": "location",
                        "type": "text"
                    }
                ]
            }
        ]
    }
}

/app.js

// register the card
let rainStartTrigger = new Homey.FlowCardTrigger('rain_start');
rainStartTrigger
    .registerRunListener(( args, state ) => {

        console.log(args); // { 'location': 'New York' }, this is the user input
        console.log(state); // { 'location': 'Amsterdam' }, this is the state parameter, as passed in trigger()

        // If true, this flow should run
        return Promise.resolve( args.location === state.location );

    })
    .register()


// trigger the card
let tokens = { 'mm_per_hour': 3 }
let state = { 'location': 'Amsterdam' }

rainStartTrigger.trigger( tokens, state )
    .then( this.log )
    .catch( this.error )