Trigger nightlight on motion (Aeotec multisensor 6 specific)

To automate a night light to trigger on a motion sensor should be pretty straight forward right? It is passed bed time, enable the flow, motion detected, turn on light, wait 2 minutes, turn off light, morning is here, disable the flow. Simple…

Well it was not and I needed several tries before I got it to work the way I wanted. Why? Because my motion sensor (Aeotec multisensor 6) has a time threshold (4 minutes by default) from the moment a motion is detected before the sensor can trigger again. Because my motion sensor will trigger a evt.presence.report when a motion is detected, but also when the threshold period has passed. You need to filter the return value (“true” for motion detected, “false” for threshold exeeded) to make sure you are using the intended trigger.

So the end result looks like this:

I post the code here as inspiration for anybody that may be interested. In addition, I also had to set my sensor with the desired time threshold (2 minutes in my case):

{
  "Id": "zUZKUbHM7MuTuRE",
  "ClassId": "zUZKUbHM7MuTuRE",
  "Author": "",
  "Version": 0,
  "CreatedAt": "2020-12-17T21:55:50.7106396+01:00",
  "UpdatedAt": "2021-01-11T22:06:08.226804708+01:00",
  "Name": "Hallway nightlight goes on on motion at 20:00",
  "Group": "hallway",
  "Description": "Turn on hallway nightlight on motion",
  "Nodes": [
    {
      "Id": "1",
      "Type": "trigger",
      "Label": "Hallway motion",
      "SuccessTransition": "11",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "pt:j1/mt:evt/rt:dev/rn:zw/ad:1/sv:sensor_presence/ad:44_0",
      "Service": "sensor_presence",
      "ServiceInterface": "evt.presence.report",
      "Config": {
        "InputVariableType": "",
        "IsValueFilterEnabled": true,
        "LookupServiceNameAndLocation": false,
        "PropFilterName": "",
        "PropFilterValue": "",
        "RegisterAsVirtualService": false,
        "Timeout": 0,
        "ValueFilter": {
          "Value": true,
          "ValueType": "bool"
        },
        "ValueJPath": "",
        "ValueJPathResultType": "",
        "VirtualServiceGroup": "",
        "VirtualServiceProps": null
      },
      "Ui": {
        "nodeType": "",
        "x": 361,
        "y": 183
      },
      "TypeAlias": "Trigger",
      "LastValue": false
    },
    {
      "Id": "6",
      "Type": "action",
      "Label": "Hallway nightlight ON",
      "SuccessTransition": "16",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "pt:j1/mt:cmd/rt:dev/rn:zw/ad:1/sv:out_bin_switch/ad:43_0",
      "Service": "out_bin_switch",
      "ServiceInterface": "cmd.binary.set",
      "Config": {
        "DefaultValue": {
          "Value": true,
          "ValueType": "bool"
        },
        "IsVariableGlobal": false,
        "Props": {},
        "RegisterAsVirtualService": false,
        "ResponseToTopic": "",
        "VariableName": "",
        "VirtualServiceGroup": "ch_0",
        "VirtualServiceProps": {}
      },
      "Ui": {
        "nodeType": "",
        "x": 360,
        "y": 534
      },
      "TypeAlias": "Action",
      "LastValue": false
    },
    {
      "Id": "10",
      "Type": "action",
      "Label": "Hallway nightlight OFF",
      "SuccessTransition": "20",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "pt:j1/mt:cmd/rt:dev/rn:zw/ad:1/sv:out_bin_switch/ad:43_0",
      "Service": "out_bin_switch",
      "ServiceInterface": "cmd.binary.set",
      "Config": {
        "DefaultValue": {
          "Value": false,
          "ValueType": "bool"
        },
        "IsVariableGlobal": false,
        "Props": {},
        "RegisterAsVirtualService": false,
        "ResponseToTopic": "",
        "VariableName": "",
        "VirtualServiceGroup": "ch_0",
        "VirtualServiceProps": {}
      },
      "Ui": {
        "nodeType": "",
        "x": 639,
        "y": 533
      },
      "TypeAlias": "Action",
      "LastValue": false
    },
    {
      "Id": "11",
      "Type": "if",
      "Label": "var_enb == true && var_light == false",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "Expression": [
          {
            "BooleanOperator": "and",
            "LeftVariableIsGlobal": false,
            "LeftVariableName": "var_enb",
            "Operand": "eq",
            "RightVariable": {
              "Value": true,
              "ValueType": "bool"
            }
          },
          {
            "BooleanOperator": "",
            "LeftVariableIsGlobal": false,
            "LeftVariableName": "var_light",
            "Operand": "eq",
            "RightVariable": {
              "Value": false,
              "ValueType": "bool"
            }
          }
        ],
        "FalseTransition": "",
        "TrueTransition": "6"
      },
      "Ui": {
        "nodeType": "",
        "x": 358,
        "y": 350
      },
      "TypeAlias": "If condition"
    },
    {
      "Id": "12",
      "Type": "time_trigger",
      "Label": "Everyday at 20:00",
      "SuccessTransition": "13",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultMsg": {
          "Value": "",
          "ValueType": ""
        },
        "Expressions": [
          {
            "Comments": "",
            "Expression": "0 20 * * 0,1,2,3,4,5,6",
            "Name": "Everyday at 20:00"
          }
        ],
        "GenerateAstroTimeEvents": false,
        "Latitude": 0,
        "Longitude": 0,
        "SunriseTimeOffset": 0,
        "SunsetTimeOffset": 0
      },
      "Ui": {
        "nodeType": "",
        "x": 31,
        "y": 198
      },
      "TypeAlias": "Time trigger"
    },
    {
      "Id": "13",
      "Type": "set_variable",
      "Label": "var_enb = true",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultValue": {
          "Value": true,
          "ValueType": "bool"
        },
        "Name": "var_enb",
        "UpdateGlobal": false,
        "UpdateInputMsg": false
      },
      "Ui": {
        "nodeType": "",
        "x": 25,
        "y": 417
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "14",
      "Type": "time_trigger",
      "Label": "Everyday at 06:30",
      "SuccessTransition": "15",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultMsg": {
          "Value": "",
          "ValueType": ""
        },
        "Expressions": [
          {
            "Comments": "",
            "Expression": "30 06 * * 0,1,2,3,4,5,6",
            "Name": "Everyday at 06:30"
          }
        ],
        "GenerateAstroTimeEvents": false,
        "Latitude": 0,
        "Longitude": 0,
        "SunriseTimeOffset": 0,
        "SunsetTimeOffset": 0
      },
      "Ui": {
        "nodeType": "",
        "x": 911,
        "y": 198
      },
      "TypeAlias": "Time trigger"
    },
    {
      "Id": "15",
      "Type": "set_variable",
      "Label": "var_enb = false",
      "SuccessTransition": "19",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultValue": {
          "Value": false,
          "ValueType": "bool"
        },
        "Name": "var_enb",
        "UpdateGlobal": false,
        "UpdateInputMsg": false
      },
      "Ui": {
        "nodeType": "",
        "x": 913,
        "y": 420
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "16",
      "Type": "set_variable",
      "Label": "var_light = true",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultValue": {
          "Value": true,
          "ValueType": "bool"
        },
        "Name": "var_light",
        "UpdateGlobal": false,
        "UpdateInputMsg": false
      },
      "Ui": {
        "nodeType": "",
        "x": 357,
        "y": 696
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "17",
      "Type": "trigger",
      "Label": "Hallway no motion",
      "SuccessTransition": "18",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "pt:j1/mt:evt/rt:dev/rn:zw/ad:1/sv:sensor_presence/ad:44_0",
      "Service": "sensor_presence",
      "ServiceInterface": "evt.presence.report",
      "Config": {
        "InputVariableType": "",
        "IsValueFilterEnabled": true,
        "LookupServiceNameAndLocation": false,
        "PropFilterName": "",
        "PropFilterValue": "",
        "RegisterAsVirtualService": false,
        "Timeout": 0,
        "ValueFilter": {
          "Value": false,
          "ValueType": "bool"
        },
        "ValueJPath": "",
        "ValueJPathResultType": "",
        "VirtualServiceGroup": "",
        "VirtualServiceProps": null
      },
      "Ui": {
        "nodeType": "",
        "x": 622,
        "y": 186
      },
      "TypeAlias": "Trigger",
      "LastValue": false
    },
    {
      "Id": "18",
      "Type": "if",
      "Label": "var_enb == true && var_light == true",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "Expression": [
          {
            "BooleanOperator": "and",
            "LeftVariableIsGlobal": false,
            "LeftVariableName": "var_enb",
            "Operand": "eq",
            "RightVariable": {
              "Value": true,
              "ValueType": "bool"
            }
          },
          {
            "BooleanOperator": "",
            "LeftVariableIsGlobal": false,
            "LeftVariableName": "var_light",
            "Operand": "eq",
            "RightVariable": {
              "Value": true,
              "ValueType": "bool"
            }
          }
        ],
        "FalseTransition": "",
        "TrueTransition": "10"
      },
      "Ui": {
        "nodeType": "",
        "x": 640,
        "y": 347
      },
      "TypeAlias": "If condition"
    },
    {
      "Id": "19",
      "Type": "set_variable",
      "Label": "var_light = false",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultValue": {
          "Value": false,
          "ValueType": "bool"
        },
        "Name": "var_light",
        "UpdateGlobal": false,
        "UpdateInputMsg": false
      },
      "Ui": {
        "nodeType": "",
        "x": 920,
        "y": 642
      },
      "TypeAlias": "Set variable"
    },
    {
      "Id": "20",
      "Type": "set_variable",
      "Label": "var_light = false",
      "SuccessTransition": "",
      "TimeoutTransition": "",
      "ErrorTransition": "",
      "Address": "",
      "Service": "",
      "ServiceInterface": "",
      "Config": {
        "DefaultValue": {
          "Value": false,
          "ValueType": "bool"
        },
        "Name": "var_light",
        "UpdateGlobal": false,
        "UpdateInputMsg": false
      },
      "Ui": {
        "nodeType": "",
        "x": 648,
        "y": 700
      },
      "TypeAlias": "Set variable"
    }
  ],
  "Settings": null,
  "IsDisabled": false,
  "IsDefault": false,
  "ParallelExecution": "keep_last"
}

This is similar on how i solved it;