Help with LUA script to run during a specific time period each day

Discussion in 'C-Bus Automation Controllers' started by Lliam, Nov 20, 2021.

  1. Lliam

    Lliam

    Joined:
    Nov 15, 2015
    Messages:
    28
    Likes Received:
    2
    Location:
    Adelaide
    Hi All

    I have a basic script that monitors a GA and every time that group address level goes to 0 it will then ramp it back to 100.
    example script below:

    test = GetCBusLevel(0, 56, 43)
    if (test == 0)
    then
    SetCBusLevel(0, 56, 43, 255, 0)
    end


    The issue I have is only want this script to activate during a specific time period every day (eg Business hours between 8:30am and 5:30pm).

    I have done similar to this before on the C-touch logic just using something like:
    and
    (time <= "5:30:00 PM") and
    (time >= "8:30:00 AM")
    then

    But this doesn't seem to work with LUA (or I am scripting it incorrectly). I think I need to use the os.time function somehow but i am stuck as to how.
    Any help would be appreciated.

    Thanks
     
    Lliam, Nov 20, 2021
    #1
  2. Lliam

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    have a look at
    https://www.lua.org/pil/22.1.html
    -- os.date returns table of hour min sec etc
    Something like this may be what you are looking for.

    t = os.date(“*t”)
    log(t)
    —I’m not sure how the below will behave without testing… might need to change the first “and” to an “or”.
    but it gives you the idea on how it can be achieved.

    if ( t.hour >= 20 ) and ( t.hour <= 5 ) then

    If t.min >= 30 then
    — do stuff here
    end

    end
     
    Last edited: Nov 20, 2021
    Pie Boy, Nov 20, 2021
    #2
  3. Lliam

    Lliam

    Joined:
    Nov 15, 2015
    Messages:
    28
    Likes Received:
    2
    Location:
    Adelaide
    Hi Pie Boy

    Thanks for your reply, i was just about to give it a go then a bolt of lightning hit me and i realised there is a simpler and more suitable (for me) way of doing it.

    I just created another GA that is turned on or off by the business hours schedule.

    I then just put an IF-THEN statement that controls the GA of the lights I want to ramp to 255 every time they drop to 0 within the IF statement that is monitors the state of the GA controlled by the schedule.

    Seems to work 100% how I want and means the schedule times can be easily adjusted by the client of needed.

    Code below if anyone is interested (setup to control 2 different GA's)

    test = GetCBusLevel(0, 56, 43)
    test2 = GetCBusLevel(0, 56, 45)
    schedule = GetCBusState(0, 56, 44)

    if (schedule == true) then

    if (test == 0)
    then
    SetCBusLevel(0, 56, 43, 255, 0)
    end

    if (test2 == 0)
    then
    SetCBusLevel(0, 56, 45, 255, 0)
    end
    end

    Cheers
    Lliam
     
    Lliam, Nov 21, 2021
    #3
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.