Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


  • 0

LUA tempfunc


Question

Posted

Hi all,

 

I am trying to learn the LUA scripting bit by bit based on what I can find online and by understanding the transformed code from building block into lua.

 

I am setting up my scenes in small bits and try to make it bigger when it works.

 

I have created a scene which is switching of 3 lights when the lux sensor is lower than 100 lux. This should only be active during daytime (8.00 and 23.00)

At 23.01 I have another scene active to switch all lights off.

Please login or register to see this code.

--[[
%% properties
38 value
%% globals
--]]

local sourceTrigger = fibaro:getSourceTrigger();
function tempFunc()
local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(38, "value")) > 100  and  (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "08", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "23", "00"))) and (math.floor(os.time()/60)-math.floor(1441087200/60))%60 == 0 )
)
then
 fibaro:call(20, "turnOff");
 fibaro:call(28, "turnOff");
 fibaro:call(16, "turnOff");
end

setTimeout(tempFunc, 60*1000)
end
if (sourceTrigger["type"] == "autostart") then
tempFunc()
else

local currentDate = os.date("*t");
local startSource = fibaro:getSourceTrigger();
if (
 ( tonumber(fibaro:getValue(38, "value")) > 100  and  (tonumber(os.date("%H%M")) >= tonumber(string.format("%02d%02d", "08", "00")) and tonumber(os.date("%H%M")) <= tonumber(string.format("%02d%02d", "23", "00"))) )
or
startSource["type"] == "other"
)
then
 fibaro:call(20, "turnOff");
 fibaro:call(28, "turnOff");
 fibaro:call(16, "turnOff");
end

end

 

What I am trying to understand is why the code is repeated twice. After the first 3 turnoff commands there is an additional block of code after
setTimeout(tempFunc, 60*1000)...  can somebody tell me what it is for ? If I remove the code it does not work

Please login or register to see this image.

/emoticons/default_icon_smile.gif" alt=":-)" />

 

 

1 answer to this question

Recommended Posts

  • 0
Posted

This block is for running scene if it is triggered manually or by autostart. Both cases do not apply to your code. If you want scene to be simply active in some period of time you do not need setTimeout etc. Just check for the time and run scene if current hour is in some time window. It will look something like this:

Please login or register to see this code.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...