event.value() == 0 from ramping lighting ga

Discussion in 'C-Bus Automation Controllers' started by SgrAystar, Oct 12, 2023.

  1. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    Moving some logic from Homegate to SHAC I have simple event based script triggered on a lighting ga that looks like this
    Code:
    log(event.getvalue())
    if event.getvalue() == 255 then
      -- do something
      SetTriggerLevel('general', 'breakfast')
    elseif (event.getvalue() == 0) then
      -- do something else
    end
    The question arises because the trigger lighting group is also set to ON by the breakfast scene (I know ...)

    If the breakfast scene sets the level instantaneously there is no confusion, but if the scene ramps to ON over 4s the script is triggered a second time with get.value() == 0 ?

    Is this intended behaviour? Or something in the tips/tricks/gotchas?
     
    SgrAystar, Oct 12, 2023
    #1
  2. SgrAystar

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    I believe this is intended behavior, event.getvalue() works the same as ifHasChanged in piced.

    it grates me that in an event script some commands relating to dimming don't happen the same as they do in toolkit/cgate eg if you watch the application log for a ramp command usually you see the group set to 255 or 0 (depending if its ramping up or down) then when the desired level is reached another command for the same GA is sent with its actual level, this doesn't seem to translate to an event script.

    my understanding is that an event script runs every time an object is updated on the SHAC, irrespective of an objects current level/state, so if say an obj is at 100% / 255 and it gets set to 100% again the script will run

    another thought, have you looked at the script settings there is a box that can be selected called "execute while ramping" not sure if its set to off or on by default but something to test/ toggle and see if it makes any difference.
    but it would seem your event script runs while ramping etc.

    you may need to put in some extra checking like check to see if an obj associated is on or off or check ramp rate with GetCBusRampRate(0, 56, 1) before setting trigger level this would stop the script running the command again.

    if event.getvalue() == 255 then
    -- do something
    if GetLightingLevel('some object') ~= 255 then
    SetTriggerLevel('general', 'breakfast')
    end

    elseif (event.getvalue() == 0) then
    -- do something else
    end
     
    Pie Boy, Oct 12, 2023
    #2
  3. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    The issue here is the object is at 100% / 255 in order to set the trigger level for the scene, then gets set to 100% / 255 again by the scene but the event value == 0.

    No tick in the box for Execute during ramping.

    Easy enough for me to work around in this case by removing the ramp, but the behaviour doesn't feel right.
     
    SgrAystar, Oct 12, 2023
    #3
  4. SgrAystar

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    What firmware version are you running? Yeah on second thoughts doesn't seem right i was just testing on 5500NAC with 1.14.0 firmware, logging event it looks like the second command event.value() 0 is sent by a script,

    so you could filter with

    if event.sender ~= 'sc' then

    end

    have you got SHAC or AC2 controller? event.sender may vary between hardware AC2 and 5500NAC/SHAC firmwares
     
    Pie Boy, Oct 12, 2023
    #4
  5. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    Thanks.
    Using an AC2 v1.14.0, hw v1.1
     
    SgrAystar, Oct 12, 2023
    #5
  6. SgrAystar

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    249
    Likes Received:
    31
    Location:
    New Zealand
    looks like the sender 'sc' is scenes, so event script is being generated again by the scene being executed.

    that obj that has the event script tied to it must be in the scene with value 0 which is why it runs twice.l and event.getvalue is 0.
     
    Pie Boy, Oct 13, 2023
    #6
  7. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    new object lighting 'testobj'
    new scene testscene, one entry 'testobj' ->255(4s)
    new event-script testscript, trigger on testobj, with one line contents: log(event.dst, event.getvalue())

    set the value of testobj to 255, log shows:
    * arg: 1
    * string: 0/56/150
    * arg: 2
    * number: 255

    run the scene testscene, log shows
    * arg: 1
    * string: 0/56/150
    * arg: 2
    * number: 0
     
    SgrAystar, Oct 13, 2023
    #7
  8. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    It seems to be a bug related to AC2 scene handling.
    If I tick the box to include the light in object logs it shows the object data 00FF0004, so starting at zero even though the light is already on.
    For comparison initiating the same sequence from a PICED scene the object data correctly shows FFFF0004.
     
    SgrAystar, Oct 13, 2023
    #8
  9. SgrAystar

    Dasman

    Joined:
    May 5, 2011
    Messages:
    39
    Likes Received:
    5
    Location:
    Adelaide
    I believe this was an issue that shows up when a group is ramped to a target level that it is already at over a timeframe greater than 0 seconds.

    If it has not gone public yet, keep an eye out for firmware version 1.15 and see if this fixes the issue.
     
    Dasman, Oct 23, 2023
    #9
  10. SgrAystar

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    242
    Likes Received:
    35
    Location:
    Melbourne
    FWIW, I raised a case with Schneider back for 1.10.0 about event scripts always executing during ramp, regardless of the check box setting.

    1.6.0 worked perfectly, so for a while I was running two automation controllers. A secondary one on 1.6.0 for some event scripts, and the other on 1.13.0 for everything else. I ended up writing a work-around for my use case.


    Code:
    --[[
    Event-based, execute during ramping, name: "HUE final work-around"
    
    Pushes HUE final level events to resident script via socket.
    
    Tag required objects with the "HUE" keyword and this script will run whenever one of those objects reaches its target level.
    
    This script is a work-around version of 'HUE final' that avounds a bug introduced after firmware 1.6.0, where scripts always
    execute during ramping, regardless of the setting of "Execute during ramping" for the script. Report filed for 1.10.0, but
    the bug remains up to 1.14.0...
    
    But for the bug, these 30 lines should be just 11, which would be far easier to understand what's going on.
    --]]
    
    logging = false
    huePort = 5435
    hueServer = '127.0.0.1' -- Address of automation controller to send messages to
    
    val = event.getvalue()
    dest = event.dst
    parts = string.split(event.dst, '/')
    net = tonumber(parts[1]); app = tonumber(parts[2]); group = tonumber(parts[3])
    rate = GetCBusRampRate(net, app, group)
    target = GetCBusTargetLevel(net, app, group)
    
    if rate > 0 then
      final = false
      -- Ramp almost always begins with zero level (but very occasionally not)
      if val == 0 or not storage.get('ramping'..dest, false) then -- Initial?
        if not storage.get('ramping'..dest, false) then
          storage.set('ramping'..dest, true)
          if logging then log('Ramp detected for '..dest) end
        elseif val == 0 and val == target then
          final = true
        end
      else
        if val == target then
          final = true
        end
      end
      if final then
        storage.delete('ramping'..dest)
        server = require('socket').udp()
        if logging then log('Sending final level for '..event.dst..' of '..val) end
        server:sendto(dest..">"..val, hueServer, huePort)
      end
    end
     
    ssaunders, Oct 23, 2023
    #10
  11. SgrAystar

    Dasman

    Joined:
    May 5, 2011
    Messages:
    39
    Likes Received:
    5
    Location:
    Adelaide
    I believe you might also be interested in fw 1.15 then ;)
     
    Dasman, Oct 24, 2023
    #11
    ssaunders likes this.
  12. SgrAystar

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    242
    Likes Received:
    35
    Location:
    Melbourne
    1.15.0 for the win. Thanks for the heads-up @Dasman. You little ripper! 16 October 2023 firmware after much... much... waiting since 1.6.0. I upgraded and just celebrated with a stogie and a long poured gin, watching in awe as event scripts execute as they should during ramp. Well done Schneider. A toast to you!

    It's the little things in life that make one a most happy man. Sadly which shouldn't have been a consternation in the first place. But per my life motto, "It is what it is", I have put up with it. But if it is not then I am most glad that it is no longer!!!
     
    ssaunders, Oct 24, 2023
    #12
  13. SgrAystar

    SgrAystar

    Joined:
    Oct 4, 2018
    Messages:
    60
    Likes Received:
    5
    Location:
    Melbourne, Australia
    Thanks for the heads up @Dasman, 1.15.0 fixed the issue
     
    SgrAystar, Nov 2, 2023
    #13
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.