Scripting RGB strip lights off modbus measurement group

Discussion in 'C-Bus Automation Controllers' started by kojobomb, Mar 26, 2022.

  1. kojobomb

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    71
    Likes Received:
    6
    Location:
    Possum Brush
    This is the desired outcome, to be able to fade RGB strip lights from Green-Orange-Red (traffic lights) following a Modbus delivered LTO Battery State of Charge (SOC) 100%-0%.

    Battery SOC already configured into SHAC on a Measurement group address (Thanks to some help from members).

    First attempt I've managed to set up 3 individual scripts. (I know it could be done in a single script but I'm trying to learn)

    First script 100%-90% in Green all works perfectly

    if event.getvalue() > 89 then
    SetCBusState(0, 56, 18, true ) else SetCBusState(0, 56, 18, false) --GREEN Led--
    end

    Second script 90%-50% in orange (not complete) I can only get it to work in either direction from 50% up or 90% down.

    if event.getvalue() >50 and <90 then

    SetCBusState(0, 56, 20, true ) else SetCBusState(0, 56, 20, false)
    end

    Third script 50%-0% in Red all works perfectly

    if event.getvalue() < 50 then
    SetCBusState(0, 56, 19, true ) else SetCBusState(0, 56, 19, false) --RED Led--
    end

    I'm having trouble trying to find the right combination to get a outcome for above 50% but below 90% any help would be appreciated, Ive been watching many tutorials and reading.

    If I can get this to work in a static colour change I will down the track try again to turn it into a single script and ad in the fading from Green to Red so it is a continuous colour change
     
    kojobomb, Mar 26, 2022
    #1
  2. kojobomb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,522
    Likes Received:
    173
    Location:
    Adelaide, Australia
    What's driving the led strips? Three separate dimmer channels?
     
    Ashley, Mar 26, 2022
    #2
  3. kojobomb

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    71
    Likes Received:
    6
    Location:
    Possum Brush
    Yes 3 dmx channels on a 5500dmx
     
    kojobomb, Mar 26, 2022
    #3
  4. kojobomb

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    1,522
    Likes Received:
    173
    Location:
    Adelaide, Australia
    I assume this is typo as lua would give you an error here.

    What you want is: if (event.getvalue() >50) and event.getvalue()<90) then ...


    Anyway, it's not that hard to make it continuous.
    At 100% you want just green
    at 0% you want just red
    at 50% you want orange which is 100% red and 50% green.

    So green goes from 100% down to 0% as the level goes from 100% to 0%. i.e. they just follow one another.
    red has to go from 0% to 100% as the level goes from 100% to 50%, then stay at 100% as the level goes to 0%.
    (if you graph this it's easier to see).
    So we can do this with a bit of maths:
    red = min(100%, (100%-level) * 2)
    The 100%-level just makes it go in the opposite direction.
    The * 2 as it has to drop 100% over a 50% range. This will make it go from 0-200% though so we need to clamp it at 100%. That's what the min function does.

    As Cbus works in 0-255 range we end up with this event script:

    local value = event.getvalue()
    SetCBusLevel(0,56,18,value,0) -- green
    SetCBusLevel(0,56,19,math.min(255, (255-value)*2), 0) -- red
     
    Ashley, Mar 27, 2022
    #4
  5. kojobomb

    kojobomb

    Joined:
    May 27, 2019
    Messages:
    71
    Likes Received:
    6
    Location:
    Possum Brush
    Hi Ashley, it wasn't a typo, it was just me after hours of trying multiple combinations and never suceeding, I was fully aware it was wrong and giving me errors and complete frustration.
    Your time is extremely helpful, and I will slowly understand more or the correct methods in lua.
    I was aware of the need to fade through the 2 colours and the percentages, your explanation of fading is what I understood but it is more the implementation in lua.
    Thank you again, I will spend some hours again on it tonight and surely greatful.
    Ash
     
    kojobomb, Mar 27, 2022
    #5
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.