Logic Machine Forum
Summing Values - 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: Summing Values (/showthread.php?tid=2316)



Summing Values - christian.troen@haaland.no - 04.11.2019

Is there an easy way for summing several values that is on the KNX-bus to one Virtual KNX-obejct? Se screenshot values that I want to sum.


RE: Summing Values - Daniel - 04.11.2019

Tag all objects you want to sum and you can use this

Code:
function tag_sum(tag)
  local objects, result

  result = 0
  objects = grp.tag(tag)

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

  return result
end



sum = tag_sum('TAG')



RE: Summing Values - christian.troen@haaland.no - 04.11.2019

Thanks for the reply.
Can you please be more spesific on how i should build it to my purpose? (I am at best Poorly experienced with LULA).
If I have given the tag "Supply" to all valves, and the tag SupplySUM to the adress I want the summing value to be written to. How should I do it?


RE: Summing Values - Daniel - 04.11.2019

You need only tag for the 'Supply' values and the you can use event script with your tag as event or resident script with interval as often you need the calculation.

Code:
function tag_sum(tag)
  local objects, result

  result = 0
  objects = grp.tag(tag)

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

  return result
end



sum = tag_sum('Supply')


grp.checkwrite('1/1/1', sum)
Change group address where you want to write it to.


RE: Summing Values - christian.troen@haaland.no - 04.11.2019

Thank you! Worked very well Big Grin


RE: Summing Values - christian.troen@haaland.no - 04.11.2019

If the values are boolean, the sum does not work. Can I convert from boolean to floating point in the same script?

See screenshot. I want to display the total number of active heating-zones in in one tag.


RE: Summing Values - Daniel - 04.11.2019

Of course a Boolean is not a number. For binary use such script.
Code:
function tag_sum(tag)
  local objects, result

  result = 0
  objects = grp.tag(tag)

  for _, object in ipairs(objects) do
    if object.data then
    result = result + 1
    end 
  end

  return result
end



sum=tag_sum('Supply'))


grp.checkwrite('1/1/1', sum)



RE: Summing Values - Tokatubs - 04.11.2019

Daniel, since you are on a rollSmile
I see that the first example is air values and i guess to sum them up.
But lets say you have some supply air vav but only one central extract vav. And then want to convert the supply sum to an control value 0-100 % to control the Extract vav.
Given you know the Min/Max/Nom values of the Vav.
Been searching forum, but have not seen anything.


RE: Summing Values - Daniel - 05.11.2019

To be honest I didn't even look what the values are, it was a number Smile
What exact logic are you looking at?