Jump to content
Guides for the Forum Read more... ×
Poradniki na Forum Read more... ×
  • 0
Ilja

My First scene - Don't work as i expected

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

 

 

 

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

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

 

Share this post


Link to post
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

    Share this post


    Link to post
    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.

    Share this post


    Link to post
    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?

     

    Share this post


    Link to post
    Share on other sites
    • 0

    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

    Share this post


    Link to post
    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

    Share this post


    Link to post
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now

    ×