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


  • 1

Auto lock door when after door is closed (door sensor)


serrzy

Question

Hello

 

I am trying to create a scene which will lock the door lock (lockwood door lock device 31) after the door has been closed for 5 seconds (Fibaro door sensor device 114).

 

LUA code is below - what am I doing wrong?

 

Thanks!

 

 

--[[
%% properties
114 armed
%% weather
%% events
%% globals
--]]

local startSource = fibaro:getSourceTrigger();
if(startSource["type"] == "other") then
    fibaro:call(31, "secure");
else
if (( tonumber(fibaro:getValue(114, "armed")) > 0 )) then
setTimeout(function()
local delayedCheck0 = false;
local tempDeviceState0, deviceLastModification0 = fibaro:get(114, "value");
if (( tonumber(fibaro:getValue(114, "armed")) > 0 ) and (os.time() - deviceLastModification0) >= 5) then
    delayedCheck0 = true;
end

local startSource = fibaro:getSourceTrigger();
if (
 ( delayedCheck0 == true )
or
startSource["type"] == "other"
)
then
    fibaro:call(31, "secure");
end
end, 40000)
end
end

Link to comment
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Hey @serrzy Here is an "inspiring piece of code" that can easily be morphed into a script that closes a lock after the door sensor has been closed for five seconds. I wrote this script for the teenagers in my house. It switches off the lights in their room after some period of no movement. See for yourself...

Please login or register to see this code.

 

Link to comment
Share on other sites

  • 0

This should work:

 

 --[[
%% properties
114 armed
%% weather
%% events
%% globals
--]]

if tonumber(fibaro:getValue(114, "value")) == 0  then
  fibaro:sleep(5000);
  fibaro:call(31, "secure");
end

Link to comment
Share on other sites

  • 0

"114 armed" need to be chaged to "114 value" if you want to trigger scene by door state (open/closed).

Link to comment
Share on other sites

  • 0
  • Inquirer
  • Thanks all. The code below works!!

     

    Where is the best place to learn more about LUA?

     

    --[[
    %% properties
    114 value
    %% weather
    %% events
    %% globals
    --]]

    if tonumber(fibaro:getValue(114, "value")) == 0  then
      fibaro:sleep(30000);
      fibaro:call(31, "secure");
    end

    Link to comment
    Share on other sites

    • 0

    It's great - very thank You for this.

     

    I'm looking for ones more improvement.

     

    When I close the door, script wait 5 (or 30) seconds and close the door. Is it possible to if I open door second one before counter reaches 5 (or 30) seconds to break, and wait when I close door for more then 5 (or 30) second.

     

    Thanks Rafal

    Link to comment
    Share on other sites

    • 0
  • Inquirer
  • On 10/02/2018 at 5:22 AM, eustachy said:

    It's great - very thank You for this.

     

    I'm looking for ones more improvement.

     

    When I close the door, script wait 5 (or 30) seconds and close the door. Is it possible to if I open door second one before counter reaches 5 (or 30) seconds to break, and wait when I close door for more then 5 (or 30) second.

     

    Thanks Rafal

     

    Do you mean if you reopen the door to reset the time counter again? I managed to get it to work using this code (adapted from the motion activated lights provided by @

    Please login or register to see this link.

     - thanks!!)

     

     


    --[[ 
    %% properties 
    114 value
    31 value
    %% globals 
    --]]

    if (fibaro:countScenes()>1) then fibaro:abort(); end
     
    function debug(color, message)
        fibaro:debug(string.format('<%s style="color:%s;">%s</%s>', "span", color, message, "span")); 
    end
     
    -- VARIABLES
    local scene = 68 -- ID This scene
    local motion = 114 -- ID for Door sensor
    local switch = 31 -- ID Door lock
    local starttimer = 30; -- Time for delay
    local timer = (starttimer); -- Timer in scene
     
    -- Start loop   
     repeat 
     timer=timer-1; 
     fibaro:sleep(1000);
        
         -- If door sensor is reopened, restart time again
         if (tonumber(fibaro:getValue(motion, "value"))) > 0 then 
             timer=starttimer; 
             debug("grey", "Door sensor open. Time started again");
         end 

     until (timer<1) 
     
    -- Lock door 
    fibaro:call(switch, "secure");
    debug("red", "Door locked");

     

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