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

Automatic light with movement


Question

Posted

Hi

I'm a very beginner with LUA, I found a nice script that turns on light on movement and turns it of after a while, when no movement is recognized.

The script works well and does exactly what I want, but it does it only once. After the light is turned of, it does not switch on any more, only if i restart the script manually.

Has somebody an idea what I do wrong? thank you

Angelo

-> original script by

Please login or register to see this link.

--[[

%% properties

%% autostart

%% properties

100 value

132 value

%% globals

** Automatic light switch turning on when motion is detected. During a 2 minute

period the scene checks for additional movement. If there is movement, the countdown starts

over for another 2 minutes. All until there has been no movement for the duration of 2 minutes.

--]]

local LightID = 132

local MotionSensorID = 100

if fibaro:getValue(LightID, "value") == "1" then

repeat

local LightStatus = fibaro:getValue(LightID, "value")

fibaro:debug("Licht is aktuell an, warte 2 Minuten")

fibaro:sleep(2*60000)

until fibaro:getValue(LightID, "value") == "0"

else

repeat

fibaro:debug(fibaro:getValue(MotionSensorID, "value"))

local MotionSensorState = fibaro:getValue(MotionSensorID, "value")

fibaro:sleep(1*1000);

until MotionSensorState == "1"

fibaro:call(LightID, "turnOn")

fibaro:debug("Licht wurde eingeschaltet")

i = 24

repeat

local MotionSensorState = fibaro:getValue(MotionSensorID, "value")

fibaro:debug(fibaro:getValue(MotionSensorID, "value"))

if MotionSensorState == "1" then i = 24

fibaro:debug("Countdown reset: "..i)

else i = i - 1

fibaro:debug("Countdown: "..i)

end

fibaro:sleep(5*1000);

until i < 1

fibaro:call(LightID, "turnOff")

fibaro:debug("Keine Bewegung mehr, Licht wurde ausgeschaltet")

end

17 answers to this question

Recommended Posts

  • 0
Posted

Try this one:

Please login or register to see this code.

  • 0
Posted
        if os.time() - czas > 5 then --change to set time without movement after light will turn off

in milliseconds?

  • 0
Posted
        if os.time() - czas > 5 then --change to set time without movement after light will turn off

in milliseconds?

os.time returns a unix timestamp - so it will be in seconds.

  • 0
Posted
os.time returns a unix timestamp - so it will be in seconds.

Thank you!

  • 0
  • Inquirer
  • Posted
    Try this one:

    [/code]

    Thank you

    Do I start this scene with scnene activation on motion sensor? How can I configure that?

    Thank you

    Angelo

    • 0
    Posted

    donangelo, it is started by motion, as you wished. It is visible in header of file, just replace

    Please login or register to see this code.

    with id of your sensor.

    • 0
    Posted

    I have a separate scene to dim light at night.

    How may I include my code to this?

    Please login or register to see this code.

    • 0
  • Inquirer
  • Posted

    Thank you

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    [ Added: 2014-10-20, 22:02 ]

    Try this one:

    [/code]

    @j.nowacki, what if there are 2 or more sensors for one light and both sensors could activate the light when motion is detected, and both sensors have to be safe for xx seconds that the light turns off again?

    thank you

    Angelo

    • 0
    Posted
    Thank you

    Please login or register to see this image.

    /emoticons/default_icon_smile.gif" alt=":-)" />

    [ Added: 2014-10-20, 22:02 ]

    Try this one:

    [/code]

    @j.nowacki, what if there are 2 or more sensors for one light and both sensors could activate the light when motion is detected, and both sensors have to be safe for xx seconds that the light turns off again?

    thank you

    Angelo

    Do this:

    Please login or register to see this code.

    [/code]

    • 0
    Posted

    donangelo, code posted by Dalle1985 looks fine for this purpose.

    • 0
    Posted

    j.nowacki, how may I change dimming level at night?

    I have a separate scene and var for this, but I want this all to be in a one script. Thank you!

    • 0
    Posted

    You could try this scene:

    Please login or register to see this link.

    I am trying to build this in a plugin, but will take some time.

    • 0
    Posted

    stevenvd, Thank you!

    But just for my own experience and knowledge I would like to know how to make a simple codes...

    • 0
    Posted

    Instead of just turning light on:

    Please login or register to see this code.

    check if it is between given hours:

    Please login or register to see this code.

    and change dimming level basing on this.

    Nice way to start is to crate scene in blocks, then convert it into LUA and analyze the code.

    • 0
    Posted

    I added my Lux sensor but the scene is not triggerd when there is motion. When i run it manually it's working fine.

    I'm i doing something wrong?

    Please login or register to see this image.

    /emoticons/default_icon_curve.gif" alt=":-/" />

    Please login or register to see this code.

    • 0
    Posted

    You need to remove the comments from the properties ("-- Sensor ID" and "--Lux ID")

    • 0
    Posted

    I changed the value 5 to 180. But still the lights turns off despite movement in bathroom.

    Any idea?

    Please login or register to see this code.

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