ConditionStaysTrue

Discussion in 'C-Bus Automation Controllers' started by carlg, Aug 12, 2022.

  1. carlg

    carlg

    Joined:
    Jan 29, 2009
    Messages:
    43
    Likes Received:
    0
    Hi all, just seeing if anyone knows if ConditionStaysTrue function that was available in PICED works with NAC & SHACs
     
    carlg, Aug 12, 2022
    #1
    1. Advertisements

  2. carlg

    Pie Boy

    Joined:
    Nov 21, 2012
    Messages:
    218
    Likes Received:
    29
    Location:
    New Zealand
    Shac works totally differently to piced,
    What are you intending to achieve in shac?
    In Shac we have event scripts, same as ifHasChanged in piced
    Or resident scripts which run every x sec.
     
    Pie Boy, Aug 13, 2022
    #2
    1. Advertisements

  3. carlg

    carlg

    Joined:
    Jan 29, 2009
    Messages:
    43
    Likes Received:
    0
    Wanting to put a button on Vis page, that the user needs to press for lets say 2 seconds before the event is executed. Like a Building "ALL OFF" don't want the lights to go off if the user accidently press to ALL OFF button.
     
    carlg, Aug 13, 2022
    #3
  4. carlg

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    137
    Likes Received:
    13
    Location:
    Melbourne
    Create a lighting group called 'Trigger all off', then an event-based script for that group:
    Code:
    logging = true
    
    val = event.getvalue()
    
    if val == 255 then
      if logging then log('Start delay') end
      storage.set('All off triggered', socket.gettime())
    else
      last = storage.get('All off triggered')
      if last ~= nil then
        if socket.gettime() - last > 2 then
          if logging then log('Trigger scene all off') end
          SetTriggerLevel('Entry / Egress', 'All Off')
        end
      end
      storage.set('All off triggered', nil)
    end
    In my network I have a trigger control group called "Entry / Egress", and it has a level of "All Off". The all off scene is set to fire on this action selector.

    Create a bell-press in visualisation for the "Trigger all off" group.
     
    ssaunders, Aug 14, 2022
    #4
  5. carlg

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    137
    Likes Received:
    13
    Location:
    Melbourne
    I guess you could also use an integer User Parameter instead of a lighting group if you didn't want to pollute lighting with lighting-support stuff like this. Haven't tried that though.
     
    ssaunders, Aug 14, 2022
    #5
  6. carlg

    ssaunders

    Joined:
    Dec 17, 2008
    Messages:
    137
    Likes Received:
    13
    Location:
    Melbourne
    (And thanks for this idea. I'm reconfiguring all of my "All off" buttons to function this way... Visualisations, DLTs by using a lighting group. The number of times I have accidentally hit a key, then yelled out "Sorry!" to a household in darkness don't bear counting.)

    Here's how I'm doing it:
    1. Create a lighting group (e.g. 0/56/250 All Off Trigger)
    2. Add keywords to that group (e.g. Delayed Trigger, trigger=Entry / Egress, selector=All Off, delay=2)
    3. Create an event-based script called 'Delayed trigger', and set it to fire on the keyword "Delayed Trigger"

    This allows multiple configurable delayed triggered scenes using bell-press. I have "All Off", "Inside Off", "Outside Off" and more.

    The script:

    Code:
    logging = true
    
    function trim(s) return s:match "^%s*(.-)%s*$" end -- Remove leading and trailing spaces
    
    val = event.getvalue()
    
    if val == 255 then
      if logging then log('Start delay for delayed trigger '..event.dst) end
      storage.set('Delay triggered '..event.dst, socket.gettime())
    else
      last = storage.get('Delay triggered '..event.dst)
      if last ~= nil then
        local trigger = ''
        local selector = ''
        local delay = 2
        tags = grp.gettags(event.dst)
        for _, t in ipairs(tags) do
          tp = string.split(t, '=')
          tp[1] = trim(tp[1])
          if tp[2] then
            tp[2] = trim(tp[2])
            if tp[1] == 'trigger' then trigger = tp[2]
            elseif tp[1] == 'selector' then selector = tp[2]
            elseif tp[1] == 'delay' then delay = tonumber(tp[2])
            end
          end
        end
        if trigger == '' or selector == '' then
          log('Error: Delayed trigger group does not have a trigger and/or selector')
          do return end
        end
    
        if socket.gettime() - last > delay then
          if logging then log('Delayed triggering '..trigger..', '..selector) end
          SetTriggerLevel(trigger, selector)
        else
          if logging then log('NOT triggering '..trigger..', '..selector..' - press not long enough') end
        end
      end
      storage.set('Delay triggered '..event.dst, nil)
    end
     
    Last edited: Aug 15, 2022
    ssaunders, Aug 15, 2022
    #6
    Timbo likes this.
  7. carlg

    carlg

    Joined:
    Jan 29, 2009
    Messages:
    43
    Likes Received:
    0
    Thanks for the coding. Will have a look later to incorporate in the homes SHAC
     
    carlg, Aug 15, 2022
    #7
    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.
Similar Threads
There are no similar threads yet.
Loading...