Logic Machine Forum
Scripts two pumps alternate - 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: Scripts two pumps alternate (/showthread.php?tid=3493)



Scripts two pumps alternate - streilkx - 29.07.2021

Hello,

can someone help me with the following script, for me scripting is completely new, I have some tutorials followed but to make the first start I find difficult.

Two pumps with alternate operation according to hours of operation and according to fault / stop status.
If both pumps are OK, they alternate every 50 hours of operation. If one of the pumps is faulty / stopped, the other always starts.


Thanks!


RE: Scripts two pumps alternate - admin - 29.07.2021

Which objects are available? Pump start/stop and fault status (both binary)?


RE: Scripts two pumps alternate - streilkx - 30.07.2021

(29.07.2021, 13:47)admin Wrote: Which objects are available? Pump start/stop and fault status (both binary)?

Yes, objects are;

Pumps start/stop (5/0/0)
Pump A Start/Stop (5/0/1)
Pump B Start/Stop  (5/0/2)
Pump A Fault/manual stop status (5/0/10)
Pump B Fault/manual stop status (5/0/20)

Thanks for help!


RE: Scripts two pumps alternate - admin - 04.08.2021

You will need 3 scripts.
Scheduled script that run once each hour:
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

-- one of the pumps is on
if on_1 or on_2 then
  pump_time = storage.get('pump_time', 0)
  pump_time = pump_time + 1

  -- try switching to another pump
  if pump_time > 50 then
    stop_1 = grp.getvalue('5/0/10')
    stop_2 = grp.getvalue('5/0/20')

    -- first is on, second is not in stop state
    if on_1 and not stop_2 then
      grp.write('5/0/1', false)
      grp.write('5/0/2', true)

      pump_time = 0
    -- second is on, first is not in stop state
    elseif on_2 and not stop_1 then
      grp.write('5/0/2', false)
      grp.write('5/0/1', true)

      pump_time = 0
    end
  end
else
  pump_time = 0
end

storage.set('pump_time', pump_time)

Event script for first pump fault (5/0/10):
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')

-- switch to the second pump
if stop_1 then
  if not stop_2 and not on_2 then
    grp.write('5/0/1', false)
    grp.write('5/0/2', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/1', true)

  storage.set('pump_time', 0)
end

Event script for second pump fault (5/0/20):
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()

-- switch to the first pump if it's not in a fault state
if stop_2 then
  if not stop_1 and not on_1 then
    grp.write('5/0/2', false)
    grp.write('5/0/1', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/2', true)

  storage.set('pump_time', 0)
end



RE: Scripts two pumps alternate - streilkx - 06.08.2021

(04.08.2021, 06:25)admin Wrote: You will need 3 scripts.
Scheduled script that run once each hour:
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

-- one of the pumps is on
if on_1 or on_2 then
  pump_time = storage.get('pump_time', 0)
  pump_time = pump_time + 1

  -- try switching to another pump
  if pump_time > 50 then
    stop_1 = grp.getvalue('5/0/10')
    stop_2 = grp.getvalue('5/0/20')

    -- first is on, second is not in stop state
    if on_1 and not stop_2 then
      grp.write('5/0/1', false)
      grp.write('5/0/2', true)

      pump_time = 0
    -- second is on, first is not in stop state
    elseif on_2 and not stop_1 then
      grp.write('5/0/2', false)
      grp.write('5/0/1', true)

      pump_time = 0
    end
  end
else
  pump_time = 0
end

storage.set('pump_time', pump_time)

Event script for first pump fault (5/0/10):
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')

-- switch to the second pump
if stop_1 then
  if not stop_2 and not on_2 then
    grp.write('5/0/1', false)
    grp.write('5/0/2', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/1', true)

  storage.set('pump_time', 0)
end

Event script for second pump fault (5/0/20):
Code:
on_1 = grp.getvalue('5/0/1')
on_2 = grp.getvalue('5/0/2')

stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()

-- switch to the first pump if it's not in a fault state
if stop_2 then
  if not stop_1 and not on_1 then
    grp.write('5/0/2', false)
    grp.write('5/0/1', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/2', true)

  storage.set('pump_time', 0)
end


Thanks for help!

I have been testing the scripts.

I understand that I always give start order to pump 1, and if it is faulty or has more than 50 hours, pump 2 starts.


I have found the following problem, if pump 1 is running, pump 2 is faulty, if pump 1 breaks down and pump 2 is repaired, pump 2 does not start automatically


RE: Scripts two pumps alternate - admin - 06.08.2021

Try modifying the event scripts like this:
Code:
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')

on_1 = grp.getvalue('5/0/1') and not stop_1
on_2 = grp.getvalue('5/0/2') and not stop_2

-- switch to the second pump
if stop_1 then
  if not stop_2 and not on_2 then
    grp.write('5/0/1', false)
    grp.write('5/0/2', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/1', true)

  storage.set('pump_time', 0)
end

Code:
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()

on_1 = grp.getvalue('5/0/1') and not stop_1
on_2 = grp.getvalue('5/0/2') and not stop_2

-- switch to the first pump if it's not in a fault state
if stop_2 then
  if not stop_1 and not on_1 then
    grp.write('5/0/2', false)
    grp.write('5/0/1', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/2', true)

  storage.set('pump_time', 0)
end



RE: Scripts two pumps alternate - streilkx - 16.08.2021

I have the following problem;

If pump 1 fault, stops pump 1 and starts pump 2, then pump 2 breaks down, pump 2 does not stop and if pump 1 is repaired, pump 2 and pump one are on.

Thanks for help!


RE: Scripts two pumps alternate - admin - 18.08.2021

This will send OFF command when a fault is detected:
Code:
stop_1 = event.getvalue()
stop_2 = grp.getvalue('5/0/20')

on_1 = grp.getvalue('5/0/1') and not stop_1
on_2 = grp.getvalue('5/0/2') and not stop_2

-- switch to the second pump
if stop_1 then
  grp.write('5/0/1', false)

  if not stop_2 and not on_2 then
    grp.write('5/0/2', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/1', true)

  storage.set('pump_time', 0)
end

Code:
stop_1 = grp.getvalue('5/0/10')
stop_2 = event.getvalue()

on_1 = grp.getvalue('5/0/1') and not stop_1
on_2 = grp.getvalue('5/0/2') and not stop_2

-- switch to the first pump if it's not in a fault state
if stop_2 then
  grp.write('5/0/2', false)

  if not stop_1 and not on_1 then
    grp.write('5/0/1', true)

    storage.set('pump_time', 0)
  end
-- fault is removed and no pump is running
elseif not on_1 and not on_2 then
  grp.write('5/0/2', true)

  storage.set('pump_time', 0)
end