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

Setting and Getting Global Variables


Lenny212

Question

Hi,

I couldn't delete my question so I edited it and turned it into a description of what I did.

---------------------------------------------------------------------------------------------------------------------------------

I want to set two global variables in two separate Lua scenes. (Both are manually triggered)

I then want to access those global variables in another scene. (Triggered based on time of day matching global variables)

----------------------------------------------------------------------------------------------------------------------------------

I created a variable called Time and a LUA scene called TimeTrigger.

--[[
%% properties
%% autostart
%% events
%% globals
--]]

if (fibaro:countScenes()>1)
then
  fibaro:debug('Scene already running')
  fibaro:abort()
end

while (true) do
  local currentDate = os.date('*t')
  local currentTime = string.format('%02d', currentDate.hour) .. ':' .. string.format('%02d', currentDate.min)
  fibaro:debug('Time = ' .. currentTime)
  fibaro:setGlobal('Time', currentTime)
  fibaro:sleep(60*1000)
end

------------------------------------------------------------------------------------------------------------------------------------------

I then created a LUA scene called 6amWakeUp (and 5am, 7am, 8am, 9am)

--[[
%% properties
%% events
%% globals
--]]
fibaro:setGlobal('WakeUpHour', '06');

------------------------------------------------------------------------------------------------------------------------------------------

I then created a LUA scene called 30WakeUp (and 00, 15, 45)

--[[
%% properties
%% events
%% globals
--]]
fibaro:setGlobal('WakeUpMinute', '30');

------------------------------------------------------------------------------------------------------------------------------------------

I then created the scene to open roller shutters/blinds in the morning

--[[
%% properties
%% events
%% globals
Time
--]]
local time = fibaro:getGlobal('Time')
local WakeUpHour = fibaro:getGlobal('WakeUpHour')
local WakeUpMinute = fibaro:getGlobal('WakeUpMinute')
local WakeUpTime = WakeUpHour .. ':' .. WakeUpMinute
if 
(
  (time == WakeUpTime)
    and
  (tonumber(fibaro:getGlobalValue("WakeUp")) == tonumber("1"))  --[[This is a 0/1 toggle variable so I can turn off the morning wake up--]]
)
then
  fibaro:call(53, "open");
  fibaro:call(56, "open");
  fibaro:sleep (10000)
  fibaro:call(222, "open");
  fibaro:sleep (10000)
  fibaro:call(74, "open");
...etc

end

----------------------------------------------------------------------------------------------------------------

 

Edited by Lenny212
Solved issue and changed text from question to solution
  • Like 1
Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

By the way you don't need the first scene. 

Set the last scene in loop every minute and compare the time directly there.

Less load on HC2.

Right now you have two scenes running every minute..(first and last).

Another suggestion is to create Virtual device to set wake up time and not to execute so many scenes....

Edited by cag014
Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thx @cag014, I have created the first scene as I may use it as a trigger for multiple scenes down the track.

    Edited by Lenny212
    Link to comment
    Share on other sites

    • 0

    You can use same solution that you did using "while(true) do" loop.

    But there is Fibaro's function setTimeout(Func_Name, sleepTime)  for this purpose.

     

    Please login or register to see this code.

    Set scene to Automatic

    Please consider to create Virtual Device with buttons to set wakeup time.

    EDIT: function mane

    2 hours ago, Lenny212 said:

    Thx @cag014, I have created the first scene as I may use it as a trigger for multiple scenes down the track.

    Right now I see only the last scene with global trigger. I don't think you need to trigger other scene using global variable "time".

    Keep using setTimeout() function.

     

    Edited by cag014
    Link to comment
    Share on other sites

    • 0

    Please pay attention...  I did mistake on line setTimeout(WakeUpTime, 60*1000)

    should be setTimeout(isWakeUpTime,60*1000)   

    wrong function name.. sorry

    Link to comment
    Share on other sites

    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...