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.

If all "tag" objects are false, then
#1
Hi.

Is there a script that can do something if all objects with a certain tag is false?

BR
Kai-Roger
Reply
#2
Hi,

Try this:
Code:
tagname = 'tag name'
for _, obj in ipairs(grp.tag(tagname)) do
 if obj.value then
   return
 end
end
log('All objects are false')
BR,

Erwin
Reply
#3
(18.03.2019, 22:03)Erwin van der Zwart Wrote: Hi,

Try this:
Code:
tagname = 'tag name'
for _, obj in ipairs(grp.tag(tagname)) do
 if obj.value then
   return
 end
end
log('All objects are false')
BR,

Erwin

Hi.

Thanks a lot!
With a lot of trial and error, i finaly got this to do what i want. If all tags are false, then Lights_status is false. If one or more of the tags are true, then Lights_status are true :)


tagname = 'Lights_room1'
Lights_status = grp.find('1/1/137')

for _, obj in ipairs(grp.tag(tagname)) do
  if obj.value then
    return
      Lights_status:write(true)
  end
end
     Lights_status:write(false)

And here a little more adjusted to suite my purpose better in a bigger script, and to work with only tag's (no group adresses) :)

for _, obj in ipairs(grp.tag('Lights_room1')) do
  if obj.value then
    return
    grp.tag('All_lights'):write(true)
  end
end
grp.tag('All_lights'):write(false)
Reply
#4
Hi,

Are you sure your script works?

I would expect the command in true state before the return..

BR,

Erwin
Reply
#5
(19.03.2019, 05:39)Erwin van der Zwart Wrote: Hi,

Are you sure your script works?

I would expect the command in true state before the return..

BR,

Erwin

Hi. Yes it does what i expected. 

Here is how it responds:
   

But what i failed to do, was to use two of these codes after another in the same code. I think it stops at the first one, so i have to change something so that the scripts run every part of the code.
Reply
#6
(19.03.2019, 06:35)Kai-Roger Wrote:
(19.03.2019, 05:39)Erwin van der Zwart Wrote: Hi,

Are you sure your script works?

I would expect the command in true state before the return..

BR,

Erwin

Hi. Yes it does what i expected. 

Here is how it responds:


But what i failed to do, was to use two of these codes after another in the same code. I think it stops at the first one, so i have to change something so that the scripts run every part of the code.

Not the prettiest script but atleast it works  Angel 


Code:
tag = grp.tag('lights_1')
lights_on = 0

-- arraytable = { 'a', 'b', 'c' }
for i, value in ipairs(tag) do
 local lights_status = grp.getvalue(value.address)
 if lights_status == true then
   lights_on = lights_on + 1
 end
end

if lights_on == 0 then
 log('All lights off')
else
 log('Some lights are on')
end
Reply
#7
You don't need grp.getvalue there, each object table already has value field populated.
Reply


Forum Jump: