Flow, Finite State Machine and conditional execution

In this example, we use the rules engine both as the flow engine as well as the finite state machine

Let’s see how this works in practise: dice_2 always runs after dice has finished (which acts as the flow engine using function chaining), while the execution of the sensor dice_4 and dice_5 depends on the outcome of the dice sensor exection (either on the particular state or transition), in which case we are working as if that was the finite state engine.


We start a task using this template (e.g. saved as “flow”) in the periodic mode like this:

 curl --user apiKey:apiSecret -H "Content-Type:application/json" -X POST -d '{
    "name": "test ",
    "template": "flow",
    "type": "periodic",
    "frequence": 2000,
    "start": true
  }' https://sandbox.waylay.io/api/tasks

In this case, we are running this task every 2 seconds.

Condition node

Waylay library has a condition sensor that allows you in a simple way to describe condition which is required before next plug gets executed. Here condition is simply described as

"${nodes.dice.state}" == "ONE" || "${nodes.dice.state}" == "THREE" || "${nodes.dice.state}" == "FIVE"  


Note that we could have achieved the same just by using simple node condition, but if you need any general condition, by checking some particular values from previous nodes or write some formulas, you can always use the previous example.


Sequence feature

In case we only care that sensors are executed in a given order, you can just use the sequence feature (setting on the node level). Please be aware that the next sequence group (all sensors within the group n) are executed regardless of the outcome of any sensor of the previous group n-1.