Posts: 7
Threads: 3
Joined: Feb 2021
Reputation:
0
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!
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
Which objects are available? Pump start/stop and fault status (both binary)?
Posts: 7
Threads: 3
Joined: Feb 2021
Reputation:
0
30.07.2021, 08:11
(This post was last modified: 30.07.2021, 08:23 by streilkx.)
(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!
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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
Posts: 7
Threads: 3
Joined: Feb 2021
Reputation:
0
(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
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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
Posts: 7
Threads: 3
Joined: Feb 2021
Reputation:
0
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!
Posts: 7773
Threads: 42
Joined: Jun 2015
Reputation:
447
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
|