Logic control in 12 way relays

Discussion in 'C-Bus Wired Hardware' started by max w, Feb 20, 2019.

  1. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Im Looking for a way of controlling a relay to come on if any of the other 11 relays are on.

    example
    relays 1 -11 are under floor heating valves and relay 12 is the boiler on.?


    is this possible in the relay logic or do I need to write some script?

    Thanks for any advice in advance

    Max W
     
    max w, Feb 20, 2019
    #1
    1. Advertisements

  2. max w

    Jake N

    Joined:
    Oct 9, 2018
    Messages:
    4
    Likes Received:
    0
    Yeah im pretty sure all you need to do is go to the 'logic' tab and select the 'boiler' group in the selection box then tick all of the 'OR' statement buttons for the 11 other channels? You would just need a way to turn the boiler off again... I could be wrong though im sure somebody will comment/confirm?
     
    Jake N, Feb 22, 2019
    #2
    1. Advertisements

  3. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    Doing that will get one channel to control 11 channels. It needs to be the other way around. i.e. 11 channels controlling one channel. With logic you can only set up 4 channels to control one channel.

    You will need a logic device for this.
     
    Ashley, Feb 22, 2019
    #3
  4. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Thanks Both, I had tried the logic in the relay rack and the relays reacted as Ashley advised. I have a Shac unit and have been trying the Getcbus state and set lighting level, Im new to scripting and if anyone could give me an example to help me that would be great.

    Thanks in advance for any help!

    Max W
     
    max w, Feb 25, 2019
    #4
  5. max w

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    175
    Likes Received:
    49
    Location:
    Sydney, NSW, Australia
    I think this will work, Im still learning Lua/Shac so there may be better coding

    1) In objects for each vale group add the keyword boiler

    2) In scripting under/ Event-based add new script, Call it Boiler
    In Group address / Keyword select Boiler
    Tick Activate
    Then save

    3) Click Edit
    Then add the following :

    value = event.getvalue()


    if value == 255 then


    -- Change x to your boiler group

    SetCBusState(0, 56, x, true)

    End


    if value == 0 then

    value = 0

    -- Change x to the number of valve groups eg 11

    for valveno= 1,x, 1 do

    value = value + GetCBusByKW('Boiler')[valveno].data.target

    end

    if value == 0 then

    -- Change x to your boiler group

    SetCBusState(0, 56, x, false)

    log("got here")

    end
    end
     
    lcrowhurst, Feb 27, 2019
    #5
  6. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Hi Lawrence, thanks for the code its works better than mine! just one slight problem, Im hoping you can help me to resolve, the on function for the boiler works fine. But with all of the relay (valves are off) the boiler on relay
    (relay 12 ) repeatable toggles from on to off. I see the following "got here" coming in on the log file even though all of the relays-GA are off. Would you have any Ideas of where I have gone wrong? Thanks for all your help!

    Max W
     
    max w, Mar 4, 2019
    #6
  7. max w

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    175
    Likes Received:
    49
    Location:
    Sydney, NSW, Australia
    can you send a screen shot of your group objects, and your code
     
    lcrowhurst, Mar 5, 2019
    #7
  8. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Hi Lawrence thanks for your reply, please find attached the screen shots. Thanks for your Help! Screenshot (19).png Screenshot (20).png Screenshot (21).png Screenshot (22).png Screenshot (23).png Screenshot (19).png
     
    max w, Mar 5, 2019
    #8
  9. max w

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    175
    Likes Received:
    49
    Location:
    Sydney, NSW, Australia
    Remove boiler tag from pump relay
     
    lcrowhurst, Mar 5, 2019
    #9
  10. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Laurence, I feel silly now! thanks for your help works like a dream.

    :)
     
    max w, Mar 6, 2019
    #10
  11. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    Aren't we all :) All our years of Pascal Logic Engine experience chucked in the bin by Schneider :(

    Anyway, a couple of (hopefully useful) comments.

    GetCBusByKW returns a table with lots of information about the objects matching the keyword. This take a lot of building. You are calling it inside the loop, so for every iteration you are creating the table, extracting one object, then throwing the table out only to re-create next loop. Move this statement outside of the loop.

    Also, once you have the table outside the loop you can get its length to set up the loop count (just use the table name prefixed with a #). This means the loop count will automatically change if you add or remove keywords which is much safer

    Finally, once you find one group that is ON inside the loop, you don't need to continue the loop

    This gives us the following code:

    value = event.getvalue()

    if value == 255 then

    -- Change x to your boiler group

    SetCBusState(0, 56, x, true)

    end

    if value == 0 then

    -- value = 0 -- don't need this as can only get here if value is already 0

    boilers = GetCBusByKW('Boiler') -- Get table once outside of loop

    for valveno= 1,#boilers, 1 do -- #boilers gives us the length of the table

    value = boilers[valveno].data.target

    if value ~= 0 then -- Don't need to continue once we find one on
    break -- this exits from the loop
    end

    end

    if value == 0 then

    -- Change x to your boiler group

    SetCBusState(0, 56, x, false)

    log("got here")

    end
    end


    While iterating though a table with integer keys is fine since Lua V5, Lua provides a standard way of iterating though tables with any type of key by using the pairs function as follows:

    for key, value in pairs(boilers) do
    -- code
    end

    For each iteration this returns the key (index in this case) and value (group object in this case).
    In our case we don't care about the key, so by convention we would just use a single underscore (_) which is a valid variable name but just tells us we don't care about it.

    So the second part of the code now becomes

    if value == 0 then

    boilers = GetCBusByKW('Boiler') -- Get table once outside of loop

    for _, group in boilers do

    value = group.data.target

    if value ~= 0 then -- Don't need to continue once we find one on
    break -- this exits from the loop
    end

    end

    if value == 0 then

    -- Change x to your boiler group

    SetCBusState(0, 56, x, false)

    log("got here")

    end
    end
     
    Ashley, Mar 7, 2019
    #11
    lcrowhurst likes this.
  12. max w

    lcrowhurst

    Joined:
    Dec 2, 2004
    Messages:
    175
    Likes Received:
    49
    Location:
    Sydney, NSW, Australia
    Thats even better :)

    where do we find out things like full details of GetCBusByKW
     
    lcrowhurst, Mar 7, 2019
    #12
    max w likes this.
  13. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    The help in the right hand column of the script edit window tells you everything you need to know about the tables returned by getCbusByKW.

    The Lua 5.1 reference manual is also a fun read (The SHAC is currently only Lua 5.1). It's available here:

    https://www.lua.org/manual/5.1/
     
    Ashley, Mar 7, 2019
    #13
    max w likes this.
  14. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Thanks both for all of your help! :)
     
    max w, Mar 7, 2019
    #14
  15. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Hi I have just load the script into my shac to test it and had a few errors.one was on line 10 so I added the = is this correct and the other is as the screen shot. Any idea's where I'm going wrong.

    Screenshot (26).png

    Thanks Max;)
     
    max w, Mar 19, 2019
    #15
  16. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    You have copied the code incorrectly.

    The for loop is:

    for _,group

    Note the space after the for, and the comma between the underscore and group. You have created a variable called
    for_group rather than a loop statement then turned it into an assignment statement with the =

    Cut and paste the code
     
    Ashley, Mar 19, 2019
    #16
    max w likes this.
  17. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Thanks Ashley for your help. I have now put the following code in .......... my boiler relay pulses on and off when any valve with the keyword "boiler is on" - where am I going wrong? Thanks for all of your help.

    Screenshot (28).png
     
    max w, Mar 22, 2019
    #17
  18. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    You have put both versions of the code in that turns the boiler off. Delete lines 6 to 20.

    Rather than paste screen shots it is much better to insert the actual code. Then we can copy it and show you what is wrong.

    Also you need to format your code so it is readable. Indent each IF statement in by a tab so you can see the hierarchy.
     
    Ashley, Mar 22, 2019
    #18
  19. max w

    max w

    Joined:
    Sep 14, 2017
    Messages:
    21
    Likes Received:
    2
    Location:
    GB
    Ashley, If I delete lines 6 -20 I'm missing part of the table and get a error ? Sorry for the constant questions - Im a LUA newbie!

    value = event.getvalue()

    if value == 255 then
    SetCBusState(0, 56, 12, true)
    end



    if value == 0 then
    boilers = GetCBusByKW('Boiler')
    for _, group in boilers do
    value = group.data.target

    if value ~= 0 then
    end
    end



    if value == 0 then

    SetCBusState(0, 56, 12, false)
    log("got here")

    end
    end
     
    max w, Mar 23, 2019
    #19
  20. max w

    Ashley

    Joined:
    Dec 1, 2005
    Messages:
    974
    Likes Received:
    73
    Location:
    Adelaide, Australia
    You left the break statement out. This is the whole thing:

    Code:
    value = event.getvalue()
    if value == 255 then
        SetCBusState(0, 56, 12, true)
    end
    
    if value == 0 then
        boilers = GetCBusByKW('Boiler') -- Get table once outside of loop
        for _, group in boilers do
             value = group.data.target
             if value ~= 0 then -- Don't need to continue once we find one on
                 break -- this exits from the loop
             end
        end
        if value == 0 then
            SetCBusState(0, 56, 12, false) 
            log("got here")
        end
    end
    
     
    Ashley, Mar 23, 2019
    #20
    1. Advertisements

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.