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!



Smart Home Forum by FIBARO Team

  • 0

LUA Code for Single scene to combine multiple scenes into one





I currently have five scenes in LUA format (block scenes converted).


Each scene switches on a light after motion is detected and during a set period of time e.g. if bewteen 07:00 - 16::45 and motion detector is breached, switch on light.


The times in each scene are basically  based on when it gets light in the morning and dark in the evening.


Problem i have is when it comes to changing the time, i have to change each scene one by one.


Is it possible to combine all the scenes so that the time is set only once, and it basically switches on the lights based on which sensor is breached.


Any help much appreciated.



Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

I don't fully understand your setup, but you could consider putting the time into a global variable, and have each scene check the variable. That way you only have one place to update the time. Next, could could write a scene that changes the global variable based on the sunset/sunrise time. That way you wouldn't need to keep manually updating the code. 


It would probably be possible to have a single self contained LUA script too, without the need for a global variable. All depends on how much time you want to spend learning LUA!

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thanks Tim, i think using global variables is the way to go.


    Im new to the whole LUA code, just learning so trying to create one script is beyond me at this stage!!



    Link to comment
    Share on other sites

    • 0

    Not sure if it's useful for your purpose, but I have a number of scenes for the lighting in a wide range of time.

    Which are then switched on or off by a LUX measurement. In fact, lighting is never switched on unnecessarily then.

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Thanks ppeterr


    im just trying to get global variable to work.


    I have HC2 in case that makes a difference in the way LUA works.


    Have set global variables, called LightsOn and LightsOff, both set to 0


    In this script im trying to set the global variable to 1 if the time of day is bewteen the two variables i have set in the script


    %% properties
    %% events
    %% globals

    -- add global variable with name "Flag" and value 0 using global variable panel
    local LightsOn     = fibaro:getGlobalValue("LightsOn")
    local ct        = os.date("%H:%M",os.time())
    local from_time = "17:15"
    local to_time   = "07:15"


    local sourceTrigger = fibaro:getSourceTrigger()
    --if sourceTrigger['type']=='property'then fibaro:debug("Scene run by motion")else fibaro:debug("Scene run manually")end
       if ct >= from_time and ct <= to_time then
    --  else
    --    fibaro:debug("Motion detect, but button already pressed once")
      -- end



    At this stage i just want the script to acknowledge the current time is e.g 20:15 and to set the global variable to 1


    If i can get it to do that , i can than have a another script which turns on the lights if the global variable is 1


    It wont go to step 2, any ideas what i m doing wrong?



    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.

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