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

LUA Basics....


Guest Lode

Question

Guest Lode

HI,

I have a slidegate with a universal sensor and an FGS-211 attached to it

When the gate is open at 23h it has to close automatically.

I made this simple scene with graphic blocks.

Here is the lua code from these blocks, nothing manually changed.

What i don't understand is the second block after "else"....

Why is that, and why does it only mention the days i selected and not the hour ?

What happens now.

When somebody tries to open the gate at a random time the block after "else" is triggered.

So the gate closes.....

Please login or register to see this code.

Link to comment
Share on other sites

9 answers to this question

Recommended Posts

  • 0

This but a better solution is not to loop every 1 min checking for a single time... see later post

Please login or register to see this code.

Link to comment
Share on other sites

  • 0
Guest Lode
  • Inquirer
  • Robmac,

    No it just has to close at 23 h. when the sensor is breached.

    That's it

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0

    that should do it just get rid of the commented lines you do not need and put the loop in or call it from the LUA scheduler at 23:00 in which case it could just be

    Please login or register to see this code.

    This i what I do for my garage doors if they are open at 22:00.

    Link to comment
    Share on other sites

    • 0
    Guest Lode
  • Inquirer
  • that should do it just get rid of the commented lines you do not need and put the loop in or call it from the LUA scheduler at 23:00 in which case it could just be

    Please login or register to see this code.

    This i what I do for my garage doors if they are open at 22:00.

    Robmac,

    Thx...

    I do understand the code but i don't know what you mean by LUA scheduler and as you said in your previous post i don't want to loop every minute for a single time

    Please login or register to see this image.

    /emoticons/default_icon_wink.gif" alt=";-)" />

    Link to comment
    Share on other sites

    • 0

    Please login or register to see this link.

    is a scene I wrote as I had lots of LUA loops in scenes running timed events.

    If you download it all you need to do is add a line where to run a scene containing the close code

    Just spotted an error in my original post

    #

    #

    Please login or register to see this code.

    Link to comment
    Share on other sites

    • 0
    Guest Lode
  • Inquirer
  • Nice......i found it, i will test it this evening....

    Thx again

    Please login or register to see this image.

    /emoticons/default_icon_biggrin.gif" alt=":-D" />

    Link to comment
    Share on other sites

    • 0
    Guest dsilletti
  • Inquirer
  • Hi all, just a simple question, without loop (while true do), scenes like this are working with no problem (this scene turn off bathrooms fans after 5 mins from the switch off of the light):

    --[[

    %% autostart

    %% properties

    27 value

    25 value

    18 value

    16 value

    %% globals

    --]]

    if (fibaro:countScenes() > 1) then fibaro:abort() end;

    if ( tonumber(fibaro:getValue(27, "value")) > 0 and tonumber(fibaro:getValue(25, "value")) == 0 )

    then

    fibaro:sleep(5*60*1000);

    fibaro:call(27, "turnOff");

    fibaro:debug("Aspiratore Bagno Dom OFF");

    end

    if ( tonumber(fibaro:getValue(18, "value")) > 0 and tonumber(fibaro:getValue(16, "value")) == 0 )

    then

    fibaro:sleep(5*60*1000);

    fibaro:call(18, "turnOff");

    fibaro:debug("Aspiratore Bagno Tony OFF");

    end

    What does it mean, that anyway there is a loop to check the condition of devices?

    If yes, how often the default loop runs?

    I need to know because I'd like to optimize all my scenes to avoid too many loops.

    regards

    Domenico

    Link to comment
    Share on other sites

    • 0

    if you want to react to a change in a property or a variable what you have is fine and the best way.

    If you want something to happen at a particular time every day or on some days then you will need a loop that checks if that time is now. The default code is to loop and check for that time every minute by putting a minute sleep in the loop.

    So it depends what you want.

    If you want to turn something on/off when something else changes you can do as you have done.

    If you want to turn on your radio at 8:15 every morning, then you will need to have code running that checks for that time on a regular basis. Thus the loop that runs while true, the sleep and the autostart.

    Hope that makes sense,

    [ Added: 2013-08-08, 16:10 ]

    I think you have a bug though.

    If you turn 27 on then two minute later 25. 25 will be turned off after 3 mins not 5.

    As your code only allows one instance, when 25 is switched code will still be running for 27 so will exit as only one instance allowed (if (fibaro:countScenes() > 1) then fibaro:abort() end; ).

    Link to comment
    Share on other sites

    • 0
    Guest dsilletti
  • Inquirer
  • if you want to react to a change in a property or a variable what you have is fine and the best way.

    If you want something to happen at a particular time every day or on some days then you will need a loop that checks if that time is now. The default code is to loop and check for that time every minute by putting a minute sleep in the loop.

    So it depends what you want.

    If you want to turn something on/off when something else changes you can do as you have done.

    If you want to turn on your radio at 8:15 every morning, then you will need to have code running that checks for that time on a regular basis. Thus the loop that runs while true, the sleep and the autostart.

    Hope that makes sense,

    [ Added: 2013-08-08, 16:10 ]

    I think you have a bug though.

    If you turn 27 on then two minute later 25. 25 will be turned off after 3 mins not 5.

    As your code only allows one instance, when 25 is switched code will still be running for 27 so will exit as only one instance allowed (if (fibaro:countScenes() > 1) then fibaro:abort() end; ).

    Hi robmac, thank you for your answer, now I understand the difference.

    Regarding my scene, 27 is fan, 25 is light.

    If I turn on light and fan, and then I turn off only the light (25), the timer start, I didn't count the time but seems ok, probably according to the single instance, this scene will not work for the second bathroom in the same time, I will check.

    Of course If I turn on fan before light, the timer will start from that moment, anyway I need sometimes to turn on only fan and go away, so this scene has double usage...

    Please login or register to see this code.

    regards

    Domenico

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