07.12.2018, 21:19
Hi,
I created this a while ago, maybe it could help you in your task.
BR,
Erwin
I created this a while ago, maybe it could help you in your task.
Code:
-- Set adresses
address_max = '1/1/2'
address_hyst = '1/1/3'
address_relais1 = '1/1/4'
address_relais2 = '1/1/5'
address_relais3 = '1/1/6'
address_relais4 = '1/1/7'
-- Get measured power
power = event.getvalue()
-- Get limit value
max = grp.getvalue(address_max)
-- Get Hysteresis
hyst = grp.getvalue(address_hyst)
-- Calculate floor value
hyst_floor = math.floor((max - hyst) + 0.5)
-- Check if chanels need to be turned on
if power < hyst_floor then
-- get current state of relais 4
current_state_relais4 = grp.getvalue(address_relais4)
if current_state_relais4 == false then
grp.write(address_relais4, true)
-- exit script and after that cascade to chanel 3
return
end
-- get current state of relais 3
current_state_relais3 = grp.getvalue(address_relais3)
if current_state_relais3 == false then
grp.write(address_relais3, true)
-- exit script and after that cascade to chanel 2
return
end
-- get current state of relais 2
current_state_relais2 = grp.getvalue(address_relais2)
if current_state_relais2 == false then
grp.write(address_relais2, true)
-- exit script and after that cascade to chanel 1
return
end
-- get current state of relais 1
current_state_relais1 = grp.getvalue(address_relais1)
if current_state_relais1 == false then
grp.write(address_relais1, true)
-- exit script
return
end
end
-- Check if chanel 1 need to be turned off, after that cascade to chanel 2, then cascade to chanel 3 etcetera
if power > max then
-- get current state of relais 1
current_state_relais1 = grp.getvalue(address_relais1)
if current_state_relais1 == true then
grp.write(address_relais1, false)
else
-- get current state of relais 2
current_state_relais2 = grp.getvalue(address_relais2)
if current_state_relais2 == true then
grp.write(address_relais2, false)
else
-- get current state of relais 3
current_state_relais3 = grp.getvalue(address_relais3)
if current_state_relais3 == true then
grp.write(address_relais3, false)
else
-- get current state of relais 4
current_state_relais4 = grp.getvalue(address_relais4)
if current_state_relais4 == true then
grp.write(address_relais4, false)
end
end
end
end
end
Erwin