This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Timer for multiple toilet's vents
#1
Hi, I need help with 60 vents control in administration building.

One off vent 6/1/0 need to be controlled with lights 3/0/7,3/0/9, 3/0/11 or 3/0/13. When one of this lights is switched ON more then 5 minutes, or all off lights are turned to OFF, then I need to switch vent ON for time that can be set over group adress 11/4/1 in seconds.

Thaks for help
Reply
#2
This can be done with 2 resident scripts:

1. OR gate for light groups: https://kb.logicmachine.net/scripting/lo...-statuses/

2. Modified staircase timer that uses status from the OR gate: https://kb.logicmachine.net/scripting/staircase-timer/

We can help with the modifications but you need describe the vent logic in more detail:
  • Is the timer setting global for all vents or adjustable for each vent separately?
  • What should happen if the light switches on while the vent is already running? Should the timer continue running or stop?
  • What should happen if the light switches off while the vent is already running? Should the timer continue running as is or should it reset to the starting value?
Reply
#3
(14.10.2024, 06:55)admin Wrote: This can be done with 2 resident scripts:

1. OR gate for light groups: https://kb.logicmachine.net/scripting/lo...-statuses/

2. Modified staircase timer that uses status from the OR gate: https://kb.logicmachine.net/scripting/staircase-timer/

We can help with the modifications but you need describe the vent logic in more detail:
  • Is the timer setting global for all vents or adjustable for each vent separately?
  • What should happen if the light switches on while the vent is already running? Should the timer continue running or stop?
  • What should happen if the light switches off while the vent is already running? Should the timer continue running as is or should it reset to the starting value?

Hi,

thaks for your answer. I look for scripts, but I need help with edit this script.

Time is same for all vents.
In both of case we want to retrigger running time and then switch off.
Reply
#4
Timer script:
Code:
if not client then
  -- input to output mapping
  mapping = {
    ['0/0/1'] = '0/0/6',
    ['0/1/1'] = '0/1/6',
    ['0/2/1'] = '0/2/6',
  }

  -- turn output on when input is on for X seconds
  ondelay = 5 * 60
  -- keep output on for X seconds
  offdelayaddress = '11/4/1'

  timers = {}
  for input, output in pairs(mapping) do
    timers[ input ] = {
      output = output,
      state = 'off',
    }
  end

  function timerset(timer, input)
    if input then
      if timer.state ~= 'ondelay' then
        timer.state = 'ondelay'
        timer.ticks = ondelay
      end
    else
      grp.checkwrite(timer.output, true)
      timer.state = 'offdelay'
      timer.ticks = grp.getvalue(offdelayaddress)
    end
  end

  function timertimeout(timer)
    if timer.state == 'ondelay' then
      timerset(timer, false)
    else
      grp.checkwrite(timer.output, false)
      timer.state = 'off'
      timer.ticks = nil
    end
  end

  grp.sender = 'tm'

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    local timer = timers[ event.dst ]
    if timer and event.sender ~= grp.sender then
      local value = tonumber(event.datahex, 16) or 0
      timerset(timer, value ~= 0)
    end
  end)
end

client:loop(1)

for _, timer in pairs(timers) do
  if timer.ticks then
    timer.ticks = timer.ticks - 1

    if timer.ticks == 0 then
      timertimeout(timer)
    end
  end
end
Reply
#5
Code:
if not client then
  -- input to output mapping
  mapping = {
    ['0/1/1'] = '0/1/2',
  }

  -- turn output on when input is on for X seconds
  ondelay = 5 * 60
  -- keep output on for X seconds
  offdelayaddress = '0/1/4'

  timers = {}
  for input, output in pairs(mapping) do
    timers[ input ] = {
      output = output,
      state = 'off',
    }
  end

  function timerset(timer, input)
    if input then
      if timer.state ~= 'ondelay' then
        timer.state = 'ondelay'
        timer.ticks = ondelay
      end
    else
      grp.checkwrite(timer.output, true)
      timer.state = 'offdelay'
      timer.ticks = grp.getvalue(offdelayaddress)
    end
  end

  function timertimeout(timer)
    if timer.state == 'ondelay' then
      timerset(timer, false)
    else
      grp.checkwrite(timer.output, false)
      timer.state = 'off'
      timer.ticks = nil
    end
  end

  grp.sender = 'tm'

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    local timer = timers[ event.dst ]
    if timer and event.sender ~= grp.sender then
      local value = tonumber(event.datahex, 16) or 0
      timerset(timer, value ~= 0)
    end
  end)
end

client:loop(1)

for _, timer in pairs(timers) do
  if timer.ticks then
    timer.ticks = timer.ticks - 1

    if timer.ticks == 0 then
      timertimeout(timer)
    end
  end
end
(5 hours ago)admin Wrote: Timer script:
Code:
if not client then
  -- input to output mapping
  mapping = {
    ['0/0/1'] = '0/0/6',
    ['0/1/1'] = '0/1/6',
    ['0/2/1'] = '0/2/6',
  }

  -- turn output on when input is on for X seconds
  ondelay = 5 * 60
  -- keep output on for X seconds
  offdelayaddress = '11/4/1'

  timers = {}
  for input, output in pairs(mapping) do
    timers[ input ] = {
      output = output,
      state = 'off',
    }
  end

  function timerset(timer, input)
    if input then
      if timer.state ~= 'ondelay' then
        timer.state = 'ondelay'
        timer.ticks = ondelay
      end
    else
      grp.checkwrite(timer.output, true)
      timer.state = 'offdelay'
      timer.ticks = grp.getvalue(offdelayaddress)
    end
  end

  function timertimeout(timer)
    if timer.state == 'ondelay' then
      timerset(timer, false)
    else
      grp.checkwrite(timer.output, false)
      timer.state = 'off'
      timer.ticks = nil
    end
  end

  grp.sender = 'tm'

  client = require('localbus').new(0.1)
  client:sethandler('groupwrite', function(event)
    local timer = timers[ event.dst ]
    if timer and event.sender ~= grp.sender then
      local value = tonumber(event.datahex, 16) or 0
      timerset(timer, value ~= 0)
    end
  end)
end

client:loop(1)

for _, timer in pairs(timers) do
  if timer.ticks then
    timer.ticks = timer.ticks - 1

    if timer.ticks == 0 then
      timertimeout(timer)
    end
  end
end

I try with other adresses, but nothing happend on the bus. What I do wrong?

Attached Files Thumbnail(s)
   
Reply
#6
Works for me. Do you have it as resident script with 0 sleep time?

Enable logging for 0/1/1 and 0/1/2. Setting 0/1/1 to OFF should immediately set 0/1/2 to ON for 10 seconds.
Reply
#7
(4 hours ago)admin Wrote: Works for me. Do you have it as resident script with 0 sleep time?

Enable logging for 0/1/1 and 0/1/2. Setting 0/1/1 to OFF should immediately set 0/1/2 to ON for 10 seconds.

Yeah, it works, I have 60s time. Thank You

(4 hours ago)2MAX Wrote:
(4 hours ago)admin Wrote: Works for me. Do you have it as resident script with 0 sleep time?

Enable logging for 0/1/1 and 0/1/2. Setting 0/1/1 to OFF should immediately set 0/1/2 to ON for 10 seconds.

Yeah, it works, I have 60s time. Thank You

Code:
  groups = {
    --samples
    { tag = 'my_group_and', output = '4/0/0', mode = 'and' },
    { tag = 'my_group_or', output = '4/0/1', mode = 'or' },
    { tag = 'my_group_avg', output = '4/0/2', mode = 'avg' },
  }
I dont understand what mean "my_group_or", it is possible to 4 adresses in this place to compare OR like this : tag = '3/1/10', '3/1/20', '3/1/24' , '3/1/47'       ??
Reply


Forum Jump: