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

My First scene - Don't work as i expected


Ilja

Question

Hello!

I try to start learning Lua to create Nice Scene!

I can do 3 Different Scenes in Graphic to realize my idea.

But i wish do ONE with LUA Programing..

I don't have any errors, if i press button PLAY all is fine, But it work only once.

Can you please look my code and tel what i must do that this scene will be Loop.

THANKS, FOR HELP!

ILJA.

 

local startSource = fibaro:getSourceTrigger();
-- Set All Outside Light to 1 % - Not Veranda Becose veranda is ON by user
if (
    fibaro:getGlobalValue("DayLight_Status") == "Dark"  and  
    fibaro:getGlobalValue("Day_Status") == "Night"  and  
    fibaro:getGlobalValue("Outside_Front") == "OFF"  and  
    fibaro:getGlobalValue("Outside_Light") ~= "Night"  and  
    fibaro:getGlobalValue("VerandaLight") == "On" ) then
  
      fibaro:call(227, "setValue", "1");
    fibaro:call(228, "setValue", "1");
    fibaro:call(229, "setValue", "1");
  
-- Set All Outside Light to 1 % Becouse is to late and we save energy:)

elseif (
    fibaro:getGlobalValue("DayLight_Status") == "Dark"  and  
    fibaro:getGlobalValue("Day_Status") == "Night"  and  
    fibaro:getGlobalValue("Outside_Front") == "OFF"  and  
    fibaro:getGlobalValue("Outside_Light") ~= "Night"  and  
    fibaro:getGlobalValue("VerandaLight") == "Off" ) then

    fibaro:call(226, "setValue", "1");
      fibaro:call(227, "setValue", "1");
    fibaro:call(228, "setValue", "1");
    fibaro:call(229, "setValue", "1");
    fibaro:setGlobal("Outside_Light", "Night");


-- Set All Outside Light to 8 % Evening light.

elseif (
    fibaro:getGlobalValue("DayLight_Status") == "Dark"  and  
    fibaro:getGlobalValue("Day_Status") == "Day"  and  
    fibaro:getGlobalValue("Outside_Front") == "OFF"  and  
    fibaro:getGlobalValue("Outside_Light") ~= "Evening" )
    
      then
    
    fibaro:call(226, "setValue", "8");
      fibaro:call(227, "setValue", "8");
    fibaro:call(228, "setValue", "8");
    fibaro:call(229, "setValue", "8");
    fibaro:setGlobal("Outside_Light", "Evening");
  
end

 

 

 

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 1

only from second if run.

For information:

  • if fibaro:countScenes() > 1 then fibaro:abort(); will kill every NEW instance of the scene and keep the first instance running. 
  • parameter "%% killOtherInstances" at begging of scene code will kill all PREVIOUS started instances of a scene and the NEWEST instance will go through.
  • Like 1
  • Thanks 1
Link to comment
Share on other sites

  • 0

Take decision run your code in loop or triggered if any of checked in code variables are changed.

For loop:

Please login or register to see this code.

For triggering method (preferred by looking resource):

 

Please login or register to see this code.

 I wrote the code quickly and I couldn't test it now on HC2 but I think it's ok.

 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thanks for help.

    Can you help me once again.

    I was found way how run it loop

    Please login or register to see this code.

     

    if (startSource["type"] == "autostart") then
     while true do
        fibaro:sleep(1*1000)

    Please login or register to see this code.

     end

    end

     

    Is this wrong?

    It's work few days, and I'm Happy but question how it load System?

    If i will have 10-20 Scenes like this.

     

    THANKS!

     

     

     

    Edited by Ilja
    Link to comment
    Share on other sites

    • 0

    Yes it's ok. For load the system, the question is number of VD's with code in main-loop and scenes running continuously and simultaneously.

    A few simple scenes like this one doesn't use many recurse.

    I things is good that you add code for kill instance if run more that one. This happens sometimes (HC2 can do it). In your loop add:

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks again, yes i will add 

    Please login or register to see this code.

    But this will kill all processes or only from second?

     

    Link to comment
    Share on other sites

    • 0

    no problem, good luck with LUA, there are a lot of helpful people on the forum so it will be easier to start

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