LUA script 2: Push Notifications for Fibaro HC2

LUA script 2: Push Notifications for Fibaro HC2

LUA Script 2: Push notifications for Fibaro HC2

A manual in which we will show you how to create notifications using the LUA code if a socket is switched on somewhere. These notifications can help you to have full control and overview of the electric appliances in a smart house.

ID of the Z-Wave devices

At the beginning you have to find out which ID of the Z-Wave devices will run the script. You will find this ID easily, just click the setting of the selected device and in the basic settings you will see the ID of the device. See the figure.

fibaro device id

Note: Note down the ID of the Z-Wave device, you will need it in the LUA script.

ID of the notifications

Then create a new notification in the Notifications panel – it may look like this. In the panel where the url address is displayed it is necessary to note down the ID of this notification, it will be later used in the LUA scene.

fibaro panel oznameni

Note: Note down the ID of the notification, you will need it in the LUA script.

ID of the mobile device

Then find out the ID of the mobile device into which you want to send these Push notifications. In the settings of the FIBARO system and in the Access management panel you should copy the name of the device into which you want to send the notifications. Then open a new window in the browser and enter the following link http://IP_adresa_HC2/api/devices , search for the name of the device (ctrl+f) that you had copied before and you will see the ID of the mobile device next to it.

fibaro uzivatelia

fibaro mobile id

Note: Note down the ID of the notification, you will need it in the LUA script.

LUA script

At this point you can create the LUA script. In the Scenes panel create a new scene in LUA. The LUA scene will look like this.

fibaro push

The LUA script for copying is below. In this LUA script it is necessary to change the following:

  • ID of the Z-Wave device in lines 3 and 10
  • ID od the mobile device in line 16
  • ID of the notification again in line 16
  • ID of the scene that starts to run after you have pushed the button

LUA script

 
--[[
%% properties
1019 value
%% globals
--]]


local startSource = fibaro:getSourceTrigger();
if (
    ( tonumber(fibaro:getValue(1019, "value")) > 0 ) 
    -- 1019 = treba zmenit za ID Vasho zariadenia (ako zistit ID zariadenia je popísané vyssie)
or
startSource["type"] == "other"
)
then
  fibaro:call(912, "sendDefinedPushNotification", "890") 
  -- 912 = ID zariadenia, na ktore sa posle Push notifikacia (ako zistiť ID v clanku)
  -- 890 = ID zvolenej notifikácie (ako zistiť ID v clanku)
  HomeCenter.PopupService.publish({ 
    title = 'Zásuvka v ShowRoome', -- hlavny nadpis
    subtitle = 'bola zapnutá', -- podnadpis 
    contentTitle = 'Chceš niečo vykonať?', -- hlavna otazka
    contentBody = 'Želáš si ju vypnúť?', -- podotazka
    img = 'https://smarterhome.sk/img/cms/smarterhome.png', -- adresa na png obrazok notifikacie
    type = 'Success', -- Sucess = oznam (zelena notifikacia), Critical = vystraha (cervena notifikacia)
    buttons = {
        { caption = 'Áno', sceneId = 44 }, -- tlacidlo ANO, ID sceny, ktoru spusta v pripade stlacenia
        { caption = 'Nie', sceneId = 0 }, -- tlacidlo NIE, ID sceny je 0 a tak sa nevykona ziadna akcia
        -- mozne pridat aj tretie tlacidlo
    }
})
end
    
  

In lines 27 and 28 you can find those buttons that run the selected scenes.

In line 27 the Yes button is defined, it runs the scene with ID 44 - this scene switches off the socket.

In line 28 No is defined, this does not run anything because the ID of the scene is 0 (such a scene does not exist)

Finding out the ID of the scene

Do you want to know how to find out the ID of the scene? It is simple, it is enough to open the selected scene and the ID of the address is displayed at the end in the url address displayed by the web browser.

fibaro scene id

Notification in a mobile device

And it looks like this in the mobile device.

fibaro push mobile

 fibaro push mobile

Related articles

LUA Script: Battery check - Fibaro Home Center 2

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

Zanechajte nám Váš názorZanechajte odpoveď

Vyhľadávanie v blogu

Najnovšie názory

Recently Viewed

No products

Menu

Compare 0