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.

the average value of tagged objects
#1
Hi,

Ok so I have room of lights.  These objects ( group addresses ) which are either switch ( boolean ) or value based ( scale ) they are tagged as "Liivng".  I want to show the average value of these lights.   All of the status objects have been tagged with the tag called "Living Feedback".  An event based script is placed on the "Living Feedback" tag.  I created a two virtual objects.  The first allows me to set the value of tag objects.  The second represents the feedback, the average value of the objects.  The problem is that there is always a varying number of lights and it can that only one light is changed or all of them are changed. The feedback value can jump up and down whilst every light returns its status.   I have tried to overcome this by not recalculating the every time by checking when the average value status object has just been updated.  Which can lead to the value not always being correct. Is there a better way to do this?

Thanks,

Roger
 
Code:
if (event.type=='groupwrite') then  local groupstatus = grp.find('5/3/0')  -- Status address of living  local delta = os.time()-groupstatus.updatetime  if(delta>5) then    local currentV = round(groupstatus.value,0)    local sobj = grp.tag('Living Feedback')    local sTotal = 0    local counter = 0    for key, obj in ipairs(sobj) do      if(sobj[key].data==true)then      elseif(sobj[key].data==false)then      else        sTotal= sTotal + sobj[key].data        counter=counter+1      end    end    local value= round((sTotal / counter),0)    if(currentV~=value) then      grp.update('5/3/0', value, dt.scale)    end  end end
Reply


Messages In This Thread
the average value of tagged objects - by rocfusion - 04.05.2016, 10:55

Forum Jump: