Page 2 of 2

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 18:23
by Doornenburgweer
Hi I am trying to use this script for a meteobridge file:
Spoiler: show
<logger>
<TH date="20200505162125" id="th0" temp="15.0" hum="42" dew="2.2" lowbat="0"/>
<THB date="20200505162115" id="thb0" temp="22.1" hum="48" dew="10.6" press="1018.8" seapress="1020.4" fc="2" lowbat="0"/>
<SOL date="20200505162147" id="sol0" rad="209" lowbat="0"/>
<WIND date="20200505162143" id="wind0" dir="63" gust="0.0" wind="0.9" chill="15.0" lowbat="0"/>
<RAIN date="20200505162117" id="rain0" rate="0.0" total="225.6" delta="0.0" lowbat="0"/>
<SOIL date="19700101000000" id="th12" temp="0.2" hum="0" lowbat="14194896"/>
<SOIL date="20200502052252" id="th11" temp="0.0" hum="200" lowbat="0"/>
<SOIL date="20200504073857" id="th10" temp="0.0" hum="200" lowbat="0"/>
</logger>
and I see this in the status log
Spoiler: show
2020-05-05 18:19:00.182 Status: dzVents: Info: getXML: ------ Start internal script: Weatherstation:, trigger: "every minute at daytime"
2020-05-05 18:19:00.182 Status: dzVents: Debug: getXML: OpenURL: url = http://meteobridge:[email protected]. ... ataxml.cgi
2020-05-05 18:19:00.182 Status: dzVents: Debug: getXML: OpenURL: method = GET
2020-05-05 18:19:00.182 Status: dzVents: Debug: getXML: OpenURL: post data = nil
2020-05-05 18:19:00.182 Status: dzVents: Debug: getXML: OpenURL: headers = nil
2020-05-05 18:19:00.182 Status: dzVents: Debug: getXML: OpenURL: callback = getXML
2020-05-05 18:19:00.183 Status: dzVents: Info: getXML: ------ Finished Weatherstation
2020-05-05 18:19:00.183 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-05 18:19:00.439 Status: dzVents: Info: Handling httpResponse-events for: "getXML"
2020-05-05 18:19:00.439 Status: dzVents: Info: getXML: ------ Start internal script: Weatherstation: HTTPResponse: "getXML"
2020-05-05 18:19:00.446 Status: dzVents: > logger:
2020-05-05 18:19:00.446 Status: dzVents: > TH:
2020-05-05 18:19:00.446 Status: dzVents: > _attr:
2020-05-05 18:19:00.446 Status: dzVents: > hum: 41
2020-05-05 18:19:00.446 Status: dzVents: > id: th0
2020-05-05 18:19:00.446 Status: dzVents: > date: 20200505161801
2020-05-05 18:19:00.446 Status: dzVents: > dew: 1.9
2020-05-05 18:19:00.446 Status: dzVents: > lowbat: 0
2020-05-05 18:19:00.446 Status: dzVents: > temp: 15.0
2020-05-05 18:19:00.446 Status: dzVents: > WIND:
2020-05-05 18:19:00.446 Status: dzVents: > _attr:
2020-05-05 18:19:00.446 Status: dzVents: > id: wind0
2020-05-05 18:19:00.446 Status: dzVents: > chill: 15.0
2020-05-05 18:19:00.446 Status: dzVents: > date: 20200505161851
2020-05-05 18:19:00.446 Status: dzVents: > gust: 1.3
2020-05-05 18:19:00.446 Status: dzVents: > wind: 0.9
2020-05-05 18:19:00.446 Status: dzVents: > dir: 84
2020-05-05 18:19:00.446 Status: dzVents: > lowbat: 0
2020-05-05 18:19:00.446 Status: dzVents: > SOIL:
2020-05-05 18:19:00.446 Status: dzVents: > 1:
2020-05-05 18:19:00.446 Status: dzVents: > _attr:
2020-05-05 18:19:00.446 Status: dzVents: > id: th12
2020-05-05 18:19:00.446 Status: dzVents: > date: 19700101000000
2020-05-05 18:19:00.446 Status: dzVents: > hum: 0
2020-05-05 18:19:00.446 Status: dzVents: > lowbat: 14194896
2020-05-05 18:19:00.446 Status: dzVents: > temp: 0.2
2020-05-05 18:19:00.446 Status: dzVents: > 2:
2020-05-05 18:19:00.447 Status: dzVents: > _attr:
2020-05-05 18:19:00.447 Status: dzVents: > id: th11
2020-05-05 18:19:00.447 Status: dzVents: > date: 20200502052252
2020-05-05 18:19:00.447 Status: dzVents: > hum: 200
2020-05-05 18:19:00.447 Status: dzVents: > lowbat: 0
2020-05-05 18:19:00.447 Status: dzVents: > temp: 0.0
2020-05-05 18:19:00.447 Status: dzVents: > 3:
2020-05-05 18:19:00.447 Status: dzVents: > _attr:
2020-05-05 18:19:00.447 Status: dzVents: > id: th10
2020-05-05 18:19:00.447 Status: dzVents: > date: 20200504073857
2020-05-05 18:19:00.447 Status: dzVents: > hum: 200
2020-05-05 18:19:00.447 Status: dzVents: > lowbat: 0
2020-05-05 18:19:00.447 Status: dzVents: > temp: 0.0
2020-05-05 18:19:00.447 Status: dzVents: > SOL:
2020-05-05 18:19:00.447 Status: dzVents: > _attr:
2020-05-05 18:19:00.447 Status: dzVents: > rad: 213
2020-05-05 18:19:00.447 Status: dzVents: > id: sol0
2020-05-05 18:19:00.447 Status: dzVents: > date: 20200505161821
2020-05-05 18:19:00.447 Status: dzVents: > lowbat: 0
But I try to find the next step.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 19:37
by waaren
Doornenburgweer wrote: Tuesday 05 May 2020 18:23 Hi I am trying to use this script for a meteobridge file:
But I try to find the next step.
Can you show the script as you use it now?
What domoticz version do you use?
Which domoticz virtual devices (name, type and subtype) do you want to update with the data from the meteobridge ?

can you add the the line
dz.log(item, dz.LOG_DEBUG) as first line after the "execute =" and show the result?

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 20:02
by Doornenburgweer
Oh man, that is a quick response, thank you, I am just new in this forum. I added the line dz.log(item, dz.LOG_DEBUG) and this is the result:
Spoiler: show

Code: Select all

2020-05-05 19:58:00.431 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-05 19:58:00.578 Status: dzVents: Info: Handling httpResponse-events for: "getXML"
2020-05-05 19:58:00.578 Status: dzVents: Info: getXML: ------ Start internal script: Weatherstation: HTTPResponse: "getXML"
2020-05-05 19:58:00.579 Status: dzVents: Debug: getXML: {["isSecurity"]=false, ["statusCode"]=200, ["data"]="<logger>
2020-05-05 19:58:00.579 <TH date="20200505175711" id="th0" temp="14.1" hum="46" dew="2.6" lowbat="0" />
2020-05-05 19:58:00.579 <THB date="20200505175711" id="thb0" temp="22.3" hum="48" dew="10.8" press="1018.8" seapress="1020.4" fc="2" lowbat="0" />
2020-05-05 19:58:00.579 <SOL date="20200505175741" id="sol0" rad="18" lowbat="0" />
2020-05-05 19:58:00.579 <WIND date="20200505175755" id="wind0" dir="0" gust="0.0" wind="0.0" chill="14.1" lowbat="0" />
2020-05-05 19:58:00.579 <RAIN date="20200505175741" id="rain0" rate="0.0" total="225.6" delta="0.0" lowbat="0" />
2020-05-05 19:58:00.579 <SOIL date="19700101000000" id="th12" temp="0.2" hum="0" lowbat="14194896" />
2020-05-05 19:58:00.579 <SOIL date="20200502052252" id="th11" temp="0.0" hum="200" lowbat="0" />
2020-05-05 19:58:00.579 <SOIL date="20200504073857" id="th10" temp="0.0" hum="200" lowbat="0" />
2020-05-05 19:58:00.579 </logger>
2020-05-05 19:58:00.579 ", ["statusText"]="OK", ["callback"]="getXML", ["ok"]=true, ["isScene"]=false, ["isHTTPResponse"]=true, ["isTimer"]=false, ["trigger"]="getXML", ["isHardware"]=false, ["baseType"]="httpResponse", ["isSystem"]=false, ["isXML"]=false, ["isCustomEvent"]=false, ["_contentType"]="text/plain", ["isGroup"]=false, ["isDevice"]=false, ["isJSON"]=false, ["headers"]={["Content-Length"]="23", ["Access-Control-Allow-Origin"]="*", ["Connection"]="close", ["Content-type"]="text/xml; charset=UTF-8", ["WWW-Authenticate"]="Basic realm="MeteoBridge"", ["Content-Type"]="text/plain", ["Transfer-Encoding"]="chunked"}, ["isVariable"]=false, ["protocol"]="HTTP/1.1"}
2020-05-05 19:58:00.587 Status: dzVents: > logger:
2020-05-05 19:58:00.587 Status: dzVents: > WIND:
2020-05-05 19:58:00.587 Status: dzVents: > _attr:
2020-05-05 19:58:00.587 Status: dzVents: > date: 20200505175755
2020-05-05 19:58:00.587 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.587 Status: dzVents: > dir: 0
2020-05-05 19:58:00.587 Status: dzVents: > id: wind0
2020-05-05 19:58:00.587 Status: dzVents: > gust: 0.0
2020-05-05 19:58:00.587 Status: dzVents: > chill: 14.1
2020-05-05 19:58:00.587 Status: dzVents: > wind: 0.0
2020-05-05 19:58:00.587 Status: dzVents: > RAIN:
2020-05-05 19:58:00.587 Status: dzVents: > _attr:
2020-05-05 19:58:00.587 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.587 Status: dzVents: > delta: 0.0
2020-05-05 19:58:00.587 Status: dzVents: > id: rain0
2020-05-05 19:58:00.588 Status: dzVents: > date: 20200505175741
2020-05-05 19:58:00.588 Status: dzVents: > total: 225.6
2020-05-05 19:58:00.588 Status: dzVents: > rate: 0.0
2020-05-05 19:58:00.588 Status: dzVents: > TH:
2020-05-05 19:58:00.588 Status: dzVents: > _attr:
2020-05-05 19:58:00.588 Status: dzVents: > temp: 14.1
2020-05-05 19:58:00.588 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.588 Status: dzVents: > hum: 46
2020-05-05 19:58:00.588 Status: dzVents: > id: th0
2020-05-05 19:58:00.588 Status: dzVents: > date: 20200505175711
2020-05-05 19:58:00.588 Status: dzVents: > dew: 2.6
2020-05-05 19:58:00.588 Status: dzVents: > THB:
2020-05-05 19:58:00.588 Status: dzVents: > _attr:
2020-05-05 19:58:00.588 Status: dzVents: > press: 1018.8
2020-05-05 19:58:00.588 Status: dzVents: > date: 20200505175711
2020-05-05 19:58:00.588 Status: dzVents: > dew: 10.8
2020-05-05 19:58:00.588 Status: dzVents: > fc: 2
2020-05-05 19:58:00.588 Status: dzVents: > hum: 48
2020-05-05 19:58:00.588 Status: dzVents: > id: thb0
2020-05-05 19:58:00.588 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.588 Status: dzVents: > seapress: 1020.4
2020-05-05 19:58:00.588 Status: dzVents: > temp: 22.3
2020-05-05 19:58:00.588 Status: dzVents: > SOIL:
2020-05-05 19:58:00.588 Status: dzVents: > 1:
2020-05-05 19:58:00.588 Status: dzVents: > _attr:
2020-05-05 19:58:00.588 Status: dzVents: > temp: 0.2
2020-05-05 19:58:00.588 Status: dzVents: > hum: 0
2020-05-05 19:58:00.588 Status: dzVents: > id: th12
2020-05-05 19:58:00.588 Status: dzVents: > date: 19700101000000
2020-05-05 19:58:00.588 Status: dzVents: > lowbat: 14194896
2020-05-05 19:58:00.588 Status: dzVents: > 2:
2020-05-05 19:58:00.588 Status: dzVents: > _attr:
2020-05-05 19:58:00.588 Status: dzVents: > temp: 0.0
2020-05-05 19:58:00.588 Status: dzVents: > hum: 200
2020-05-05 19:58:00.588 Status: dzVents: > id: th11
2020-05-05 19:58:00.588 Status: dzVents: > date: 20200502052252
2020-05-05 19:58:00.589 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.589 Status: dzVents: > 3:
2020-05-05 19:58:00.589 Status: dzVents: > _attr:
2020-05-05 19:58:00.589 Status: dzVents: > temp: 0.0
2020-05-05 19:58:00.589 Status: dzVents: > hum: 200
2020-05-05 19:58:00.589 Status: dzVents: > id: th10
2020-05-05 19:58:00.589 Status: dzVents: > date: 20200504073857
2020-05-05 19:58:00.589 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.589 Status: dzVents: > SOL:
2020-05-05 19:58:00.589 Status: dzVents: > _attr:
2020-05-05 19:58:00.589 Status: dzVents: > rad: 18
2020-05-05 19:58:00.589 Status: dzVents: > id: sol0
2020-05-05 19:58:00.589 Status: dzVents: > date: 20200505175741
2020-05-05 19:58:00.589 Status: dzVents: > lowbat: 0
2020-05-05 19:58:00.589 Status: dzVents: Info: getXML: ------ Finished Weatherstation
The used script at the moment, your scrip is:

Code: Select all

local url = 'http://meteobridge:meteobridge@internIP/cgi-bin/livedataxml.cgi'

local scriptVar = 'getXML' 

return 
{
    on = 
    {
        timer = 
        {
            'every minute at daytime',
        },
        
        devices = 
        {
            'triggerhulp',
        },
    
        httpResponses =
        {
            scriptVar,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },
    
    execute = function(dz, item)
        dz.log(item, dz.LOG_DEBUG)

        if item.isHTTPResponse then
            if item.ok then
                --dz.log(item,dz.LOG_DEBUG)
                rt = dz.utils.fromXML(item.data)
                dz.utils.dumpTable(rt)
            else
                dz.log('There was a problem handling the request', dz.LOG_ERROR)
                dz.log(item, dz.LOG_ERROR)
            end
            return

            -- tempdevice = domoticz.devices('WetterAußen') 
        end

        dz.openURL(
        {
            url = url, 
            method = 'GET',
            callback = scriptVar,
        })
    end
}

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 20:08
by Doornenburgweer
the Domoticz 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

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 20:45
by Doornenburgweer
Sorry, I jsut saw your other question about the virtual devices just now. See here the first ones:

Code: Select all

82	weerstation	140A2	1	Temperatuur Davis	Temp	LaCrosse TX3	
83	weerstation	140A3	1	Regen Davis	Rain	TFA	0;0	-	
84	weerstation	140A4	1	Wind Davis	Wind	WTGR800	0;N;0;0;0;0	

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 05 May 2020 22:29
by waaren
Doornenburgweer wrote: Tuesday 05 May 2020 20:45 I just saw your other question about the virtual devices just now. See here the first ones:

Code: Select all

82	weerstation	140A2	1	Temperatuur Davis	Temp	LaCrosse TX3	
83	weerstation	140A3	1	Regen Davis	Rain	TFA	0;0	-	
84	weerstation	140A4	1	Wind Davis	Wind	WTGR800	0;N;0;0;0;0	
Script could look like below. It should help you to extend the functionality. Please visit the wiki for specifics on how to update other deviceTypes.

Any questions; please feel free to ask

When not yet familiar with dzVents please start with reading Get started Before implementing (~ 5 minutes). Special attention please for "In Domoticz go to Setup > Settings > Other and in the section EventSystem make sure the checkbox 'dzVents enabled' is checked. Also make sure that in the Security section in the settings you allow 127.0.0.1 to not need a password. dzVents uses that port to send certain commands to Domoticz. Finally make sure you have set your current location in Setup > Settings > System > Location, otherwise there is no way to determine nighttime/daytime state."

Code: Select all

local url = 'http://meteobridge:meteobridge@internIP/cgi-bin/livedataxml.cgi'
local scriptVar = 'get_meteoBridge'

return
{
    on =
    {
        timer =
        {
            'every minute at daytime',
        },

        devices =
        {
            'triggerhulp',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local temperatureSensor = dz.devices('Temperatuur Davis')
        local rainSensor = dz.devices('Regen Davis')
        local windSensor = dz.devices('Wind Davis')

        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

        if item.isHTTPResponse then
            if item.ok then
                rt = dz.utils.fromXML(item.data)

                -- dz.log(item,dz.LOG_DEBUG)
                -- dz.utils.dumpTable(rt)

                local temperature = rt.logger.THB._attr.temp
                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)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperature ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust
                    , dz.LOG_DEBUG)

                rainSensor.updateRain(rainRate, rainTotal)
                temperatureSensor.updateTemperature(temperature)
                windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)
            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
}

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Wednesday 06 May 2020 8:27
by Doornenburgweer
Thanks it works excellent.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Wednesday 06 May 2020 23:35
by Doornenburgweer
Hi, still a small problem. I started to use more parameters, also humidity. As copycat I made this

Code: Select all

local url = 'http://meteobridgeIP/cgi-bin/livedataxml.cgi'

local scriptVar = 'get_meteoBridge'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },

        devices =
        {
            'triggerhulp',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local temperatureSensor = dz.devices('Temperatuur Davis')
        local rainSensor = dz.devices('Regen Davis')
        local windSensor = dz.devices('Wind Davis')
        local dewSensor = dz.devices('Dauwpunt')
        local humSensor = dz.devices('Relatieve luchtvochtigheid')
     --   local windSensor = dz.devices('Wind Davis')
                        
        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 humidityStatus(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

        if item.isHTTPResponse then
            if item.ok then
                rt = dz.utils.fromXML(item.data)

                -- dz.log(item,dz.LOG_DEBUG)
                -- dz.utils.dumpTable(rt)

                local temperature = rt.logger.TH._attr.temp
                local dewpoint = rt.logger.TH._attr.dew
                local humidity = rt.logger.TH._attr.hum                
                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)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperature ..
                    '\nhumidity: ' .. humidity ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust
                    , dz.LOG_DEBUG)

                humidity.updateHumidity(humidity)
                rainSensor.updateRain(rainRate, rainTotal)
                temperatureSensor.updateTemperature(temperature)
                dewSensor.updateTemperature(dewpoint)
                windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)
            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
}
and this is a part of the Status log file
Spoiler: show

Code: Select all

2020-05-06 23:28:00.218 Status: dzVents: Info: get_meteoBridge: ------ Start internal script: Meteobridge:, trigger: "every minute"
2020-05-06 23:28:00.236 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Temperatuur Davis: Temperature device adapter
2020-05-06 23:28:00.238 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Regen Davis: Rain device
2020-05-06 23:28:00.239 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Wind Davis: Wind device adapter
2020-05-06 23:28:00.240 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Dauwpunt: Temperature device adapter
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Relatieve luchtvochtigheid: Humidty device adapter
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: OpenURL: url = http://meteobridgeIP/cgi-bin/livedataxml.cgi
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: OpenURL: method = GET
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: OpenURL: post data = nil
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: OpenURL: headers = nil
2020-05-06 23:28:00.241 Status: dzVents: Debug: get_meteoBridge: OpenURL: callback = get_meteoBridge
2020-05-06 23:28:00.241 Status: dzVents: Info: get_meteoBridge: ------ Finished Meteobridge
2020-05-06 23:28:00.242 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-05-06 23:28:00.543 Status: dzVents: Info: Handling httpResponse-events for: "get_meteoBridge"
2020-05-06 23:28:00.543 Status: dzVents: Info: get_meteoBridge: ------ Start internal script: Meteobridge: HTTPResponse: "get_meteoBridge"
2020-05-06 23:28:00.544 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Temperatuur Davis: Temperature device adapter
2020-05-06 23:28:00.545 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Regen Davis: Rain device
2020-05-06 23:28:00.546 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Wind Davis: Wind device adapter
2020-05-06 23:28:00.547 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Dauwpunt: Temperature device adapter
2020-05-06 23:28:00.548 Status: dzVents: Debug: get_meteoBridge: Processing device-adapter for Relatieve luchtvochtigheid: Humidty device adapter
2020-05-06 23:28:00.554 Status: dzVents: Debug: get_meteoBridge: Data from meteoBridge:
2020-05-06 23:28:00.554 temperature: 11.1
2020-05-06 23:28:00.554 humidity: 74
2020-05-06 23:28:00.554 rainTotal: 225.6
2020-05-06 23:28:00.554 rainrate: 0.0
2020-05-06 23:28:00.554 wind: 0.0
2020-05-06 23:28:00.554 windBearing: 20
2020-05-06 23:28:00.554 windDirection: NW
2020-05-06 23:28:00.554 windChill: 11.1
2020-05-06 23:28:00.554 windGust: 0.0
2020-05-06 23:28:00.554 Status: dzVents: Info: get_meteoBridge: ------ Finished Meteobridge
but the error message is like this

Code: Select all

2020-05-06 23:34:00.721 Error: dzVents: Error: (3.0.2) get_meteoBridge: An error occurred when calling event handler Meteobridge
2020-05-06 23:34:00.721 Error: dzVents: Error: (3.0.2) get_meteoBridge: ...moticz/scripts/dzVents/generated_scripts/Meteobridge.lua:98: attempt to call a nil value (field 'updateHumidity')
. I tried many things :another deveice type, but no(t yet) an succes to get the humidity on the dashboard.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Thursday 07 May 2020 1:48
by waaren
Doornenburgweer wrote: Wednesday 06 May 2020 23:35 Hi, still a small problem. I started to use more parameters, also humidity.

I tried many things :another device type, but no(t yet) an succes to get the humidity on the dashboard.
new devicetypes are humidity for the humidity sensor and combined Temperature, Humidity, Barometer for the dewpoint sensor

Code: Select all

local url = 'http://meteobridgeIP/cgi-bin/livedataxml.cgi'

local scriptVar = 'get_meteoBridge'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },

        devices =
        {
            'triggerhulp',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local temperatureSensor = dz.devices('Temperatuur Davis')
        local rainSensor = dz.devices('Regen Davis')
        local windSensor = dz.devices('Wind Davis')
        local dewpointSensor = dz.devices('Dauwpunt')  -- define as a combined Temperature, Humidity, Barometer sensor
        local humiditySensor = dz.devices('Relatieve luchtvochtigheid') -- Humidity sensor

        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
            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 temperature = tonumber(rt.logger.THB._attr.temp)
                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.seapress)
                local forecast = baroForecast(pressure)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperature ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust ..
                    '\nhumidity: ' .. humidity ..
                    '\nhumidityStatus: ' .. humidityStatus ..
                    '\nbarometer: ' .. pressure ..
                    '\nforecast: ' .. forecast
                    , dz.LOG_DEBUG)

                -- update the weather sensors
                dewpointSensor.updateTempHumBaro(temperature, humidity, humidityStatus, pressure, forecast)
                humiditySensor.updateHumidity(humidity, humidityStatus)
                rainSensor.updateRain(rainRate, rainTotal)
                temperatureSensor.updateTemperature(temperature)
                windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)

            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
}

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Thursday 07 May 2020 8:15
by Doornenburgweer
]Thanks, still some issues with humidity. the dewpoint (Dauwpunt) sensor is ( I believe) a temperature sensor and when I use this script with dewpoint as temperature device it works.

Code: Select all

local url = 'http://meteobridgePI/cgi-bin/livedataxml.cgi'

local scriptVar = 'get_meteoBridge'

return
{
    on =
    {
        timer =
        {
            'every minute',
        },

        devices =
        {
            'triggerhulp',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    execute = function(dz, item)

        local temperatureSensor = dz.devices('Temperatuur Davis')
        local rainSensor = dz.devices('Regen Davis')
        local windSensor = dz.devices('Wind Davis')
        local dewSensor = dz.devices('Dauwpunt')  --temp sensor
        --local humSensor = dz.devices('Relatieve luchtvochtigheid')
     --   local windSensor = dz.devices('Wind Davis')
                        
        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 humidityStatus(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

        if item.isHTTPResponse then
            if item.ok then
                rt = dz.utils.fromXML(item.data)

                -- dz.log(item,dz.LOG_DEBUG)
                -- dz.utils.dumpTable(rt)

                local temperature = rt.logger.TH._attr.temp
                local dewpoint = rt.logger.TH._attr.dew
                local humidity = rt.logger.TH._attr.hum                
                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)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperature ..
                    '\nhumidity: ' .. humidity ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust
                    , dz.LOG_DEBUG)

               -- humidity.updateHumidity(humidity)
                rainSensor.updateRain(rainRate, rainTotal)
                temperatureSensor.updateTemperature(temperature)
                dewSensor.updateTemperature(dewpoint)
                windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)
            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
}
. I had the Humdity device as a humidity device, but that gave some issues. Will work on it more this evening. But thanks for your help alerady.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Thursday 07 May 2020 11:08
by waaren
Doornenburgweer wrote: Thursday 07 May 2020 8:15 ]Thanks, still some issues with humidity. the dewpoint (Dauwpunt) sensor is ( I believe) a temperature sensor and when I use this script with dewpoint as temperature device it works.
:?: This is not the (tested and working) script I posted in my last post.
Please note the virtual devices must be the types that I wrote in the comments. If you use different types, the dzVents update methods are no longer aligned with the device types.

different device type => different dzVents device.update method

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Thursday 07 May 2020 18:01
by Doornenburgweer
okay thanks, will check it out more this evening. thanks

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Saturday 09 May 2020 10:13
by Doornenburgweer
thanks Waaren. I played more with your code and now I get almost all the data with this script ( your script!)

Code: Select all

local url = 'http://IPMeteobridgelocal with userand password/cgi-bin/livedataxml.cgi'

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 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 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 temperature = tonumber(rt.logger.TH._attr.temp) -- outside temperature
                local dewpoint = rt.logger.TH._attr.dew -- outside dewpoint
                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)

                dz.log('Data from meteoBridge: ' ..
                    '\ntemperature: ' .. temperature ..
                    '\ndew: ' .. dewpoint ..
                    '\nrainTotal: ' .. rainTotal ..
                    '\nrainrate: ' .. rainRate ..
                    '\nwind: ' .. windSpeed ..
                    '\nwindBearing: ' .. windBearing ..
                    '\nwindDirection: ' .. windDirection ..
                    '\nwindChill: ' .. windChill ..
                    '\nwindGust: ' .. windGust ..
                    '\nhumidity: ' .. humidity ..
                    '\nhumidityStatus: ' .. humidityStatus ..
                    '\nbarometer: ' .. pressure ..
                    '\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)
                temperatureSensor.updateTemperature(temperature)
                windSensor.updateWind(windBearing, windDirection, windSpeed, windGust, temperature, windChill)

            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
}
Now my next step: the Soiltemperature and soil moisture out of this file

Code: Select all

<logger>
<TH date="20200509081001" id="th0" temp="19.6" hum="49" dew="8.6" lowbat="0"/>
<THB date="20200509080929" id="thb0" temp="23.2" hum="46" dew="10.9" press="1011.8" seapress="1013.3" fc="2" lowbat="0"/>
<SOL date="20200509080925" id="sol0" rad="374" lowbat="0"/>
<WIND date="20200509080937" id="wind0" dir="45" gust="0.0" wind="0.4" chill="19.6" lowbat="0"/>
<RAIN date="20200509081001" id="rain0" rate="0.0" total="225.6" delta="0.0" lowbat="0"/>
<SOIL date="20200509081001" id="th10" temp="18.3" hum="14" lowbat="0"/>
<SOIL date="20200509080917" id="th11" temp="18.9" hum="25" lowbat="0"/>
<SOIL date="20200509081001" id="th13" temp="19.4" hum="255" lowbat="0"/>
<SOIL date="20200509081001" id="th12" temp="18.9" hum="255" lowbat="0"/>
</logger>
. The ID has different numbers. That is my job for the coming days.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Saturday 09 May 2020 10:19
by Doornenburgweer
Solved. I made another Meteobridge xml file (uploaded with FTP by Meteobridge) to my website.
Spoiler: show
<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>
and used with the great help of Waaren the next script
Spoiler: show
local url = 'http://www.website.com/domoticz.txt'

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
}
. Thanks!

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 30 June 2020 20:39
by sailmich
I get error in my domoticz event system.

2020-06-30 20:25:01.399 Error: dzVents: Error: (3.0.9) getXML: An error occurred when calling event handler Wetterstation
2020-06-30 20:25:01.399 Error: dzVents: Error: (3.0.9) getXML: ...domoticz/dzVents/runtime/device-adapters/wind_device.lua:27: attempt to perform arithmetic on a string value (local 'speed')
Code I used and working for long time
Spoiler: show

Code: Select all

local url = 'http://xxx.xxx.xxx.xx/current.xml'
local scriptVar = 'getXML' 

return 
{
    on = 
    {
        timer = 
        {
            'every 1 minutes at daytime',
        },
        
        devices = 
        {
            'DFhoch1',
        },
    
        httpResponses =
        {
            scriptVar,
        },
    },

    logging = 
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data = 
    {
        equalCounter = { initial = 0 },
        stationTime = { initial  = '' },
    },

    execute = function(dz, item)

        local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)
            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}
            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_DEBUG)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end
            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local function wind2Degrees(direction)
            if direction == 'N' then degrees = 360 end
            if direction == 'NE' then degrees = 315 end
            if direction == 'E' then degrees = 270 end
            if direction == 'SE' then degrees = 225 end
            if direction == 'S' then degrees = 180 end
            if direction == 'SW' then degrees = 135 end
            if direction == 'W' then degrees = 90 end
            if direction == 'NW' then degrees = 45 end
            return '-'
        end
    
        local function humidityStatus(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

        local function getData(data)
            resultTable = dz.utils.fromXML(data).maintag.realtime
            relevantData = {}
            for index, record in ipairs(resultTable) do
                --dz.log((record.data._attr.realtime or record.data._attr.units) .. ': ' .. record.data[1],dz.log_DEBUG)
                relevantData[(record.data._attr.realtime or record.data._attr.units)] =  record.data[1]
            end
            return(relevantData)
        end
        
        function baroForecast(pressure)                                               -- Return text
            if pressure == nil          then return nil                                               -- Should not happen
                elseif pressure < 966   then return dz.BARO_THUNDERSTORM
                elseif pressure < 993   then return dz.BARO_CLOUDY_RAIN
                elseif pressure < 1007  then return dz.BARO_CLOUDY
                elseif pressure < 1013  then return dz.BARO_UNSTABLE
                elseif pressure < 1033  then return dz.BARO_STABLE
            end
            return dz.BARO_SUNNY            
        end

        local function updateDevices(data)
            local rain = dz.devices('Regen')                   -- devicetype Rain 
            local temperature = dz.devices('WetterAußen')      -- devicetype Temperature 
            local wind = dz.devices('Boen')                    -- devicetype Wind 
            local humidity = dz.devices('Humidity')            -- devicetype Humidity  
            local barometer = dz.devices('BaroAußen')          -- devicetype Barometer
            local temperatureI = dz.devices('WetterInnen')
            local radiation = dz.devices('radiation')
            local UV = dz.devices('UV')
            local gust =dz.devices('Gust')
            local rainnow = dz.devices('Regenfall')
            
            temperature.updateTemperature(data.temp)
            wind.updateWind(wind2Degrees(data.winddir),data.winddir, data.windspeed, data.windGust, data.temp, data.windchill)
            rain.updateRain(data.rain_rate, data.todaysrain )
            humidity.updateHumidity(tonumber(data.hum), humidityStatus(tonumber(data.temp), tonumber(data.hum)))
            barometer.updateBarometer(data.barometer, baroForecast(tonumber(data.barometer)))
            temperatureI.updateTemperature(data.temp)
            radiation.updateRadiation(data.radiation)
            UV.updateUV(data.UV)
            gust.updateCustomSensor(data.windGust)
            rainnow.updateCustomSensor(data.rain_rate)
            
        end
        
        if item.isHTTPResponse then
            if item.ok then
                local rt = getData(item.data)
                if dz.data.stationTime == rt.station_time then dz.data.equalCounter = dz.data.equalCounter + 1
                    dz.log('Received old data. Skipping this reading', dz.LOG_ERROR)
                    if dz.data.equalCounter > 5 then 
                        dz.log('Received old data for >= 5 consecutive times. Booting weatherpi', dz.LOG_ERROR)
                        osCommand('ssh bootCommand') 
                    end
                    return
                end    
                dz.data.stationTime = rt.station_time
                dz.data.equalCounter = 0
                updateDevices(rt)
            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
}
/domoticz/dzVents/runtime/device-adapters
Spoiler: show

Code: Select all

return {

        baseType = 'device',

        name = 'Wind device adapter',

        matches = function (device, adapterManager)
                local res = (device.deviceType == 'Wind')
                if (not res) then
                        adapterManager.addDummyMethod(device, 'updateWind')
                end
                return res
        end,

        process = function (device, data, domoticz, utils, adapterManager)

                device.speedMs = utils.round(tonumber(device.rawData[3]) / 10, 1)
                device.gustMs = utils.round(tonumber(device.rawData[4]) / 10, 1)

                device.gust = tonumber(device.rawData[4]) / 10     -- Until gust is in data ( like speed already is ) we take it from sValues
                device.temperature = tonumber(device.rawData[5])
                device.chill = tonumber(device.rawData[6])

                function device.updateWind(bearing, direction, speed, gust, temperature, chill)
                        local value = tostring(bearing) .. ';' ..
                                tostring(direction) .. ';' ..
                                tostring(speed * 10) .. ';' ..
                                tostring(gust * 10) .. ';' ..
                                tostring(temperature) .. ';' ..
                                tostring(chill)
                        return device.update(0, value)
                end
        end

}

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 30 June 2020 22:07
by waaren
sailmich wrote: Tuesday 30 June 2020 20:39 I get error in my domoticz event system.

2020-06-30 20:25:01.399 Error: dzVents: Error: (3.0.9) getXML: An error occurred when calling event handler Wetterstation
2020-06-30 20:25:01.399 Error: dzVents: Error: (3.0.9) getXML: ...domoticz/dzVents/runtime/device-adapters/wind_device.lua:27: attempt to perform arithmetic on a string value (local 'speed')
Can you try again with this amended one?

Code: Select all

local url = 'http://xxx.xxx.xxx.xx/current.xml'
local scriptVar = 'getXML'

return
{
    on =
    {
        timer =
        {
            'every 1 minutes at daytime',
        },

        devices =
        {
            'DFhoch1',
        },

        httpResponses =
        {
            scriptVar,
        },
    },

    logging =
    {
        level = domoticz.LOG_DEBUG,
        marker = scriptVar,
    },

    data =
    {
        equalCounter = { initial = 0 },
        stationTime = { initial  = '' },
    },

    execute = function(dz, item)

        local function osCommand(cmd)
            dz.log('Executing Command: ' .. cmd,dz.LOG_DEBUG)
            local fileHandle = assert(io.popen(cmd .. ' 2>&1 || echo ::ERROR::', 'r'))
            local commandOutput = assert(fileHandle:read('*a'))
            local returnTable = {fileHandle:close()}
            if commandOutput:find '::ERROR::' then     -- something went wrong
               dz.log('Error ==>> ' .. tostring(commandOutput:match('^(.*)%s+::ERROR::') or ' ... but no error message ' ) ,dz.LOG_DEBUG)
            else -- all is fine!!
                dz.log('ReturnCode: ' .. returnTable[3] .. '\ncommandOutput:\n' .. commandOutput, dz.LOG_DEBUG)
            end
            return commandOutput,returnTable[3] -- rc[3] contains returnCode
        end

        local function wind2Degrees(direction)
            if direction == 'N' then degrees = 360 end
            if direction == 'NE' then degrees = 315 end
            if direction == 'E' then degrees = 270 end
            if direction == 'SE' then degrees = 225 end
            if direction == 'S' then degrees = 180 end
            if direction == 'SW' then degrees = 135 end
            if direction == 'W' then degrees = 90 end
            if direction == 'NW' then degrees = 45 end
            return '-'
        end

        local function humidityStatus(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

        local function getData(data)
            resultTable = dz.utils.fromXML(data).maintag.realtime
            relevantData = {}
            for index, record in ipairs(resultTable) do
                --dz.log((record.data._attr.realtime or record.data._attr.units) .. ': ' .. record.data[1],dz.log_DEBUG)
                relevantData[(record.data._attr.realtime or record.data._attr.units)] =  record.data[1]
            end
            return(relevantData)
        end

        function baroForecast(pressure)                                               -- Return text
            if pressure == nil          then return nil                                               -- Should not happen
                elseif pressure < 966   then return dz.BARO_THUNDERSTORM
                elseif pressure < 993   then return dz.BARO_CLOUDY_RAIN
                elseif pressure < 1007  then return dz.BARO_CLOUDY
                elseif pressure < 1013  then return dz.BARO_UNSTABLE
                elseif pressure < 1033  then return dz.BARO_STABLE
            end
            return dz.BARO_SUNNY
        end

        local function updateDevices(data)
            local rain = dz.devices('Regen')                   -- devicetype Rain
            local temperature = dz.devices('WetterAußen')      -- devicetype Temperature
            local wind = dz.devices('Boen')                    -- devicetype Wind
            local humidity = dz.devices('Humidity')            -- devicetype Humidity
            local barometer = dz.devices('BaroAußen')          -- devicetype Barometer
            local temperatureI = dz.devices('WetterInnen')
            local radiation = dz.devices('radiation')
            local UV = dz.devices('UV')
            local gust =dz.devices('Gust')
            local rainnow = dz.devices('Regenfall')

            dz.log(data, dz.LOG_DEBUG )

            temperature.updateTemperature(data.temp)
            wind.updateWind(wind2Degrees(data.winddir),data.winddir, tonumber(data.windspeed), data.windGust, data.temp, data.windchill)
            rain.updateRain(data.rain_rate, data.todaysrain )
            humidity.updateHumidity(tonumber(data.hum), humidityStatus(tonumber(data.temp), tonumber(data.hum)))
            barometer.updateBarometer(data.barometer, baroForecast(tonumber(data.barometer)))
            temperatureI.updateTemperature(data.temp)
            radiation.updateRadiation(data.radiation)
            UV.updateUV(data.UV)
            gust.updateCustomSensor(data.windGust)
            rainnow.updateCustomSensor(data.rain_rate)

        end

        if item.isHTTPResponse then
            if item.ok then
                local rt = getData(item.data)
                if dz.data.stationTime == rt.station_time then dz.data.equalCounter = dz.data.equalCounter + 1
                    dz.log('Received old data. Skipping this reading', dz.LOG_ERROR)
                    if dz.data.equalCounter > 5 then
                        dz.log('Received old data for >= 5 consecutive times. Booting weatherpi', dz.LOG_ERROR)
                        osCommand('ssh bootCommand')
                    end
                    return
                end
                dz.data.stationTime = rt.station_time
                dz.data.equalCounter = 0
                updateDevices(rt)
            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
}

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 30 June 2020 22:39
by sailmich
Take a while because I forgotten that daytime is already gone :lol:

Code: Select all

 2020-06-30 22:35:00.217 Status: dzVents: Info: getXML: ------ Start internal script: Script #5:, trigger: "every 1 minutes"
2020-06-30 22:35:00.218 Status: dzVents: Debug: getXML: OpenURL: url = http://xxx.xxx.xxx.xx/current.xml
2020-06-30 22:35:00.218 Status: dzVents: Debug: getXML: OpenURL: method = GET
2020-06-30 22:35:00.218 Status: dzVents: Debug: getXML: OpenURL: post data = nil
2020-06-30 22:35:00.218 Status: dzVents: Debug: getXML: OpenURL: headers = nil
2020-06-30 22:35:00.219 Status: dzVents: Debug: getXML: OpenURL: callback = getXML
2020-06-30 22:35:00.220 Status: dzVents: Info: getXML: ------ Finished Script #5
2020-06-30 22:35:00.498 Status: dzVents: Info: Handling httpResponse-events for: "getXML"
2020-06-30 22:35:00.499 Status: dzVents: Info: getXML: ------ Start internal script: Script #5: HTTPResponse: "getXML"
2020-06-30 22:35:00.600 Status: dzVents: Debug: getXML: Processing device-adapter for Regen: Rain device
2020-06-30 22:35:00.602 Status: dzVents: Debug: getXML: Processing device-adapter for WetterAußen: Temperature device adapter
2020-06-30 22:35:00.604 Status: dzVents: Debug: getXML: Processing device-adapter for Boen: Wind device adapter
2020-06-30 22:35:00.606 Status: dzVents: Debug: getXML: Processing device-adapter for Humidity: Humidty device adapter
2020-06-30 22:35:00.608 Status: dzVents: Debug: getXML: Processing device-adapter for BaroAußen: Barometer device adapter
2020-06-30 22:35:00.610 Status: dzVents: Debug: getXML: Processing device-adapter for WetterInnen: Temperature device adapter
2020-06-30 22:35:00.612 Status: dzVents: Debug: getXML: Processing device-adapter for radiation: Solar radiation device adapter
2020-06-30 22:35:00.614 Status: dzVents: Debug: getXML: Processing device-adapter for UV: UV device adapter
2020-06-30 22:35:00.616 Status: dzVents: Debug: getXML: Processing device-adapter for Gust: Custom sensor device adapter
2020-06-30 22:35:00.618 Status: dzVents: Debug: getXML: Processing device-adapter for Regenfall: Custom sensor device adapter
2020-06-30 22:35:00.619 Status: dzVents: Debug: getXML: {["station_date"]="Di, 30 Jun 2020", ["station_time"]="22:33 CEST", ["low_dew"]="5,6", ["sunset"]="21:47:39", ["low_hum"]="40", ["barometer"]="1006,3", ["high_rain_rate"]="0,0", ["windunit"]="m/s", ["high_temp"]="22,7", ["temp"]="16,7", ["sunrise"]="05:00:54", ["hum"]="74", ["rain_rate"]="0,0", ["todaysrain"]="0,0", ["rainunit"]="mm", ["windchill"]="16,7", ["high_hum"]="74", ["low_windchill"]="13,7", ["dew"]="12,0", ["high_barometer"]="1008,4", ["inside_temp"]="25,9", ["uv_index"]="0,0", ["barunit"]="mb", ["humunit"]="%", ["tempunit"]="C", ["radiation"]="1", ["rateunit"]="mm/hr-", ["winddir"]="W", ["high_windspeed"]="8,2", ["storm_rate"]="0,0", ["heatindex"]="16,7", ["low_barometer"]="1006,1", ["windGust"]="0,7", ["windspeed"]="0,3", ["high_heatindex"]="22,7", ["changebarometer"]="-0,6", ["high_dew"]="12,3", ["low_temp"]="13,7"}
2020-06-30 22:35:00.619 Status: dzVents: Info: getXML: ------ Finished Script #5
2020-06-30 22:35:00.619 Error: dzVents: Error: (3.0.9) getXML: An error occurred when calling event handler Script #5
2020-06-30 22:35:00.619 Error: dzVents: Error: (3.0.9) getXML: ...domoticz/dzVents/runtime/device-adapters/wind_device.lua:27: attempt to perform arithmetic on a nil value (local 'speed') 

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Tuesday 30 June 2020 22:58
by waaren
sailmich wrote: Tuesday 30 June 2020 22:39

Code: Select all

2020-06-30 22:35:00.619 Status: dzVents: Debug: getXML: {["station_date"]="Di, 30 Jun 2020", ["station_time"]="22:33 CEST", ["low_dew"]="5,6", ["sunset"]="21:47:39", ["low_hum"]="40", ["barometer"]="1006,3", ["high_rain_rate"]="0,0", ["windunit"]="m/s", ["high_temp"]="22,7", ["temp"]="16,7", ["sunrise"]="05:00:54", ["hum"]="74", ["rain_rate"]="0,0", ["todaysrain"]="0,0", ["rainunit"]="mm", ["windchill"]="16,7", ["high_hum"]="74", ["low_windchill"]="13,7", ["dew"]="12,0", ["high_barometer"]="1008,4", ["inside_temp"]="25,9", ["uv_index"]="0,0", ["barunit"]="mb", ["humunit"]="%", ["tempunit"]="C", ["radiation"]="1", ["rateunit"]="mm/hr-", ["winddir"]="W", ["high_windspeed"]="8,2", ["storm_rate"]="0,0", ["heatindex"]="16,7", ["low_barometer"]="1006,1", ["windGust"]="0,7", ["windspeed"]="0,3", ["high_heatindex"]="22,7", ["changebarometer"]="-0,6", ["high_dew"]="12,3", ["low_temp"]="13,7"}
For some reason your weather-station now returns numbers with a decimal comma. dzVents expects numbers with a decimal point.

Re: Help needed get Data from Weatherstation Lua to dzvents

Posted: Wednesday 01 July 2020 9:15
by sailmich
I didn't regonize the change from decimal point to comma neither I didn't know that this make a different. Now I know! I will check if it's a problem with my system or within the weewx software. Because I changed the version of that software a couple of days ago and also the OS from Jessie to Buster.
Thx again waaren!