Page 1 of 1
COP calculation script
Posted: Wednesday 17 October 2018 8:21
by juuzo
Hi, I'm really new to lua scripting and I'm trying to make simple calculation program that calculates heatpump cop with measured temperatures, power and fan speed. Anyway I'm little stuck on this script. I get error
/home/pi/domoticz/scripts/lua/script_time_COP.lua:5: ']' expected near 'Fan'
So I assume that there is somethin wrong with fan speed reading. Fan speed is simple 6 step switch with values 0 to 60.
Code: Select all
commandArray = {}
time = os.date("*t")
if((time.min % 5)==0)then --Run every 5 minutes
var1 = commandArray.GetValue(otherdevices_svalues[Heatpump Fan Speed],1)
if (var1 == 0 or var1 == 10) then
airvolume = 0
end
if (var1 == 20) then
airvolume = 120
end
if (var1 == 30) then
airvolume = 220
end
if (var1 == 40) then
airvolume = 320
end
if (var1 == 50) then
airvolume = 520
end
if (var1 == 60) then
airvolume = 620
end
OutletTemp = commandArray.GetValue(otherdevices_svalues[Heatpump Outlet Temp],1)
InletTemp = commandArray.GetValue(otherdevices_svalues[Heatpump Inlet Temp],1)
inpower = commandArray.GetValue(otherdevices_svalues[Heatpump Power/Energy],1)
outpower = airvolume * 1,293 * 1,01 * (OutletTemp-InletTemp)
calculation = outpower / inpower
print( " ####Cop debug: "..calculation)
COPidx = otherdevices_idx['Heatpump COP']
commandArray['UpdateDevice'] = COPidx..'|0|'..calculation
end
return commandArray
Re: COP calculation script
Posted: Wednesday 17 October 2018 8:37
by SweetPants
Try var1 = commandArray.GetValue(otherdevices_svalues['Heatpump Fan Speed'],1)
Re: COP calculation script
Posted: Wednesday 17 October 2018 9:26
by juuzo
I got something to work with this script
Now I can read values even though my airflow doesn't update in those if then fields. Biggest problem is now that my energy meter gives values like 300.10;259999 where first value is power what I want and second is energy what I don't need. How do I parse that first number and how can I convert it to float? I have tried tonumber() command but it doesn't work.
Code: Select all
local airvolume = 10
commandArray = {}
time = os.date("*t")
if((time.min % 1)==0)then --Run every 5 minutes
var1 = otherdevices['Heatpump Fan Speed']
if var1 == 0 or var1 == 1 then
airvolume = 0
end
if var1 == 2 then
airvolume = 120
end
if var1 == 3 then
airvolume = 220
end
if var1 == 4 then
airvolume = 320
end
if var1 == 5 then
airvolume = 520
end
if var1 == 6 then
airvolume = 620
end
print( " ####Fan read: "..var1)
print( " ####Airvolume: "..airvolume)
OutletTemp = otherdevices_svalues['Heatpump Outlet Temp']
InletTemp = otherdevices_svalues['Heatpump Inlet Temp']
inpower = tonumber(otherdevices_svalues['Heatpump Power/Energy'])
print( " ####Outlet temp: "..OutletTemp)
print( " ####Inlet temp: "..InletTemp)
print( " ####Power: "..inpower)
outpower = 300*1.293*1.01*(OutletTemp-InletTemp)
print( " ####Outpower: "..outpower)
calculation = outpower / inpower
print( " ####Cop debug: "..calculation)
COPidx = otherdevices_idx['Heatpump COP']
commandArray['UpdateDevice'] = COPidx..'|0|'..calculation
end
return commandArray
Re: COP calculation script
Posted: Wednesday 17 October 2018 10:34
by juuzo
Ok Now I got it work. Required some try and error methods. Here's the working script with some other additions.
Code: Select all
local debug = "1" -- Debug on = 1, off = 0
COPidx = otherdevices_idx['Heatpump COP']
commandArray = {}
time = os.date("*t")
if((time.min % 2)==0)then --Run every 2 minutes
if otherdevices['Heatpump Mode'] == "Heat" then
OutletTemp = otherdevices_svalues['Heatpump Outlet Temp']
InletTemp = otherdevices_svalues['Heatpump Inlet Temp']
inpower, energy = otherdevices_svalues['Heatpump Power/Energy']:match("([^;]+)")
var1 = otherdevices['Heatpump Fan Speed']
if var1 == "Auto" then
airvolume = 0 --If fan is in Auto mode, air flow could not be determined
elseif var1 == "1" then
airvolume = 406.80 --Fan speed 1 means 406.80m3/h air flow
elseif var1 == "2" then
airvolume = 475.80 --Fan speed 1 means 475.80m3/h air flow
elseif var1 == "3" then
airvolume = 684.60 --Fan speed 1 means 684.60m3/h air flow
elseif var1 == "4" then
airvolume = 900.00 --Fan speed 1 means 900.00m3/h air flow
elseif var1 == "5" then
airvolume = 954.60 --Fan speed 1 means 954.60m3/h air flow
else
print("####Ivalid FAN Speed") --If fan speed could not be read it is invalid and program terminated
return
end
inpowercompare = tonumber(string.format("%." .. (2) .. "f", inpower))
if inpowercompare > 165 then --Panasonic minimum input power in Heat mode
outpower = (OutletTemp-InletTemp)*airvolume*0.94*1.293*1.01--Assume that there is 6% error in air volume(0.96), 1.293 constant air density, 1.01 specific heat capacity for air
outpowercompare = tonumber(string.format("%." .. (2) .. "f", outpower))
if outpower > 0 then
rawcop = outpower/(inpower/1000*3600) --inpower*3600, power consumption in hour
cop = tonumber(string.format("%." .. (2) .. "f", rawcop))
else
print( "####Outpower negative, Heapump de-ice?...")
return
end
else
print( "####Inpower too low, Heapump COP calculation not updated...")
return
end
if (debug == "1") then
print( " ####Fan read: "..var1)
print( " ####Airvolume: "..airvolume)
print( " ####Outlet temp: "..OutletTemp)
print( " ####Inlet temp: "..InletTemp)
print( " ####Power: "..inpower)
print( " ####Outpower: "..outpower)
print( " ####Raw Cop calculation: "..rawcop)
print( " ####Cop: "..cop)
end
if cop < 12 then
if cop > -0.01 then
commandArray['UpdateDevice'] = COPidx..'|0|'..cop
print( "####Heatpump COP updated")
else
print ( "####COP too low, Heapump COP calculation not updated...")
end
else
print( "####COP too high, Heapump COP calculation not updated...")
end
else
print( "####Heatpump not in Heat mode...")
end
end
return commandArray
Re: COP calculation script
Posted: Friday 19 October 2018 10:46
by juuzo
I tested this scrip yesterday and noticed that I need some kind of averaging for this script. Have to resolve that next.
Re: COP calculation script
Posted: Tuesday 11 December 2018 19:27
by Derik
Dear...
Can you please tell me what airflow meter you have?
A china one?
What hardware do you use?
And where is the place you put the flowmeter?