could you please check script below. All tagged properly in the project, but when true signal comes from one of 30 objects nothing is being written to group 34/1/10
06.04.2022, 20:49 (This post was last modified: 06.04.2022, 21:11 by manos@dynamitec.)
Hello admin,
Can the part below be edit to be able to calculate with a resolution of 1 decimal point the average value of 2byte float or any byte value (temp, brightness, power ...)? Now in the script says the value must be between 0-100.
Code:
1234567891011121314151617181920212223242526
-- AVERAGE valuecalc['avg'] = function(group)
localresult, count, value = 0, 0for_, addressinipairs(group.objects) dovalue = values[ address ]
-- number must be in [0..100] range!!!!!!!!!!!!!!!!!iftype(value) == 'number'thenresult = result + valuecount = count + 1-- boolean true is 100%, false is 0%elseiftype(value) == 'boolean'theniftoboolean(value) thenresult = result + 100endcount = count + 1endendifcount > 0thenresult = math.floor(result / count + 0.5)
grp.checkwrite(group.output, result)
endend
Can the part below be edit to be able to calculate with a resolution of 1 decimal point the average value of 2byte float or any byte value (temp, brightness, power ...)? Now in the script says the value must be between 0-100.
Code:
1234567891011121314151617181920212223242526
-- AVERAGE valuecalc['avg'] = function(group)
localresult, count, value = 0, 0for_, addressinipairs(group.objects) dovalue = values[ address ]
-- number must be in [0..100] range!!!!!!!!!!!!!!!!!iftype(value) == 'number'thenresult = result + valuecount = count + 1-- boolean true is 100%, false is 0%elseiftype(value) == 'boolean'theniftoboolean(value) thenresult = result + 100endcount = count + 1endendifcount > 0thenresult = math.floor(result / count + 0.5)
grp.checkwrite(group.output, result)
endend
Thank you in advance
I guess just removing math.floor(..........+0.5) is the solution to this?
(07.04.2022, 06:53)admin Wrote: The 0..100 range is only needed when binary and scale objects are used together. This way binary ON is considered 100%.
For general average use this:
Code:
1234567891011121314151617
-- AVERAGE valuecalc['avg'] = function(group)
localresult, count, value = 0, 0for_, addressinipairs(group.objects) dovalue = values[ address ]
iftype(value) == 'number'thenresult = result + valuecount = count + 1endendifcount > 0thengrp.checkwrite(group.output, result / count)
endend