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

simple scene in LUA for automating garage lights


Question

Posted

I'm a beginner and I would like some help with a LUA scene to switch on garage lights when garage door sensor is tripped and it automatically switch them off after 5 minutes(timeout) after the door sensor is not tripped anymore(door closed).I searched the forum and found very elaborated(complex) solutions like Very smart lights  or Advanced llighting control etc.. but they are way more than I need and I didn't manage to configure them.. not have the knowledge

I do not need lux settings(night or day)

Can someone please help me with the code?

 

Thank you

6 answers to this question

Recommended Posts

  • 0
Posted

 

  • 0
  • Inquirer
  • Posted

    I put this code:

    --[[
    %% autostart
    %% properties
    520 value
    569 value
    --]]
    local light=520             -- ID light (Dimmer)
      local motion=569            -- ID motion sensor
      local maxTime  = 1*60      -- time max motion safety
      local dimTime  = 3*60      -- time to dim
      local dimValue = 100        -- value to dim
      local sleepTime = 5 

      function loopUntil(fun,cont,secs)
        local function loop()
          if not fun() then 
            fibaro.setTimeout(1000*secs,loop) 
          else 
            if cont then cont()
            end 
          end
        end
        fibaro.setTimeout(1000*secs,loop)
      end

      fibaro.call(light, 'setValue', 100)   --fibaro.call (light,"turnOn") 
      fibaro.debug("Luzes Dimmer On")    

      local safeTime = 0
      local dimmed = false
      
      loopUntil(

        function()                                     -- Loop function
          if safeTime >= maxTime then return true end                
          safeTime=safeTime+sleepTime                   -- Timer SEGURO
          fibaro.debug("Contando Tempo Seguro",safeTime,maxTime) 
          if safeTime >= dimTime and not dimmed then
            fibaro.call(light,"setValue",dimValue)
            dimmed = true
          end
          if fibaro.getValue(motion,'value') then --> '0' then -- motion violado
            safeTime=0       -- reset safeTime
            dimmed = false
            fibaro.call(light,"setValue",100)
            fibaro.debug("Reset", safeTime)
          end
        end,

        function()  -- Things to do after the loop ends
          fibaro.call(light,"turnOff")    
          fibaro.debug ("Luzes Dimmer Off")    
        end,
        sleepTime
      ) 

     

    but I got error [DEBUG] 22:25:00: 2021-05-31 22:25:00.771722 [ fatal] Unknown exception: /opt/fibaro/scenes/56.lua:26: Assertion failed: Expected string
     

    I do not need deem because I have Fibaro switch, not dimmer for lights..

    • 0
    Posted

    Sorry, I didn't see that you had an HC2. This code runs on the. HC3.

    • 0
  • Inquirer
  • Posted

    OK.. do you have any sugestion for how to acomplish this on my HC2? (not with dimmer,but simple switch for lights)

     

    Thank you

    • 0
    Posted
    --[[
    %% properties
    XXX value 
    %% events
    %% globals
    --]]
     
     
    if (fibaro:countScenes()>1) then
    -- fibaro:debug("abort")
    fibaro:abort();
    end
     
     
     
    if (tonumber(fibaro:getValue(XXX, "value")) > 0)  then
    local timer = 300; -- time in secs
    fibaro:call(XXY, "turnOn");
     
    repeat
    fibaro:sleep(1000);
     
    timer = timer - 1
    if (tonumber(fibaro:getValue(XXX, "value")) > 0) then
    timer=300 -- time in secs
     
    end
     
    until (timer<1)
    fibaro:call(XXY, "turnOff");
     
    end


    Try this where
    XXX = motion sensor ID
    XXY = light ID
    • 0
  • Inquirer
  • Posted (edited)

    I think it's working nice..Will test more in depth tomorrow

    Many thanks for the help !

    Edited by emariu

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