Logic Machine Forum
status of 100 windows and send a command to turn off the AC - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: status of 100 windows and send a command to turn off the AC (/showthread.php?tid=5494)



status of 100 windows and send a command to turn off the AC - Osvaldas - 04.07.2024

Hi, 

I need to track the status of 100 windows and send a command to turn off the AC in the room where window is open. Should send command every 5 minutes until window is closed.
Ideally, I'd like to achieve this with a single script, either resident (always running) or scheduled to run periodically. This simplifies maintenance by keeping everything in one place.
I'm unsure of the best approach. I tried using repeat..until loop, but it seems to keep running even when disabled.
Another option is a resident script that checks all 100 windows every minute and sends the "off" signal to the AC if any are open. The downside here is that the script would send the signal every minute instead of the desired 5-minute interval. 

Any insights or experiences would be appreciated Smile


RE: status of 100 windows and send a command to turn off the AC - djaval - 04.07.2024

I think you don't need use repeat..until loop, as resident script is already launched periodically by itself.


RE: status of 100 windows and send a command to turn off the AC - Daniel - 04.07.2024

Each object has Pool interval parameter where you can set time for read request sent.


RE: status of 100 windows and send a command to turn off the AC - Osvaldas - 04.07.2024

(04.07.2024, 07:18)djaval Wrote: I think you don't need use repeat..until loop, as resident script is already launched periodically by itself.

At first I thought to use event based scripts. Sorry for the confusion in my problem description.

(04.07.2024, 07:40)Daniel Wrote: Each object has Pool interval parameter where you can set time for read request sent.

Could you please explain more about your idea?


RE: status of 100 windows and send a command to turn off the AC - Daniel - 04.07.2024

https://openrb.com/wp-content/uploads/2022/05/LM-manual_3.2022.pdf
page 17


RE: status of 100 windows and send a command to turn off the AC - admin - 04.07.2024

You can use this as a scheduled script. mapping table contains tag as a key and output address as a value.
Off is sent to the output address when at least one of the tagged objects is true. Otherwise no action is performed.

Code:
function tag_or(tag)
  local result = false
  local objects = grp.tag(tag)

  for _, object in ipairs(objects) do
    result = result or object.data
  end

  return result
end

mapping = {
  ['window1'] = '1/1/1',
  ['window2'] = '1/1/2',
  ['window3'] = '1/1/3',
  ['window4'] = '1/1/4',
}

for tag, output in pairs(mapping) do
  value = tag_or(tag)

  if value then
    grp.write(output, false)
    os.sleep(0.2)
  end
end



RE: status of 100 windows and send a command to turn off the AC - Osvaldas - 08.07.2024

(04.07.2024, 08:33)admin Wrote: You can use this as a scheduled script. mapping table contains tag as a key and output address as a value.
Off is sent to the output address when at least one of the tagged objects is true. Otherwise no action is performed.

Code:
function tag_or(tag)
  local result = false
  local objects = grp.tag(tag)

  for _, object in ipairs(objects) do
    result = result or object.data
  end

  return result
end

mapping = {
  ['window1'] = '1/1/1',
  ['window2'] = '1/1/2',
  ['window3'] = '1/1/3',
  ['window4'] = '1/1/4',
}

for tag, output in pairs(mapping) do
  value = tag_or(tag)

  if value then
    grp.write(output, false)
    os.sleep(0.2)
  end
end

This script is exactly what I needed. Thank you, admin!