Convert from Fibaro LUA to Domoticz LUA

Moderator: leecollings

Post Reply
vinisz
Posts: 11
Joined: Monday 21 January 2019 20:05
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Convert from Fibaro LUA to Domoticz LUA

Post by vinisz »

Hi All,

I'm switching from Fibaro HC2 to Domoticz.
Now I have this LUA scene below which I used for my lighting, it works very well so I would like to use it in Domoticz.
However, I tried some things but cannot get it to work,
If someone can take a look at it and maybe help me "translate" this, that would be really nice...



--[[
%% properties
505 value
513 value
%% globals
--]]


if (fibaro:countScenes()>1) then fibaro:abort(); end



function debug(color, message)
fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
end


local zon = (fibaro:getGlobal("zonstand"))
--if zon ~= "Onder" then
-- debug("orange", "Zon is niet onder, stop de scene");


-- VARIABELS
local motion = 505 -- ID for PIR
local switch = 513 -- ID Contact
local starttimer = 900; -- Time for delay, in seconds
local timer = (starttimer); -- Timer in scene
--local stroomverbruik = 1012 --Id voor een verbuiker zoals een stekker



-- Turn on and OFF
if (tonumber(fibaro:getValue(motion, "value")) > 0 ) and (tonumber(fibaro:getValue(switch, "value")) < 1) and (zon == "Onder") then -- Movement?

fibaro:call(switch, "turnOn");
debug("green", "Light on");
fibaro:sleep(10000);
end


-- Start loop
repeat
timer=timer-1;
fibaro:sleep(1000);

-- If movement start time again
if tonumber(fibaro:getValue(motion, "value")) > 0 then
timer=starttimer;
--debug("grey", "Movement. Time started again");

end

-- Turn off if switch is used
if (tonumber(fibaro:getValue(switch, "value"))) < 1 then
debug("red", "Manual push on switch - program terminated");
fibaro:abort()
end
until (timer<1)



-- Turn off light
fibaro:call(switch, "turnOff");
debug("red", "Light off");
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest