• Professional advice
  • Order before 16.30 uur shipped today
  • Almost always available (+31 73 762 0 762)
  • Monday open late

FIBARO LUA functions

FIBARO LUA coding:  Examples, functions and solutions 

With LUA code (only available in the HC2) the Home Center 2 can perform complicated tasks. For example sending a preset-command to a camera when a doorsensor is tripped, of controlling a non-Z-wave smart thermostat, or sent a pushmessage to a Pushover server. And many many more. Lots of people have created virtual devices based on LUA code.

fibaro:abort()

fibaro:calculateDistance()

fibaro:call()

fibaro:countScenes()

fibaro:debug()

fibaro:get()

fibaro:getGlobal()

fibaro:getGlobalModificationTime()

fibaro:getGlobalValue()

fibaro:getModificationTime()

fibaro:getRoomID()

fibaro:getSectionID()

fibaro:getSelfId()*

fibaro:getSourceTrigger()

fibaro:getSourceTriggerType()

fibaro:getType()

fibaro:getValue()

fibaro:isSceneEnabled()

fibaro:killScenes()

fibaro:log()*

fibaro:setGlobal()

fibaro:setSceneEnabled()

fibaro:sleep()

fibaro:startScene()

tonumber()

tostring()

os.time()

 

2 interesting LUA codes 

2)  Creating a home-scene with a random timer
1)  Refresh mesh network

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

2) Creating a scene with a random timer variable

When you're away and want your Z-Wave controller to simulate you are at home, you can do the following: Create a scene that generates a variable and use this variable to switch items of in your house.

 

1) Create a Global Variable in the variable panel called RandomMin
2) Create a new scene 'GenerateRandom' with the following LUA and run it every day at a specific time (in this case 00:15)

 

--[[
%% autostart
%% properties
%% globals
RandomMin
--]]

 

local sourceTrigger = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
while true do

 

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "00:15") )
)
then
   fibaro:debug(fibaro:getGlobalValue("RandomMin"));
   fibaro:setGlobal("RandomMin", tostring(math.random(18,43)));     ---Hier wordt de random waarde bepaald
   fibaro:debug(fibaro:getGlobalValue("RandomMin"));
end

 

   fibaro:sleep(60*1000);
end
else
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
   ( (currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday   == 7) )
   or
   startSource["type"] == "other"
   )
   then
      fibaro:debug(fibaro:getGlobalValue("RandomMin"));
      fibaro:setGlobal("RandomMin", tostring(math.random(18,43)));
      fibaro:debug(fibaro:getGlobalValue("RandomMin"));
   end
end

 

3) After this you need a scene that starts at the random time.

 

--[[
%% autostart
%% properties
%% globals
RandomMin
--]]

 

local sourceTrigger = fibaro:getSourceTrigger();
if (sourceTrigger["type"] == "autostart") then
while true do

 

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
( ((currentDate.wday == 1 or currentDate.wday == 2 or currentDate.wday == 3 or currentDate.wday == 4 or currentDate.wday == 5 or currentDate.wday == 6 or currentDate.wday == 7) and string.format("%02d", currentDate.hour) .. ":" .. string.format("%02d", currentDate.min) == "23:" .. string.format("%02d", tonumber(fibaro:getGlobalValue("RandomMin")) )) )
)
then
   fibaro:call(4, "turnOff");
   -- Here you can add all kinds of actions

 

 end
fibaro:sleep(60*1000);
end
else
   local currentDate = os.date("*t");
   local startSource = fibaro:getSourceTrigger();
   if (
   startSource["type"] == "other"
   )
then
   fibaro:call(4, "turnOff");
   -- Here you can add all kinds of actions

end

 

Done :)
 

 

 

1)  HOW TO: Request neighbour update of a module (mesh network)

Make a scene with the following code.

--[[ %% properties %% globals --]]
fibaro:call(xx,'requestNodeNeighborUpdate')
fibaro:debug('Rediscover all node ')
fibaro:sleep(5000)
--

Set the device ID you have an issue with on xx. When you set 1 it will reconfigure all mesh network.

 

 
Customer Service Phone

+31737620762
mon-fri: 10am-5pm and sat 10am-3pm

 
Adress

Gerstakker 16 5236 VG Empel Netherlands

Google maps