Logic Machine Forum
last active groupadress - 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: last active groupadress (/showthread.php?tid=4144)



last active groupadress - Dré - 11.07.2022

I hope someone can help me.

i want to make a script to automatic activated my alarm.

so i need to know what group address was last changed.

i want to check all group adresses between
14/0/25 and 14/0/68 *but there are some group adresses they dont excist.
and if group adress 14/0/49 or 14/0/52 was last who changed, i want to sent a 'true' command to 14/2/1

i hope it doenst matter if some of them are still active of or not, i just want to know who was the last one who changed of state.


RE: last active groupadress - admin - 11.07.2022

Use an event script with a tag and check event.dst


RE: last active groupadress - Dré - 12.07.2022

Hi admin,

is it also possible to run a script on scheduled en just check at that moment?
to check what adres did chanced last?
I only want run the script on 11pm.
so i think it is better to just check that time.


RE: last active groupadress - admin - 13.07.2022

Use this:
Code:
tagobjs = grp.tag('tag_name')
maxtime = 0

for _, tagobj in ipairs(tagobjs) do
  updtime = tonumber(tagobj.updatetime) or 0
  if updtime > maxtime then
    obj = tagobj
    maxtime = updtime
  end
end

log(obj)



RE: last active groupadress - Dré - 14.07.2022

Thanks admin, it looks like it is working.

Just curious to understand better scripts.

Why is this part of script need for?
Code:
  if updtime > maxtime then
changing the maxtime, doesnt look do anyting.
and why doesnt work
Code:
log(tagobj)
for me it looks like its the same as 'log(obj)' , but it isn't?


RE: last active groupadress - admin - 14.07.2022

maxtime stores the maximum update time, it is changed when an object with a larger update time is found. Another option would be to sort the tagged object table by the updatetime field and use the first element of the table.
tagobj is a local variable and it's only visible inside the for loop.