Logic Machine Forum
Central statuses - 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: Central statuses (/showthread.php?tid=220)



Central statuses - buuuudzik - 16.02.2016

How prepare calculating of central statuses on Logic Machine by event-script and tags? E.g. "1Floor status", "Kitchen status" ...


RE: Central statuses - admin - 16.02.2016

Here are 2 functions for getting OR / AND values for binary objects with the same tag. You can then use the result to write out the status.

Code:
function tag_and(tag)
  local objects, result

  result = true
  objects = grp.tag(tag)

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

  return result
end

function tag_or(tag)
  local objects, result

  result = false
  objects = grp.tag(tag)

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

  return result
end



RE: Central statuses - buuuudzik - 16.02.2016

(16.02.2016, 11:22)admin Wrote: Here are 2 functions for getting OR / AND values for binary objects with the same tag. You can then use the result to write out the status.

Code:
function tag_and(tag)
 local objects, result

 result = true
 objects = grp.tag(tag)

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

 return result
end

function tag_or(tag)
 local objects, result

 result = false
 objects = grp.tag(tag)

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

 return result
end

ThanksWink


RE: Central statuses - Pawel - 18.02.2016

Is there any solution to prevent executing this function on every tag change?

When there is 5 - 10 statuses, there is no problem, but if there is 100 or 200 statuses of whole house, script has to execute 100 time which can slow down LM...


RE: Central statuses - buuuudzik - 18.02.2016

(18.02.2016, 08:21)Pawel Wrote: Is there any solution to prevent executing this function on every tag change?

When there is 5 - 10 statuses, there is no problem, but if there is 100 or 200 statuses of whole house, script has to execute 100 time which can  slow down LM...

Before doing a function you can check if the status of this lamp is the same that the central status.

Code:
tag="kitchen"
if status1~=central then
tag_or(tag)
end