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.

Loop through groupadresses to set alarm
#1
Code:
    -- Comfort alarm for room 9. All adresses for room 9 = X / X / 9.

-- Thresholds for alarm
MaxCo2 = 800
MaxTemp = 25
MinTemp = 20
MaxHum = 60
MinHum = 40

-- Get co2, temperature and humidity values
Co2 = grp.getvalue('12/1/9')
Temp = grp.getvalue('6/1/9')
Humidity = grp.getvalue('13/1/9')
ComfortAlarm = grp.getvalue('25/1/9')


-- Check if values are within the thresholds
if Co2 > MaxCo2 or Temp > MaxTemp or Temp < MinTemp or Humidity > MaxHum or Humidity < MinHum then

 
  -- Sets alarm on or off
if ComfortAlarm == false then
        grp.write('25/1/9', 1)
else
end
else
  if
    ComfortAlarm == true then
    grp.write('25/1/9', 0)
  end
end
Hey,

I have made a script to set a comfort alarm if Co2, room temperature or humidity is not within threshold values. This works fine. 
The group adress structure in my project is that all adresses to one room = X / X / room number. So for the code above its a comfort alarm for room number 9.
Example Co2 in room number 9 is 12/1/9. Co2 in room 24 is 12/1/24. So main group and middle group is all the same in every room. 

My question is if its possible to make a loop to run through every room checking the same adresses and setting the same alarm for each room?
So alarm for room 9 would set 25/1/9, and alarm for room 60 would set 25/1/60.
All help would be appreciated
Reply
#2
(27.02.2022, 15:50)SennepKrem Wrote: Hey,

I have made a script to set a comfort alarm if Co2, room temperature or humidity is not within threshold values. This works fine. 
The group adress structure in my project is that all adresses to one room = X / X / room number. So for the code above its a comfort alarm for room number 9.
Example Co2 in room number 9 is 12/1/9. Co2 in room 24 is 12/1/24. So main group and middle group is all the same in every room. 

My question is if its possible to make a loop to run through every room checking the same adresses and setting the same alarm for each room?
So alarm for room 9 would set 25/1/9, and alarm for room 60 would set 25/1/60.
All help would be appreciated

Are all the rooms in numerical order, following the xx/xx/room format?
This loop below would work if they are all in order, otherwise you may need a table to list all the rooms and iterate over that from the start to the end.

Code:
   -- Comfort alarm for room 9. All adresses for room 9 = X / X / 9.

-- Thresholds for alarm
MaxCo2 = 800
MaxTemp = 25
MinTemp = 20
MaxHum = 60
MinHum = 40

start_Grp = '1'
end_Grp = '60'

for i = start_Grp, end_Grp do


-- Get co2, temperature and humidity values
  Co2 = grp.getvalue('12/1/'.. i)
temp = grp.getvalue('6/1/'.. i)
Humidity = grp.getvalue('13/1/'.. i)
ComfortAlarm = grp.getvalue('25/1/'.. i)


-- Check if values are within the thresholds
if Co2 > MaxCo2 or Temp > MaxTemp or Temp < MinTemp or Humidity > MaxHum or Humidity < MinHum then

 
  -- Sets alarm on or off
if ComfortAlarm == false then
        grp.write('25/1/'.. i, 1)
else
end
else
  if
    ComfortAlarm == true then
    grp.write('25/1/'.. i, 0)
  end
end
 
end
Reply
#3
(27.02.2022, 20:40)benanderson_475 Wrote:
(27.02.2022, 15:50)SennepKrem Wrote: Hey,

I have made a script to set a comfort alarm if Co2, room temperature or humidity is not within threshold values. This works fine. 
The group adress structure in my project is that all adresses to one room = X / X / room number. So for the code above its a comfort alarm for room number 9.
Example Co2 in room number 9 is 12/1/9. Co2 in room 24 is 12/1/24. So main group and middle group is all the same in every room. 

My question is if its possible to make a loop to run through every room checking the same adresses and setting the same alarm for each room?
So alarm for room 9 would set 25/1/9, and alarm for room 60 would set 25/1/60.
All help would be appreciated

Are all the rooms in numerical order, following the xx/xx/room format?
This loop below would work if they are all in order, otherwise you may need a table to list all the rooms and iterate over that from the start to the end.

Code:
   -- Comfort alarm for room 9. All adresses for room 9 = X / X / 9.

-- Thresholds for alarm
MaxCo2 = 800
MaxTemp = 25
MinTemp = 20
MaxHum = 60
MinHum = 40

start_Grp = '1'
end_Grp = '60'

for i = start_Grp, end_Grp do


-- Get co2, temperature and humidity values
  Co2 = grp.getvalue('12/1/'.. i)
temp = grp.getvalue('6/1/'.. i)
Humidity = grp.getvalue('13/1/'.. i)
ComfortAlarm = grp.getvalue('25/1/'.. i)


-- Check if values are within the thresholds
if Co2 > MaxCo2 or Temp > MaxTemp or Temp < MinTemp or Humidity > MaxHum or Humidity < MinHum then

 
  -- Sets alarm on or off
if ComfortAlarm == false then
        grp.write('25/1/'.. i, 1)
else
end
else
  if
    ComfortAlarm == true then
    grp.write('25/1/'.. i, 0)
  end
end
 
end

Thank you! This worked just as i wanted. Very much appreciated!
Reply


Forum Jump: