10.12.2018, 17:14
(07.12.2018, 21:19)Erwin van der Zwart Wrote: Hi,
I created this a while ago, maybe it could help you in your task.
BR,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
Hi Erwin,
I have some question about this script.
1. Is this a resident script or event base script?
2 If is it a resident script which is the refresh time? In case it was a event base script, what is the event base object?
3 Power, hyst and power limit are 4 byte floating point object as per Watt?
Thank you for your help.
regards.