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.

Peak load limiter
#3
Hi,

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
BR,

Erwin
Reply


Messages In This Thread
Peak load limiter - by tomnord - 07.12.2018, 15:41
RE: Peak load limiter - by buuuudzik - 07.12.2018, 17:13
RE: Peak load limiter - by Erwin van der Zwart - 07.12.2018, 21:19
RE: Peak load limiter - by tomnord - 07.12.2018, 21:25
RE: Peak load limiter - by Domoticatorino - 10.12.2018, 17:14
RE: Peak load limiter - by Domoticatorino - 12.12.2018, 20:09
RE: Peak load limiter - by BMA - 19.02.2021, 17:11
RE: Peak load limiter - by tomnord - 08.12.2018, 18:33

Forum Jump: