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.

Converting 0-100% into litres/second.
#1
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)
Reply


Messages In This Thread
Converting 0-100% into litres/second. - by PacoUmea - 11.06.2023, 19:02

Forum Jump: