Meteobridge and Domoticz

All about the standard Meteobridge devices based on mobile routers from TP-Link, D-Link, ASUS

Moderator: Mattk

Post Reply
doornenburgweer
Junior Boarder
Junior Boarder
Posts: 20
Joined: Mon Apr 08, 2013 8:18 pm

Meteobridge and Domoticz

Post by doornenburgweer »

Last week I finished an connection Meteobridge to Domotisz.The Meteobridge uploadfile (FTP) looks like this, with 5 minute upload

Code: Select all

<logger>
<TH date="[YYYY][MM][DD][hh][mm][ss]" id="th0" temp="[th0temp-act.1:---]" hum="[th0hum-act.0:---]" dew="[th0dew-act]"/> 
<THB date="[YYYY][MM][DD][hh][mm][ss]" id="thb0" temp="[thb0temp-act.1:---]" hum="[thb0hum-act.0:---]" dew="[thbdew-act]" press="[thb0seapress-act.1:--]"/>
<SOILA date="[YYYY][MM][DD][hh][mm][ss]" id="th10" temp="[th10temp-act.1:0]" hum="[th10hum-act.0:0]" lowbat="0"/>
<SOILB date="[YYYY][MM][DD][hh][mm][ss]" id="th11" temp="[th11temp-act.1:0]" hum="[th11hum-act.0:0]" lowbat="0"/>
<SOILC date="[YYYY][MM][DD][hh][mm][ss]" id="th12" temp="[th12temp-act.1:0]" hum="[th12hum-act.0:0]" lowbat="0"/>
<SOILD date="[YYYY][MM][DD][hh][mm][ss]" id="th13" temp="[th13temp-act.1:0]" hum="[th13hum-act.0:0]" lowbat="0"/>
<SOL date="[YYYY][MM][DD][hh][mm][ss]" id="sol0" rad="[sol0rad-act:--]"/> 
<WIND date="[YYYY][MM][DD][hh][mm][ss]" id="wind0" dir="[wind0dir-act]" gust="[wind0wind-max10]" wind="[wind0wind-act=bft.0]" chill="1[wind0chill-act]"/>
<RAIN date="[YYYY][MM][DD][hh][mm][ss]" id="rain0" " daytotal="[rain0total-daysum]" rate="[rain0rate-act]" total="[rain0total-yearsum]"/>  
</logger>
The DZvents script looks like this :

Code: Select all

local url = 'http://www.website.com/domoticz.txt'
-- thanks to Waaren ( Domoticz Dzvents forum)
local scriptVar = 'get_meteoBridge'

return
{
    on =
    {
        timer =
        {
            'every minute', -- 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 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)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperatureB ..
                    '\ntemperature: ' .. temperature ..
                    '\ndew: ' .. dewpoint ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nrad: ' .. radiation ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust ..
                    '\nhumidity: ' .. humidity ..
                    '\nhumidityStatus: ' .. humidityStatus ..
                    '\nbarometer: ' .. pressure ..
                    '\nsoil moisture A: ' .. soilmoistureA ..
                    '\nsoil moisture B: ' .. soilmoistureB ..
                    '\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)

            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
}
Post Reply