I bought a pyranometer (measures global radiation from the sun).
https://tweakers.net/i/Ut0QbXAs-PH2fCc1 ... lbum_large
The data is retrieved in domoticz via Modbus RTU in Watt/m². With a dzVents script I convert that to Joules/cm². That gives the global radiation per day. I can then test this against an official KNMI station 5 km away as the crow flies.
After a few months of testing, my pyranometer on average seems to indicate about 20% more than the official KNMI station. That is also the case when I compare it with 5 other KNMI stations within a radius of approximately 30 km. The thing comes from China and is therefore a bit expensive to send it back to have it recalibrated. So I want to do that with software. I have already worked out the formula for this.
I'm trying to do that in domoticz with this script:
Code: Select all
return
active = true,
on = {
devices =
[ 'Sun Power SEM228T' ] =
{'between 30 minutes before sunrise and 35 minutes after sunset'},
execute = function(domoticz, Sun_Power_SEM228T)
if domoticz.devices('Sun Power SEM228T').sValue >= 38 then
local SunPowerWatts50 = domoticz.devices('Sun Power SEM228T').sValue - 38
else
local SunPowerWatts50 = domoticz.devices('Sun Power SEM228T').sValue
end
domoticz.devices('Sun Power SEM228T 50').updateCustomSensor(SunPowerWatts50)
endWhat the script has to do is check whether the value of Sun Power SEM228T is above or equal to 38 Watt/m² and then subtract 38 Watt/m² form Sun Power SEM228T. If the value of 38 Watt/m² is not exceeded, the value of Sun Power SEM228T is adopted. The result then appears in Sun Power SEM228T 50.
The problem is that I keep getting this error message:
Code: Select all
2022-03-07 16:28:07.307 Error: dzVents: Error: (3.1.7) An error occurred when calling event handler Sun Power SEM228T 50
2022-03-07 16:28:07.307 Error: dzVents: Error: (3.1.7) ...omoticz/scripts/dzVents/scripts/Sun Power SEM228T 50.lua:13: attempt to compare number with stringCode: Select all
domoticz.devices('Sun Power SEM228T').sValue >= 38As soon as I comment out the if then else end with -- the line works
Code: Select all
local SunPowerWatts50 = domoticz.devices('Sun Power SEM228T').sValue - 38What I've already tried is to replace sValue with: state; _state; raw; rawData and sensorValue. But even then I keep getting the error that an attempt is being made to compare a string with a number.
Also tried this:
Code: Select all
return
{
active = true,
on = {
devices =
{
[ 'Test Total solar radiation' ] =
{'between 30 minutes before sunrise and 35 minutes after sunset'},
},
},
execute = function(domoticz, Sun_Power_SEM228T)
local SunPower50 = tonumber(domoticz.devices('Test Total solar radiation').sValue)
if SunPower50 >= 38.0 then
local SunPowerWatts50 = SunPower50 - 38
else
local SunPowerWatts50 = SunPower50
end
domoticz.devices('Sun Power SEM228T 50').updateCustomSensor(SunPowerWatts50)
end
}It does not give an error message anymore, but a value of 0
What am I doing wrong here? And how do I solve it?