LUA 'ifConditionStaysTrue' Equivalent

Discussion in 'C-Bus Automation Controllers' started by Blade, Aug 12, 2020.

  1. Blade

    Blade

    Joined:
    Aug 12, 2020
    Messages:
    6
    Likes Received:
    0
    Hi all,

    Wondering what the best way would be to achieve an equivalent ifConditionStaysTrue type statement in LUA script?

    For context the function / need for it is to monitor state change on a dummy group being used in a PE cell, and to only turn the relevant lighting group(s) on/off based on PE cell state IF the state has remained consistent for x seconds.

    Thanks!
     
    Blade, Aug 12, 2020
    #1
  2. Blade

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    You could create an event script on that group and when it is triggered compare the current time to the last time it was triggered. You would need to create a user object to store the time in.
     
    Ashley, Aug 13, 2020
    #2
    Blade likes this.
  3. Blade

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    how many x sec do you need to wait before checking and making the change?
     
    Pie Boy, Aug 13, 2020
    #3
  4. Blade

    Blade

    Joined:
    Aug 12, 2020
    Messages:
    6
    Likes Received:
    0
    Thanks Ashley.

    I'll have a play around with that method.

     
    Blade, Aug 13, 2020
    #4
  5. Blade

    Blade

    Joined:
    Aug 12, 2020
    Messages:
    6
    Likes Received:
    0
    Up to 60 seconds would probably be all it would need.
     
    Blade, Aug 13, 2020
    #5
  6. Blade

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    Potentially a scheduled script to run every min/ 60 to check the values could work,
    but it could also be out of sync depending on when the daylight cell changes and when the scheduled script runs/checks etc, this might get you started(run in a scheduled script ever 1 min with cron format */*/* etc )

    Code:
    Ga = grp.find('0/56/46') -- daylight cell ga
    
    on_time = os.time() - Ga.updatetime 
    log (on_time) -- this is the time in sec from the last activation of Ga
    
    if on_time >= 60 and Ga.value == 255 then --  time has past 60 sec and daylight cell ga is on/ level 255
     
      log('timer has past')
      -- do command   
    
    end 
    
     
    Pie Boy, Aug 14, 2020
    #6
    Blade likes this.
  7. Blade

    Blade

    Joined:
    Aug 12, 2020
    Messages:
    6
    Likes Received:
    0
    Thank you very much for the example, that helps a lot.
     
    Blade, Aug 14, 2020
    #7
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.