Logic Machine Forum
Fb editor - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Fb editor (/showthread.php?tid=3307)



Fb editor - Tokatubs - 20.04.2021

I have 2 Group adresses, one with an pir detector connected to it. 
I want the second GA to also go high when first is connected. 
But when first GA goes off, the second should have have an delay on the output for extra time. 

I did this via the FB Editor, and seems to work. But i was really wondering how this could be written more easily in normal event script?

Code:
require('custom.fbeditor20.Time')

functions_Time_json_fbe_switch_delay_input_1 = grp.find(event.dst)
functions_Time_json_fbe_switch_delay_input_2 = 0
functions_Time_json_fbe_switch_delay_input_3 = 10
out, out_not = fbe_switch_delay(functions_Time_json_fbe_switch_delay_input_1, functions_Time_json_fbe_switch_delay_input_2, functions_Time_json_fbe_switch_delay_input_3, 'fb__New_diagram__fbe_switch_delay__id')
if out ~= nil then
    grp.checkwrite('17/1/0', out, 1)
end



RE: Fb editor - Daniel - 20.04.2021

You can use this script without FB only change the output grp and make sure this 'fb__New_diagram__fbe_switch_delay__id' is a unique value as this is used as storage ID. 
The function itself looks like this:
Code:
function fbe_switch_delay(input, delayOn, delayOff, blockID)
  -- Create callID
  math.randomseed(os.time())
    math.random()
    math.random()
    local callID = ""
    for i=1,16 do
      callID = callID .. string.format("%x", math.random(0, 0xf))
    end
  -- Store callID
  storage.set(blockID .. "_callID", callID)
  -- Wait
  if input.value and input.value ~= 0 then
    sleep(delayOn)
  else
    sleep(delayOff)
  end
  -- If a telegram arrives during an ongoing delay, then only the last telegram is output delayed. Ongoing delays are cancelled!
  if callID == storage.get(blockID .. "_callID") then
    return input.value, not input.value
  else
    return nil, nil
  end
end