Error: dzVents: Error: (3.0.2) ...moticz/scripts/dzVents/generated_scripts/Meteobridge.lua:114: attempt to index a nil value (field 'SOILA')
With the help of Waaren I created the next script:
Code: Select all
local url = 'http://www.website.com/domoticz.txt'
local scriptVar = 'get_meteoBridge'
return
{
on =
{
timer =
{
'every 5 minutes', -- change this to 5 minute after testing
},
devices =
{
'triggerhulp',
},
httpResponses =
{
scriptVar,
},
},
--logging =
--{
-- level = domoticz.LOG_DEBUG,
-- marker = scriptVar,
--},
execute = function(dz, item)
local temperatureBSensor = dz.devices(97) --indoor temperatuur
local temperatureSensor = dz.devices(82) --outside temperature
local rainSensor = dz.devices(83) -- rain
local windSensor = dz.devices(84) -- wind
local dewpointSensor = dz.devices(95) -- define as a combined Temperature, Humidity, Barometer sensor
local humiditySensor = dz.devices(96) -- Humidity sensor
local pressureSensor = dz.devices(86) -- barometer
local radiationSensor = dz.devices(89) -- radiation
local SoilATempSensor = dz.devices(90) -- soil temperature -5 cm
local SoilBTempSensor = dz.devices(91) -- soil temperature -10 cm
local SoilCTempSensor = dz.devices(92) -- soil temperature -15 cm
local SoilDTempSensor = dz.devices(93) -- grass temperature +10 cm
local SoilASensor = dz.devices(99) -- soil moisture -20 cm
local SoilBSensor = dz.devices(101) -- soil moisture -40 cm
local ETsensor = dz.devices(120) -- Evapotranspiration
local function windBearing2Direction(degrees)
local function between(value, center, variance)
variance = variance or 22.5
local value = tonumber(value)
return ( value >= (center - variance) or value <= (center + variance) )
end
if between(degrees, 45) then return 'NW'
elseif between(degrees, 90) then return 'W'
elseif between(degrees, 135) then return 'Sw'
elseif between(degrees, 180) then return 'S'
elseif between(degrees, 225) then return 'SE'
elseif between(degrees, 270) then return 'E'
elseif between(degrees, 315) then return 'NE'
end
return 'N'
end
local function humStatus(temperature, humidity)
if humidity <= 30 then return dz.HUM_DRY
elseif humidity >= 70 then return dz.HUM_WET
elseif humidity >= 35 and
humidity <= 65 and
temperature >= 22 and
temperature <= 26 then return dz.HUM_COMFORTABLE
else return dz.HUM_NORMAL end
end
function baroForecast(pressure)
if pressure == nil then return dz.BARO_NOINFO
elseif pressure < 1003 then return dz.BARO_RAIN
elseif pressure < 1013 then return dz.BARO_CLOUDY
elseif pressure < 1033 then return dz.BARO_PARTLYCLOUDY
end
return dz.BARO_SUNNY
end
if item.isHTTPResponse then
if item.ok then
rt = dz.utils.fromXML(item.data)
-- dz.log(item,dz.LOG_DEBUG)
-- dz.utils.dumpTable(rt)
-- get the values from the table and add missing values via weather functions
local temperatureB = tonumber(rt.logger.THB._attr.temp)
local temperature = tonumber(rt.logger.TH._attr.temp)
local dewpoint = rt.logger.TH._attr.dew
local rainTotal = rt.logger.RAIN._attr.total
local rainRate = rt.logger.RAIN._attr.rate
local windSpeed = rt.logger.WIND._attr.wind
local windBearing = rt.logger.WIND._attr.dir
local windChill = rt.logger.WIND._attr.chill
local windGust = rt.logger.WIND._attr.gust
local windDirection = windBearing2Direction(windBearing)
local humidity = tonumber(rt.logger.THB._attr.hum)
local humidityStatus = humStatus(temperature, humidity)
local pressure = tonumber(rt.logger.THB._attr.press)
local forecast = baroForecast(pressure)
local radiation = rt.logger.SOL._attr.rad
local soilmoistureA = tonumber(rt.logger.SOILA._attr.hum)
local soilmoistureB = tonumber(rt.logger.SOILB._attr.hum)
local SoilATemp = tonumber(rt.logger.SOILA._attr.temp)
local SoilBTemp = tonumber(rt.logger.SOILB._attr.temp)
local SoilCTemp = tonumber(rt.logger.SOILC._attr.temp)
local SoilDTemp = tonumber(rt.logger.SOILD._attr.temp)
local Evap = rt.logger.SOL._attr.evo
-- dz.log('Data from meteoBridge: ' ..
-- '\ntemperature: ' .. temperatureB ..
-- '\ntemperature: ' .. temperature ..
-- '\ndew: ' .. dewpoint ..
-- '\nrainTotal: ' .. rainTotal ..
-- '\nrainrate: ' .. rainRate ..
-- '\nrainrate: ' .. rainRate ..
-- '\nforecast: ' .. forecast
-- , dz.LOG_DEBUG)
-- update the weather sensors
dewpointSensor.updateTempHumBaro(dewpoint, humidity, humidityStatus, pressure, forecast)
pressureSensor.updatePressure(pressure)
humiditySensor.updateHumidity(humidity, humidityStatus)
rainSensor.updateRain(rainRate, rainTotal)
temperatureBSensor.updateTemperature(temperatureB)
temperatureSensor.updateTemperature(temperature)
windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)
radiationSensor.updateRadiation(radiation)
SoilASensor.updateSoilMoisture(soilmoistureA)
SoilBSensor.updateSoilMoisture(soilmoistureB)
SoilATempSensor.updateTemperature(SoilATemp)
SoilBTempSensor.updateTemperature(SoilBTemp)
SoilCTempSensor.updateTemperature(SoilCTemp)
SoilDTempSensor.updateTemperature(SoilDTemp)
ETsensor.updateCustomSensor(Evap)
else
dz.log('There was a problem handling the request', dz.LOG_ERROR)
dz.log(item, dz.LOG_ERROR)
end
return
end
dz.openURL(
{
url = url,
method = 'GET',
callback = scriptVar,
})
end
}
The data is "picked" from a file like this:
- Spoiler: show
Version:
Version: 2020.2
Build Hash: b63341bc0
Compile Date: 2020-04-26 13:47:55
dzVents Version: 3.0.2
Python Version: 3.7.3 (default, Dec 20 2019, 18:57:59) [GCC 8.3.0]