Control of GA from two other GAs

Discussion in 'C-Bus Automation Controllers' started by CB user, Jul 18, 2019.

  1. CB user

    CB user

    Joined:
    Jul 18, 2019
    Messages:
    3
    Likes Received:
    0
    Hi all,

    I am new to Lua, so please don't shoot me down for my basic questions. I have searched the forum for a solution but can't find anything to explain why this doesn't work.

    I am trying to achieve control over a single GA (Fan) from two other Gas (Trigger 1 and Trigger 2), whereby I do not want Trigger 2 to have any effect while the Fan was triggered by Trigger 1.

    In Pascal all that is needed is the following:

    once (GetLightingState("Trigger 1") = ON) then
    begin
    PulseCBusLevel("Local", "Lighting", "Fan", 100%, 0, "0:00:20", 0%);
    PulseCBusLevel("Local", "Lighting", "Flag", 100%, 0, "0:00:10", 0%);
    end;

    once (GetLightingState("Trigger 2") = ON) and
    (GetLightingState("Flag") = OFF) then
    begin
    PulseCBusLevel("Local", "Lighting", "Fan", 100%, 0, "0:00:05", 0%);
    end;


    In Lua I cannot make this happen. I have created two separate Event Based Scripts as below:

    Script 1:

    if (GetCBusLevel(0, 56, 97) ==255) then ---Trigger 1
    PulseCBusLevel(0, 56, 142, 255, 0, 30, 0) -- fan
    PulseCBusLevel(0, 56, 210, 255, 0, 30, 0) -- set Flag
    end

    Script 2:

    if (GetCBusLevel(0, 56, 141) ==255) and -- Trigger 2
    (GetCBusLevel(0, 56, 210) ==0) then -- Flag
    PulseCBusLevel(0, 56, 142, 255, 0, 30, 0) -- fan
    end


    Besides the fact that on NAC the “Fan” does not even change status when triggered is the first oddity.

    On my test set-up (NAC, DIN Dimmer, eDLT) I see the Fan status change on the eDLT as it should, all the while it does not on the NAC while running the Lua script.

    Running the Pascal script on a PAC, each status shows correctly on NAC.


    With the Lua script (PAC disconnected) the following unwanted behaviour takes place:

    If I pulse Trigger 2 while Trigger 1 has started the Fan, then the Fan stops immediately, and that is that for the routine.

    Additionally, I would expect that while Trigger 1 has started the Fan, I can extend the run-time of the Fan by re-triggering Trigger 1 before the Pulse timer has expired.

    This works with the Pascal (PAC) code, but not with Lua.

    I would appreciate if if someone could point me in the right direction to achieve this in Lua, as I must be missing something big time.
     
    CB user, Jul 18, 2019
    #1
  2. CB user

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    Hi

    I had a similar issue with the PulseCBusLevel()

    From my experience when a group is pulsed by a unit there is no status on the SHAC/NAC it just dosn't change the Ga object to follow the Pulse command. so if you are calling the GetCbusLevel() it wont have changed in the SHAC/NAC if it has been pulsed by PulseCBusLevel().

    run up toolkit log at the same time and see...
    when the PulseCBusLevel() command is sent (from the SHAC/NAC) the Ga Changes state/level (in the toolkit log to, eg Group Ramped to 255(100% over 0 seconds) ) as expected

    But if you look at the object log for that GA in the SHAC/NAC (once you have sent the pulse command ) it dose not change state/level with a (Group Ramped to 255(100% over 0 seconds) ) command as you would expect.

    it dose however receive the off command though.

    i wonder if this function might work for you? instead of checking the state/level of the GA that has been pulsed.
    -- Get target level of application 56 group 1 on the local network
    value = GetCBusTargetLevel(0, 56, 1)
    i expect this would return the value of the ramped to command for the GA

    or do the timing another way and set the GA to on/off/level
     
    Pie Boy, Jul 19, 2019
    #2
    CB user likes this.
  3. CB user

    CB user

    Joined:
    Jul 18, 2019
    Messages:
    3
    Likes Received:
    0
    Thank you for your reply.

    I have tried different timing by using OS sleep, but that also does not solve the problem.

    The status display on NAC is not even the biggest issue for me at the moment. The fact that when triggering from the second trigger it actually switches off the Fan instead of restarting the new timer is a real problem.

    I thought that these new controllers are a replacement for the old ones, but it looks as though they do not really function well.
    I'll continue to try and get this working, but actually expected that I made a simple mistake which would be an easy fix.
    This starts to look like there are numerous bugs with the product.
     
    CB user, Jul 19, 2019
    #3
  4. CB user

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    248
    Likes Received:
    31
    Location:
    New Zealand
    CB user, 3
    Dont think of the NAC/SHAC as a native C-bus device but as a device that talks to C-bus.

    Stick this in a resident script with 0 delay and test, it might not be exactly correct for your functionality and might not be the most efficient code... but i think it will work.


    local trg_1 = GetLightingState(97)
    local trg_2 = GetLightingState(141)
    local flag

    -- trigger 1
    if (trg_1) and (flag == nil or 0) then
    SetLightingState(142, true) -- turn fan on
    storage.set('Timer_1', os.time()) -- store time at activation
    log('trigger 1 activated')
    flag = 1
    end

    -- trigger 2
    if (trg_2) and (flag ~= 1) then
    SetLightingState(142, true) -- turn fan on
    storage.set('Timer_1', os.time())
    log('trigger 2 activated')
    flag = 0
    end

    -- timer has expired
    if os.time() - storage.get('Timer_1') >= storage.get('Timer_1') + 30 then -- time in sec for 30 min use 60*30
    SetLightingState(142, false)
    flag = 0
    end
     
    Pie Boy, Jul 21, 2019
    #4
    CB user likes this.
  5. CB user

    CB user

    Joined:
    Jul 18, 2019
    Messages:
    3
    Likes Received:
    0
    Thank you Pie Boy,

    Sorry for the delay, I'm not always on the forum.
    I'll try this and let you know how it goes :)
     
    CB user, Jul 25, 2019
    #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.