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.

For loops
#1
Code:
local thermostatCount = 18 -- Number of thermostats
local heating_cooling_sources = '12/1/211'

--+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++


local script_lock = '12/1/210'
local holidays = '6/1/3' -- Thermostat Mode
local S4_ON_OFF = {} --   AUTO / OFF
local S4_ON_OFF_FB = {} --   AUTO/OFF feedback
local overheat = {} -- Overheat status
local climate_status = {} -- Thermostat heating status
local Force_heat = {} --  FORCED POS
local PIDBLOCK = {} --  PID block
local thermostat_block = {} -- Thermostat block
local blocking_Fb = {} --  blocking FB
local frost_heat_FB = {} -- Termostato Frost/Heat protection Feedback

-- Initialize thermostat addresses and other variables
for i = 1, thermostatCount do
  S4_ON_OFF[i] = '12/1/' .. i
  S4_ON_OFF_FB[i + 100] = '12/1/' .. (i + 100)
  overheat[i] = '2/4/' .. i
  climate_status[i] = '3/6/' .. i
  Force_heat[i] = '3/1/' .. i
  PIDBLOCK[i] = '3/5/' .. i
  thermostat_block[i + 100] = '3/5/' .. (i + 100)
  blocking_Fb[i] = '12/0/' .. i
  frost_heat_FB[i] = '3/4/' .. i

end





for i = 1, thermostatCount do
  os.sleep(0.2)
    if grp.getvalue(overheat[i])  or grp.getvalue(holidays) == 3 or not grp.getvalue(S4_ON_OFF[i]) or not grp.getvalue(climate_status[i]) then
      grp.checkwrite(PIDBLOCK[i], true)
    else
      grp.checkwrite(PIDBLOCK[i], false)
    end
  end
 




if grp.getvalue(heating_cooling_sources) == 1 then
   
  for i = 1, thermostatCount do
    local index2 = i + 100
    if grp.getvalue(overheat[i])  then
      grp.checkwrite(Force_heat[i], true)
      --grp.checkwrite(PIDBLOCK[i], true)
      grp.checkwrite(thermostat_block[index2], true)
      -- Log thermostat block action
      log('Termostat block enabled for thermostat ' .. i)
    else
      grp.checkwrite(Force_heat[i], false)
     -- grp.checkwrite(PIDBLOCK[i], false)
      grp.checkwrite(thermostat_block[index2], false)
     
      -- Log thermostat block disabled action
      log('Termostat block disabled for thermostat ' .. i)
    end
  end
end










if grp.getvalue(heating_cooling_sources) == 2 then

  -- Šildymo vožtuvų ir termostaų blokavimas
  for i = 1, thermostatCount do
  os.sleep(0.2)
    if grp.getvalue(overheat[i]) then
      grp.checkwrite(Force_heat[i], true)
      --grp.checkwrite(PIDBLOCK[i], true)
      -- Log vožtuvo block action
      log('Vožtuvas block enabled for thermostat ' .. i)
    else
      grp.checkwrite(Force_heat[i], false)
      --grp.checkwrite(PIDBLOCK[i], false)
      -- Log vožtuvo block disabled action
      log('Vožtuvas block disabled for thermostat ' .. i)
    end
  end
end


 



  for i = 1, thermostatCount do
  os.sleep(0.2)
    if grp.getvalue(overheat[i])  then
     -- if grp.getvalue(S4_ON_OFF[i]) then
        grp.checkwrite(blocking_Fb[i], true)
        -- Log visualization block action
        log('Visualization block enabled for thermostat ' .. i)
      else
        if not grp.getvalue(overheat[i])  then
  -- if grp.getvalue(S4_ON_OFF[i]) then
        grp.checkwrite(blocking_Fb[i], false)
        -- Log visualization block disabled action
        log('Visualization block disabled for thermostat ' .. i)
           -- end
         -- end
      end
    end
  end




  for i = 1, thermostatCount do
  os.sleep(0.2)
    local index = i + 100 -- Calculate the corresponding index for S4_ON_OFF_FB
    if grp.getvalue(frost_heat_FB[i]) or grp.getvalue(holidays) ~= 1 or not grp.getvalue(S4_ON_OFF[i])  or grp.getvalue(thermostat_block[index]) then
    grp.checkwrite(S4_ON_OFF_FB[index], false)

   

  else
   if not grp.getvalue(frost_heat_FB[i]) and  grp.getvalue(holidays) == 1 and  grp.getvalue(S4_ON_OFF[i])  and not grp.getvalue(thermostat_block[index])  then
    grp.checkwrite(S4_ON_OFF_FB[index], true)
   
 
end
end
end
I have written a script that controls the thermostats and contains five for loops. Each thermostat is associated with four separate addresses that can trigger this script. I utilize this script for 18 thermostats. However, when I activate all the thermostats within a minute, a significant number of for loops are executed, consuming 100% of the processor's capacity. Consequently, not all the addresses maintain the correct values, leading to an unstable system. All 18 thermostat addresses share the same tag.

My goal is to employ a single script to control all the thermostats, given that they are identical. This approach would enhance the scalability of the script and facilitate error correction. In other words, the same script would be applicable to all thermostats, and any changes made would immediately apply to all thermostats. This eliminates the need to modify 18 tags individually.

How I can lower processor load?
Reply


Messages In This Thread
For loops - by os2099 - 08.08.2023, 12:27
RE: For loops - by admin - 08.08.2023, 12:38
RE: For loops - by os2099 - 08.08.2023, 13:56
RE: For loops - by admin - 09.08.2023, 12:35

Forum Jump: