Table of contents
With LUA language you can easily broaden the possibilities of your FIBARO Home Center system by creating pop-ups for your mobile phone. In this short tutorial you will get to know how to create them.
Requirements
- FIBARO Home Center 2,
- FIBARO Z-Wave devices,
- Smartphone with FIBARO App connected to Home Center.
Step-by-step instruction
- Log in to your FIBARO Home Center.
- Click on Scenes.
- Choose Add scene.
- Find Add scene in LUA and click on Add.
- Now you can see the box where you can type the LUA code.
- Every pop-up LUA scene contains of four parts: triggers paragraph, defying local variables, conditions-result and pop-up settings.
- Remember to save the scene.
Triggers Paragraph
1 2 3 4 5 6 7 8 9 |
--[[ %% properties 72 value %% events %% globals --]] |
That means that scene will trigger if property “value” of device with ID 72 changes.
Local Variables are used to make the code clearer and easier to modify in the future.
1 2 3 4 5 6 |
-- ID of Motion Sensor local MotionSensorID = 72 -- variable which contains the icon url (you can upload your own icon; remember to modify the IP address to your Home Center IP), local imgUrl = 'http://192.168.103.97/fibaro/icons/motion_sensor/motion_sensor0.png' -- variable which contains current time, local currentDate = os.date("*t"); |
Conditions and result
Depending on scene you can choose here requirements that have to be fulfilled in order to your needs. In most cases condition and result formula looks like: if (condition) then (result).
For example you can limit instances running at the same time:
1 2 3 4 |
-- allow only one instance of this scene to run at a time if (fibaro:countScenes() > 1) then fibaro:abort() end |
Pop-up settings
Start with HomeCenter.PopupService.publish({}) function. Then, there are a few settings you can manage to get a satisfactory outcome:
title – required title of pop-up
subtitle – optional subtitle of pop-up
contentTitle – optional title of pop-up content
contentBody – required body of pop-up content
img – notification image in .jpg, .png, or .bmp file format
type – type of the pop-up
buttons – definition of buttons used in the pop-up
Look at the example of this part below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
-- opening the pop-up window, HomeCenter.PopupService.publish({ -- title – required field, title = 'No motion detected', -- subtitle – optional field, subtitle = string.format("%02d:%02d:%02d | April %02d, %04d", currentDate.hour, currentDate.min, currentDate.sec, currentDate.day, currentDate.year), -- Title of the pop-up content (optional), contentTitle = 'No motion since last 15 minutes', -- Content of the pop-up – required field, contentBody = 'Should I run the scene "Night"?', -- Image of the notification (acceptable formats - .jpg, .png, .bmp), img = imgUrl, -- Notification type: ('Info' – blue color, 'Success' – green color, 'Warning' – yellow color, 'Critical' – red color) type = 'Success', -- defying buttons – ‘caption’ – text of the button, sceneId – Id of scene that will be started after clicking on button (0 – no scene will be started), you can defy up to 3 buttons, in default there will be a button with ‘Ok’ buttons = { { caption = 'Yes', sceneId = 1 }, { caption = 'No', sceneId = 0 } } }) |
The popup will look like this:
Types of notification color
- Green border color:
- Blue border color:
- Yellow border color:
- Red border color:
1 |
type = 'Success', |
1 |
type = 'Info', |
1 |
type = 'Warning', |
1 |
type = 'Alert', |
Number of buttons
- One button:
- Two buttons:
- Three buttons:
1 2 3 |
buttons = { { caption = 'Ok', sceneId = 0 } } |
1 2 3 4 |
buttons = { { caption = 'Yes', sceneId = 1 }, { caption = 'No', sceneId = 0 } } |
1 2 3 4 5 |
buttons = { { caption = 'Yes', sceneId = 2 }, { caption = 'No', sceneId = 1 }, { caption = 'Cancel', sceneId = 0 } } |
Hint
As you can see, each button used as a part of a pop-up may trigger different scene. The only thing you have to know is scene’s ID which may be obtained in its settings. This is why each scene must be firstly created before using in a pop-up.