LUA script 60 min ramp time

Discussion in 'C-Bus Automation Controllers' started by L Plater, Sep 23, 2021.

  1. L Plater

    L Plater

    Joined:
    Sep 2, 2019
    Messages:
    3
    Likes Received:
    0
    My apologies if this has been discussed before.

    Im new to lua and can not work out a script for the NAC to ramp lights over a period of an hour.

    I think it would need to be done in stages as the max cbus ramp time is 17mins. So would i need to say set a level every 20secs for the 17mins then repeat.

    If any one has a sample script it would be much appreciated.
     
    L Plater, Sep 23, 2021
    #1
  2. L Plater

    potato

    Joined:
    Jun 24, 2021
    Messages:
    2
    Likes Received:
    0
    Hi,

    It depends how you are going to trigger this, and if there will be multiple triggers the script will likely end up running concurrently with itself so you would either need to make sure its only triggered once or put in a handler to end the currently running script and then execute the new one.

    I quickly put the below together which should get you started anyway.
    Code:
    groupName = 'test' -- set group name
    startLevel = GetCBusLevel(0, 56, groupName) -- get starting level of lighting group, change application if required
    finalLevel = 0 -- level to ramp to 0 to 255, could be either up or down
    rampTime = 3600 -- ramp time in seconds
    levelChanges = math.abs(startLevel - finalLevel) -- number of level changes, we use math.abs to get the absolute value in case we are ramping up otherwise we would get a negative number.
    delayTime = rampTime / levelChanges --divide ramptime by number of level changes to get the delay between level changes
    
    --log(startLevel, finalLevel, rampTime, levelChanges, delayTime)
    
    
    for i = 1,levelChanges do
      SetCBusLevel(0, 56, groupName, math.abs(startLevel - i), 0)
      --log('ramping ' .. groupName .. ' to ' .. (startLevel - i))
      os.sleep(delayTime)
    end
     
    potato, Sep 27, 2021
    #2
  3. L Plater

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,524
    Likes Received:
    173
    Location:
    Adelaide, Australia
    Cbus doesn't have "ramp times", it has "ramp rates". This is the time it takes to go from fully off (0) to fully on (255), so setting a ramp rate of 17 minutes every 20 seconds won't give you a smooth progression (even though you probably wouldn't notice it)

    Cbus has 256 levels, so a ramp rate of 1 hour is a change of 1 in the ga every 3600/256=14 seconds. So all you need is a script that increments or decrements the current value every 14 seconds while you are ramping.

    But I would question the point of all this. Why do you need a 1 hour ramp rate anyway? What's it's purpose? A maximum ramp rate of 17 minutes didn't happen by accident.
     
    Ashley, Sep 28, 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.