Fibaro HC2: LUA script to check the status of windows and doors

Fibaro HC2: LUA script to check the status of windows and doors

Perhaps many of you have encountered the situation that you were leaving your own home. You may did not know if you had left any of the windows open. So you had to go check the window in a particular room. In this blog will be presented a short and simple LUA script, which will send you a PUSH notification with information about the window or door that remained open.

This LUA script can run eg:

  • if you press the Fibaro Button, you have at the exit door
  • if you are using a Zipato RFID keypad to activate or deactivate the alarm
  • e.g. change the value of a predefined variable in the Fibaro system
  • the LUA script can run another magic, block, or LUA scene in the Fibaro system

You can link the script to any condition that suits you.

Changes to the LUA script

In the LUA script below, you need to make some adjustments to work with your control unit.

Need to know:

1. IDs of the Window and Door Sensors you want to check. (LUA 8th line)

Then insert these values in the LUA script on the 8th line, which looks like -> sensors = {33, 37, 59}

2. IDs of the Mobile Devices to which you want to send PUSH notifications. (9th LUA line)

Then insert these values in the LUA script on the 9th line, which looks like this -> phones = {205, 206}

LUA script

%% properties
%% weather
%% events
%% globals

sensors = {33, 37, 59} -- IDs of Windows or Door sensors
phones = {205, 206} -- IDs of Mobile Devices for PUSH Notifications

local sensor_triggered = 0;
local sensor_name = 0;
local sensor_room = 0;
local message1 = "Okno miestnost: "; -- content of PUSH notification for Room Name, can be changed
local message2 = "Okno zariadenie: "; -- content of PUSH notification for Device Name, can be changed
local message3 = "Vsetko zatvorene!"; -- content of PUSH notification when no sensor is triggered

function sensors_check()

for i=1, #sensors do

if(tonumber(fibaro:getValue(sensors[i], "value")) > 0) then
sensor_triggered = 1;
sensor_name = fibaro:getName(sensors[i]);
sensor_room = fibaro:getRoomNameByDeviceID(sensors[i]);
message1 = message1 .. sensor_room .. " | ";
message2 = message2 .. sensor_name .. " | ";



function message_push()

if (sensor_triggered == 1) then

for j=1, #phones do
fibaro:call(phones[j], "sendPush", message1);
fibaro:call(phones[j], "sendPush", message2);


elseif (sensor_triggered == 0) then

for j=1, #phones do
fibaro:call(phones[j], "sendPush", message3);




-- main code


PUSH notification on mobile device

Push notification on mobile phone looks like in both the original and new FIBARO controllers.


Note 1: This LUA script is an inspiration, you can incorporate the changes by yourself. e.g. not just send notification as PUSH notification but as email.

Note 2: To send only room name to PUSH notification, comment out (-) all lines in the LUA script containing "message1".

Note 3: To send only a specific device name to the PUSH notification, comment out (-) all lines in the LUA script containing "message2".

How do I get the Window and Door Sensor IDs?

You can get the Z-Wave ID of your window and door sensors in several ways:

  • after clicking on the advanced options of the Z-Wave device either in the URL address or directly in the device description


  • directly when creating an LUA script / scene using the left side panel



How do I get the Mobile Device ID value subscribed to the Fibaro system?

You can get mobile device IDs in several ways:

  • when converting a Block Scene using mobile devices to a LUA scene


  • in Fibaro settings -> Access control -> Mobile devices list -> in browser Click F12 -> Explorer -> locate mouse arrow to specific mobile device on Checkbox



Posted on 27.05.2019 Tutorials and Tips, FIBARO, FIBARO HC2, LUA scripts for HC2 2 11255

Related articles

Using Aeon Labs Minimote in Fibaro HC2

Using Aeon Labs Minimote in Fibaro HC2

LUA Script: Battery check - Fibaro Home Center 2

A simple LUA script to check the status of battery devices.

LUA: Fibaro Swipe

Implementations and setting the device for the triggering of the Fibaro Swipe scenes using the LUA script.


  • Norbert Kovács

    Norbert Kovács 25.12.2020 Reply


    the scene runs on the controller, but no push notification comes
    - I entered phone IDs
    do I need to change anything else?

    thank you and merry christmas!
    • SmarterHOME Team

      SmarterHOME Team 26.12.2020 Reply

      thank you for comment.

      Are you sure that you entered correct IDs of mobile/smart devices?
      If yes then - Are you able to connect to your HC2 trough cloud (FIBARO ID service)?
      If yes, try to reboot your HC2.

      Have a nice day.

Leave a CommentLeave a Reply

Blog search

Latest Comments

Recently Viewed

No products


Compare 0