LogicMachine Forum
Converting 0-100% into litres/second. - Printable Version

+- LogicMachine 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: Converting 0-100% into litres/second. (/showthread.php?tid=4825)



Converting 0-100% into litres/second. - PacoUmea - 11.06.2023

Hi
New to all this and trying to convert a 0-100% value that i recive from VAV modules in building and converting these to litres/second. I know that 0% is the same as 20 litres/s and 100% equals 140 litres/second in this case. I tried to get som help from chatGPT and from this forum and others but there is somthing thats not working.
I got the following from the error log.

Quote:User script 13: attempt to perform arithmetic on local 'percentage' (a boolean value) stack traceback:
User script 13: in function 'convertFlowRate'


Code:
-- KNX group addresses local PERCENTAGE_GROUP = "0/3/67" local LITERS_PER_SECOND_GROUP = "0/3/68" -- Flow rate conversion function function convertFlowRate(percentage)     local minPercentage = 0     local maxPercentage = 100     local minLitersPerSecond = 20     local maxLitersPerSecond = 140     -- Calculate the percentage within the range 0-1     local normalizedPercentage = (percentage - minPercentage) / (maxPercentage - minPercentage)     -- Calculate the flow rate within the range minLitersPerSecond-maxLitersPerSecond     local flowRate = minLitersPerSecond + normalizedPercentage * (maxLitersPerSecond - minLitersPerSecond)     return flowRate end -- Read the percentage from group 0/3/67 local percentage = grp.read(PERCENTAGE_GROUP) -- Convert the percentage to liters per second local litersPerSecond = convertFlowRate(percentage) -- Write the liters per second to group 0/3/68 grp.write(LITERS_PER_SECOND_GROUP, litersPerSecond)



RE: Converting 0-100% into litres/second. - admin - 12.06.2023

You need to use event.getvalue(). grp.read() sends read request but does not return the actual value.
Code:
value = event.getvalue() value = 20 + value * 1.2 grp.checkwrite('0/3/68', value)



RE: Converting 0-100% into litres/second. - PacoUmea - 13.06.2023

(12.06.2023, 07:24)admin Wrote: You need to use event.getvalue(). grp.read() sends read request but does not return the actual value.
Code:
value = event.getvalue() value = 20 + value * 1.2 grp.checkwrite('0/3/68', value)

Ah, super! Thank you very much!