Logic Machine Forum
Multi OR port - 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: Multi OR port (/showthread.php?tid=1851)



Multi OR port - fabiorusco - 21.01.2019

Hallo,
I need create a OR port with about 90-100 input. I tagged each input in objects window. It's possible create the OR gate useing the tag of the group address?

I wrote the follow example that don't function:


if (true == grp.tag('LuciScalaA')) then
  grp.write('12/1/21', true)
else
  os.sleep(100)
  grp.write('12/1/21', false)
end

See attached

Best regards


RE: Multi OR port - Erwin van der Zwart - 21.01.2019

Hi,

grp.tag will always return a table with objects so this is never true or false..

Here are the needed scripts for logical and/or by TAG:
Code:
-- Logical OR port by tagged objects
tagname = 'OR_LOGIC'
output = '1/1/1'
for i, object in ipairs(grp.tag(tagname)) do
  if object.data then
    grp.checkwrite(output, true, 1)
    return
 end
end
grp.checkwrite(output, false, 1)

Code:
-- Logical AND port by tagged objects
tagname = 'AND_LOGIC'
output = '1/1/1'  
for i, object in ipairs(grp.tag(tagname)) do
 if not object.data then
   grp.checkwrite(output, false, 1)
   return
 end
end
grp.checkwrite(output, true, 1)
BR,

Erwin


RE: Multi OR port - Daniel - 22.01.2019

Hi
Here is universal script
https://forum.logicmachine.net/showthread.php?tid=291&pid=1518#pid1518
BR


RE: Multi OR port - MantasJ - 24.01.2019

What script is more effective and takes less time and less resources to execute? Something like this:

Quote:value = grp.getvalue('1address')
value2 = grp.getvalue('2address)
value3 = grp.getvalue('3address')

output = 'outputaddress'

if(value or value2 or value3 == true) then
  grp.write(output, true)
else 
  grp.write(output, false)
end
 Or this one:

Quote:tagname = 'OR_LOGIC'
output = 'output_address'
for i, object in ipairs(grp.tag(tagname)) do
if object.data then
grp.checkwrite(output, true, 1)
return
end
end
grp.checkwrite(output, false, 1)

I have many lights and many rooms and if I turn on ALL lights at the same time there are a lot of scripts executing at once, so I need the most perfomance-effective solution.


RE: Multi OR port - Daniel - 24.01.2019

The best for performance is this
https://forum.logicmachine.net/showthread.php?tid=291&pid=1518#pid1518


RE: Multi OR port - MantasJ - 24.01.2019

Well you see I have a problem with this one. As I have A LOT lights, it feels that if many lights are turning on/off the script starts to "hang" and doesn't update any addresses any more and then it needs to be disabled/enabled to work again. I've tried upgrading LM to newest version but it didn't help so I'm kind of stuck with those 2 scripts.


RE: Multi OR port - Daniel - 24.01.2019

If you have a lot of lights then this script is much better as it is just one PID, The other creates a lots of them with each telegram sent. Can you send me your project to PM to check why it is happening, It could be some bug or other reason.


RE: Multi OR port - Erwin van der Zwart - 24.01.2019

Hi,

Are you using a os.sleep in your script?

If you do that in a event script you might have several scripts running in paralel..

BR,

Erwin