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
#10
Hi,

Here is a more complex script for load balancing, i use it for EV chargers, they can use max 63 Amp and need minimal 8 Amp, based on active chargers and available power the chargers are set to a maximum loader output over modbus (for our EVLink)

All works with TAG's on the binary state (active/not active) object and a offset of 1 in the main address (32/1/1 = State -> 32/1/1 = Set max charging output) so you can easily add multiple chargers (:
Code:
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
-- Get maximal available amperage Max_Amp = grp.getvalue('35/0/10') -- Get current messured amperage Current_Amp = grp.getvalue('35/0/11') -- Calculate available amperage for loaders Available_Amp = Max_Amp - Current_Amp -- Minimal amperage output on loader Min_Loader_Amp = 8 -- Maximal amperage output on loader Max_Loader_Amp = 63 -- Get all loaders on/off states All_Loaders = grp.tag('LoaderState') -- Function to sort table by updatetime local function tableSortCat (a,b)  return a.updatetime < b.updatetime end -- Sort table All_Loaders by updatetime table.sort(All_Loaders, tableSortCat) -- Create table with active loader Active_Loaders = {} -- Determine amount of active loaders Number_Active_Loaders = 0 -- Ceeate new table with values and only loader tagged bit objects for _, item in pairs(All_Loaders) do  if item.datatype == 1 or (item.datatype > 999 and item.datatype < 2000) then    if item.value == true then      Number_Active_Loaders = Number_Active_Loaders + 1    end    table.insert(Active_Loaders, {id = item.id, updatetime = item.updatetime, datatype = item.datatype, address = item.address, value = item.value})  end end -- Sort table Active_Loaders by updatetime table.sort(Active_Loaders, tableSortCat) -- Determine maximum loaders based on available power Max_Number_Loaders_Possible =  math.floor(Available_Amp / Min_Loader_Amp) -- Check if more loaders are active then max possible loaders if Number_Active_Loaders < Max_Number_Loaders_Possible then  Max_Number_Loaders_Possible = Number_Active_Loaders end --Set available amperage per loader Available_Amperage_Loader_Per_Unit = math.round(Available_Amp / Max_Number_Loaders_Possible, 2) --Check if output exceeds loaders Max_Amp if Available_Amperage_Loader_Per_Unit > Max_Loader_Amp then  Available_Amperage_Loader_Per_Unit = Max_Loader_Amp end -- Set loaders to 0 when current amperage exceeds max amperage if Current_Amp > Max_Amp then     Max_Number_Loaders_Possible = 0  Available_Amperage_Loader_Per_Unit = 0 end -- Write values to the output of each loader Number_Loaders_Value_Written = 0 for _, item in pairs(All_Loaders) do  Address_Table = string.split(item.address, "/")  New_Address = Address_Table[1]+1 .. '/' .. Address_Table[2] .. '/' .. Address_Table[3]  if item.value == true then    if Number_Loaders_Value_Written < Max_Number_Loaders_Possible then        grp.checkupdate(New_Address,Available_Amperage_Loader_Per_Unit)      Number_Loaders_Value_Written = Number_Loaders_Value_Written + 1    else      grp.checkupdate(New_Address,0)    end  else    grp.checkupdate(New_Address,0)  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 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 Erwin van der Zwart - 12.12.2018, 22:45
RE: Peak load limiter - by BMA - 19.02.2021, 17:11
RE: Peak load limiter - by tomnord - 08.12.2018, 18:33

Forum Jump: