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

interesting light scene


Jackson

Question

I'm trying to create a scene with Graphic blocks but it doesn't work out the way I want it to be.
So I think I have to do this in LUA.

 

The idea is the following:

 

1 - when entering a room when light must turn on at 50% brightness, after sunset, for 2 minutes.
2 - after these 2 minutes the light has to dim to 10% brightness during 10 minutes and then go off if no one has entered the room in this time.
3 - when someone enters the room within these 10 minutes the cycle has to start over again, so go back to 1

 

Can this still be done with Graphic blocks and how can I do this? Of do I have to do it in LUA?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

I think it is too advanced for block scenes but it rather easy in LUA.

 

Here is a lua program for turning on lights on movements and keeping it on for 50 sec unless there is movement. You can easely expand it with dimming function and longer period with lights. 

Please login or register to see this link.

I have a program in my hall that is in the lines with your ideas. It is just not connected with sunset but with time. It dimmes light in four steps with only 10 percent during the night.

 

Link to comment
Share on other sites

  • 0
4 hours ago, Thomasn said:

...Here is a lua program for turning on lights on movements and keeping it on for 50 sec unless there is movement...

Hi Thomasn,

 

I've have tried your LUA script, but when I manually turn on the light, it doesn't stay on, the light goes off after the 50 sec. 

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thank you @Thomasn

     

    I was missing the part of a period dimmed light and then turn off at no movement OR bighten up the light at new movement. Unfortunately it doesn't work, I seems I am missing something....

    Script ends immediately with debug: Light Off.

     

    ------------- Variables. Change to own values---------------------------------------------------
     
    local motion = 35-- ID for PIR
    local switch = 77 -- ID for Switch
    local starttimer = 10; -- Time for light to be on in seconds
    local timer = (starttimer); -- timer
     
    ------------- Do not edit program below this line -----------------------------------------------
     
    function debug(color, message)
        fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
    end
     
    -- Turn on / off light---------------------------------
    if ( tonumber(fibaro:getValue(motion, "value")) > 0  )
      then -- Movement!
      -- 2 minuten op 50%
              fibaro:call(switch, "setValue", "50");
            debug("green", "Light 50%") 
            fibaro:sleep(5000);
            fibaro:call(switch, "setValue", "10");
            debug("green", "Light 10%") 
     
    ------------------ Start loop ----------------------------------------
      repeat
      -- timer starts  
        timer=timer-1;
            fibaro:sleep(1000);
             debug("grey", timer)
    -- if movement then restart timer------------------
           if (tonumber(fibaro:getValue(motion, "value"))) > 0 then
                timer=starttimer;
                debug("grey", "I see movement. Timer reset");
                  fibaro:call(switch, "setValue", "50");
                fibaro:sleep(5000);
                fibaro:call(switch, "setValue", "10");
             end
     
    until (timer<1)
    end
    ---------------- Program terminates. Light off ----------------------
    fibaro:call(switch, "turnOff");
    debug("red", "Light off");

    Link to comment
    Share on other sites

    • 0
    5 hours ago, SmartHomeEddy said:

    Hi Thomasn,

     

    I've have tried your LUA script, but when I manually turn on the light, it doesn't stay on, the light goes off after the 50 sec. 

    No, that is how I have designed the program. But you could add a line or two where a manually use of the switch will terminate the program. I would do it by setting a variable to 1 if the switch is used manually. Replace the scrip's manual control with this:

     

    If  (tonumber(fibaro:getValue(switch, "value")))  < 1 then

    fibaro:setGlobal("switchvariable", "1")

    fibaro:abort()

    end

     

    and add a line in the beginning of the script like this:

     

    if (tonumber(fibaro:getGlobal("switchvariable"))=1) and (tonumber(fibaro:getValue(switch,"value"))) < 1 then fibaro:abort(); else fibaro:setGlobal("switchvariable","0"); end

     

    Remember to create the global variable switchvariable and that the pir-trigger first works again if the light is manually turned off

     

    NB: I have not tested the script!.

     

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

     

    Ok, this works for me - it is in Danish and the permanent on/off is not implemented:

     

     

    local motion = 264 -- ID for bevægelsessensor

    local motionToo = 277 -- ID for bevægelsessensor 2

    local switch = 51 -- ID for relækontakt

    local starttimer = 50 -- tid for tændt lys (ændres ikke af program)

    local timer = (starttimer); -- timer, der ændres i program

    local currenttime = os.date('*t'); -- Klokkeslet

    local currenthour = currenttime['hour']; -- Klokkeslet heltime

     

    -- TÆND OG SLUK LYS

    -- if (tonumber(fibaro:getValue(switch, "value")) < 1) then -- lys slukket?

     

    -- Hvis det er sen aften, så tænd med 20% styrke

    if (currenthour >= 22 ) then

    fibaro:call(switch, "setValue", "20");

    debug("grey", "20%");

    -- Hvis det er tidlig aften, så tænd med 40%

    elseif (currenthour >= 18) then

    fibaro:call(switch, "setValue", "40");

    debug("grey", "40%");

    -- Hvis det er sen eftermiddag, så tænd med 60%

    elseif (currenthour >= 16) then

    fibaro:call(switch, "setValue", "60");

    debug("grey", "60%");

    -- Hvis det er dag, så tænd med 80%

    elseif (currenthour >= 6) then

    fibaro:call(switch, "setValue", "80");

    debug("grey", "80%");

    -- Hvis det er midnat, så tænd med 3% styrke

    else

    fibaro:call(switch, "setValue", "3");

    debug("grey", "3%");

    end

     

    debug("green", "Tænder lys");

     

    -- løkke startes

     

    repeat

    timer=timer-1;

    fibaro:sleep(1000);

     

    -- Genstarte tid, hvis der er bevægelse inden for forsinkelsen

    if (tonumber(fibaro:getValue(motionToo, "value")) > 0) or (tonumber(fibaro:getValue(motion, "value")) > 0) then

    timer=starttimer;

    debug("grey", "Nulstil tid, bevægelse erkendt");

    end

     

    -- Slukker for lyset, når kontakt benyttes

    if (tonumber(fibaro:getValue(switch, "value"))) < 1 then

    debug("red", "Manuelt tryk observeret - løkke afbrydes");

    timer=0

    fibaro:sleep(7*1000);

    end

    debug("green", timer);

    until (timer<1)

     

     

    -- Slukker for lys, når tiden er gået

    fibaro:call(switch, "turnOff");

    debug("red", "lys slukkes");

    Edited by Thomasn
    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • Hi, I got it working!

    I forgot to write the ID's between the --[[   ]]-- part

    There are still a lot of debugmessages, but that may be handy for someone else.

     

    --[[ 
    %% autostart
    %% properties
    35 value
    37 value
    77 value
    %% weather
    %% events
    %% globals
    Dagdeel
    --]]
     
    -- This program use a PIR to turn on light. If there is movement during this period
    -- the timer is reset. If the switch for the light is used manually the light will be
    -- turned off as it will when the program terminates.
    -- As standard the light is on for 50 seconds - but that can be changed in the
    -- variable section below.
    -- Made in Denmark by Thomas G. Nielsen 2017.


    local startSource = fibaro:getSourceTrigger();
    -------- Do not start additional scenes ------------------
    if (fibaro:countScenes()>1) then fibaro:abort(); end
    --------------------------------------------------------------
     
    ------------- Variables. Change to own values---------------------------------------------------
     
    local motion = 35 -- ID for PIR
    local lux = 37    -- ID for luxmeter
    local switch = 77 -- ID for Switch
    local starttimer = 600; -- Time for light to be on in seconds
    local timer = (starttimer); -- timer
     
    ------------- Do not edit program below this line -----------------------------------------------
     
    function debug(color, message)
        fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span"));
    end

    -- Turn on / off light---------------------------------
    debug("blue", "Start script")
    debug("orange" , "motion = ".. tonumber(fibaro:getValue(motion, "value")))
    debug("orange" , "lux = " .. tonumber(fibaro:getValue(lux, "value")))
    debug("orange" , "dagdeel = " .. fibaro:getGlobalValue("Dagdeel"))
      
    if ( 
            tonumber(fibaro:getValue(motion, "value")) > 0  
       and  tonumber(fibaro:getValue(lux, "value")) <= 20  
       and  fibaro:getGlobalValue("Dagdeel") == "Avond"  
       and  tonumber(fibaro:getValue(switch, "value")) == 0 
      )
      then -- Movement!
      -- 2 minutes at 50%
              fibaro:call(switch, "setValue", "50");
            debug("green", "Light 50%") 
            fibaro:sleep(120000);
            fibaro:call(switch, "setValue", "10");
            debug("green", "Light 10%") 
     
    ------------------ Start loop ----------------------------------------
      repeat
      -- timer starts  
        timer=timer-1;
            fibaro:sleep(1000);
             debug("grey", timer)
    -- if movement then restart timer------------------
           if (tonumber(fibaro:getValue(motion, "value"))) > 0 then
                timer=starttimer;
                debug("grey", "I see movement. Timer reset");
                  fibaro:call(switch, "setValue", "50");
                fibaro:sleep(120000);
                fibaro:call(switch, "setValue", "10");
             end
     
      until (timer<1)
      ---------------- Program terminates. Light off ----------------------
      fibaro:call(switch, "turnOff");
      debug("red", "Light off");
    end

    debug("blue","End script")

    Edited by Jackson
    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...