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
#3
(08.08.2023, 12:38)admin Wrote: You should check which group address triggered the script and update only the relevant thermostat, not all of them. You also have a lot of grp.getvalue() calls to the same group addresses. You should cache these values to improve performance.
Could you please explain the concept of caching these values?

I've observed that when the script is triggered by address 3/6/1, the for loop runs twice when the value changes, for example, from 4 to 1. However, if I send the same value, the for loop only runs once. Additionally, when I use another address with a boolean data type, the for loop runs only once, regardless of whether the value changes.

Do you have any insight into why this might be happening?

For test I'm using only this part of code.
Code:
local thermostatCount = 1 -- 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

This might not seem like a significant issue at first glance, but when considering that I have 18 thermostats and each one triggers the script twice, the impact accumulates.

Attached Files Thumbnail(s)
   
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: