Motion sensor with countdown (Custom widget)

How to configure, using the Custom widget component, a logic that turns on a light on motion and switches it off after a user-adjustable time.

Introduction

This guide explains how to configure a motion sensor logic that, once executed, turns on a light and, after a specific period of time, switches it off automatically. This logic is configured with the Custom widget component. In the KNX world this logic is already present in most motion sensors, among their configuration parameters; it can therefore be useful when the motion sensor is not KNX.

Component configuration

Step 1:

Add the following components to the project:

  • 2 Switch components. You can find this component in the section called Base within the Component library tab;

  • 1 Info component. You can find this component in the section called Base within the Component library tab;

  • 1 Custom widget component. You can find this component in the section called Base within the Component library tab;

  • 1 Adjustable value component. You can find this component in the section called Base within the Component library tab.

Adding the required components for configuring the JavaScript logic within the Ilevia Manager configuration software.

Step 2:

Add the variables in the JSON text field. The image below shows the required variables.

Creation of the variables within the JSON field of the Custom widget component in the Ilevia Manager configuration software.

JavaScript code configuration

Step 3:

In the JavaScript text field, add the code required for the logic to work. The script is shown below:

Click the following link to view the JavaScript code.

Where to add the JavaScript code within the Custom widget component in Ilevia Manager.

Step 4:

Add the variables in the script: these variables get the value of the component specified in the JSON text, among the parameters of the Custom widget component.

JavaScript variables within the code in the Custom widget component in the Ilevia Manager configuration software.

Step 5:

The first function in the JavaScript code is called countDown. This function takes as input the time set by the user in the Adjustable value component and starts the countdown that will switch off the light.

First JavaScript function within the motion sensor code in the Ilevia Manager configuration software.

Step 6:

The second function handles the value coming from the motion sensor and turns on the light when motion is detected. When the motion sensor state changes to Off, this function starts a time interval linked to the first function, called “countDown”.

Second JavaScript function within the motion sensor code in the Ilevia Manager configuration software.

Step 7:

Finally, set the setTrigger: this command runs the function called motion_detection every time the Motion sensor component changes state.

SetTrigger in the JavaScript code of the motion sensor within the Custom widget component in the Ilevia Manager configuration software.

Step 8:

Add the components to the user interface and upload the project to the server.

Uploading the project with the required components to test the motion sensor logic within the user interface of the Ilevia Remote Plus application.

Visual result

This is the final result of the Motion sensor logic in the Ilevia Remote Plus app.

How the motion sensor logic works within the user interface of the Ilevia Remote Plus application.

Click the link below to download the demo project for the motion sensor script with the Custom widget component and try it yourself.

Download the demo project here!

Last updated: