Page 1 of 2
Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 12:06
by sailmich
Rpi 2
Z-Stick 5
Fine Offset weatherstation
Hi, I tried to change a lua script, to fetch data from my personal weatherstation, into dzvents.
Lua works
- Spoiler: show
Code: Select all
commandArray = {}
time = os.date("*t")
if ((time.min % 10)==0) then
os.execute('sudo wget http://192.xxx.xxx.xx/weewx_pws.xml -O /path to/weewx_pws.xml')
local filename = "path to/weewx_pws.xml"
local line = ''
local temperature = 0
local tempdevice = ''
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=tonumber(string.match(line, "%-?%d+.?%d*"))
end
end
-- Update virtual device idx
tempdevice='idx|1|'..temperature..';0'
--print(tempdevice))
commandArray['UpdateDevice'] = tempdevice
end
return commandArray
dzvents need help
- Spoiler: show
Code: Select all
return {
on = {
timer = {'every 1 minutes'}
--,devices = {'triggerhulp'}
},
execute = function(domoticz)
-- check time of the day
if domoticz.time.isDayTime then
os.execute('sudo wget http://xxx.xxx.xxx.xx/weewx_pws.xml -O /path to/weewx_pws.xml')
local filename = "/path to/weewx_pws.xml"
local line = ''
local temperature = 0
local tempdevice = ''
for line in io.lines(filename) do
if string.find(line,"\"temp\"") then
temperature=tonumber(string.match(line, "%-?%d+.?%d*"))
end
end
--Update virtual device id , nval(0) sval (temp)
--tempdevice='208|1|'..temperature..';0'
--print(tempdevice))
tempdevice = domoticz.devices('WetterAußen')
end
end
}
till os.execute('sudo wget
http://xxx.xxx.xxx.xx/weewx_pws.xml -O /path to/weewx_pws.xml') It's running.
I don't know how to get data from xml file and update my Temperature sensor.
THX for any help
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 12:54
by waaren
sailmich wrote: ↑Thursday 19 March 2020 12:06
Hi, I tried to change a lua script, to fetch data from my personal weatherstation, into dzvents.
THX for any help
This script will get the data from the weatherstation. If you can execute it once and share the loglines I can continue from there.
Also please state what version of domoticz / dzVents you use.
Code: Select all
local url = 'http://xxx.xxx.xxx.xxx/weewx_pws.xml'
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)
if item.isHTTPResponse then
if item.ok then
dz.log(item,dz.LOG_DEBUG)
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: Thursday 19 March 2020 13:02
by sailmich
Thanks for your quick reply!
I use newest domoticz beta 11.796 and dzvents 3.0.1.
I will check the script in a couple of minutes!
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 13:39
by sailmich
This is my domoticz log.
- Spoiler: show
- 2020-03-19 13:33:00.638 Status: dzVents: Debug: Commands sent to Domoticz:
2020-03-19 13:33:00.638 Status: dzVents: Debug: - OpenURL = {["URL"]="http://xxx.xxx.xxx.xx/weewx_pws.xml", ["_trigger"]="getXML", ["method"]="GET"}
2020-03-19 13:33:00.638 Status: dzVents: Debug: =====================================================
2020-03-19 13:33:00.639 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-03-19 13:33:00.759 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-19 13:33:00.821 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-19 13:33:00.821 Status: dzVents: Debug: Event triggers:
2020-03-19 13:33:00.821 Status: dzVents: Debug: - HTTPResponse: getXML
2020-03-19 13:33:00.872 Status: dzVents: Info: Handling httpResponse-events for: "getXML"
2020-03-19 13:33:00.872 Status: dzVents: Info: getXML: ------ Start internal script: TemperaturDraußen: HTTPResponse: "getXML"
2020-03-19 13:33:00.874 Status: dzVents: Debug: getXML: {["ok"]=true, ["isScene"]=false, ["isVariable"]=false, ["isTimer"]=false, ["data"]="<?xml version="1.0" encoding="UTF-8" ?>
2020-03-19 13:33:00.874 <maintag>
2020-03-19 13:33:00.874 <!--MISC-->
2020-03-19 13:33:00.874 <misc><misc data="station_location">Hannover, Niedersachsen, Deutschland</misc></misc>
2020-03-19 13:33:00.874 <!--STATION DATA-->
2020-03-19 13:33:00.874 <realtime><data realtime="station_date">Thu, 19 Mar 2020</data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="station_time">13:30 CET</data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="sunrise">06:24:22</data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="sunset">18:33:14<!--sunsetTime--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="moonrise">04:56:48<!--moonriseTime--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="moonset">13:01:27<!--moonsetTime--></data></realtime>
2020-03-19 13:33:00.874 <!--TEMPERATURE-->
2020-03-19 13:33:00.874 <realtime><data realtime="temp">13.4<!--outsideTemp--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_temp">14.0<!--hiOutsideTemp--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="low_temp">10.7<!--lowOutsideTemp--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="heatindex">13.4<!--outsideHeatIndex--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_heatindex">14.0<!--hiHeatindex--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="inside_temp">25.0<!--inside_temp--></data></realtime>
2020-03-19 13:33:00.874 <!--HUMIDITY-->
2020-03-19 13:33:00.874 <realtime><data realtime="hum">62<!--outsideHumidity--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_hum">71<!--hiHumidity--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="low_hum">60<!--lowHumidity--></data></realtime>
2020-03-19 13:33:00.874 <!--WIND-->
2020-03-19 13:33:00.874 <realtime><data realtime="winddir" misc="imgwinddir">E<!--windDirection--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="windspeed">0.7<!--windSpeed--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="windGust">1.0<!--windGust--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_windspeed">2.0<!--hiWindSpeed--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="windchill">13.4<!--windChill--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="low_windchill">10.7<!--lowWindchill--></data></realtime>
2020-03-19 13:33:00.874 <!--DEWPOINT-->
2020-03-19 13:33:00.874 <realtime><data realtime="dew">6.3<!--outsideDewPt--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_dew">7.1<!--hiDewpoint--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="low_dew">4.5<!--lowDewpoint--></data></realtime>
2020-03-19 13:33:00.874 <!--BAROMETER-->
2020-03-19 13:33:00.874 <realtime><data realtime="barometer">1025.2<!--barometer--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="changebarometer">0.2<!--hourchangebarom--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_barometer">1025.6<!--hiBarometer--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="low_barometer">1022.8<!--lowBarometer--></data></realtime>
2020-03-19 13:33:00.874 <!--RAIN-->
2020-03-19 13:33:00.874 <realtime><data realtime="todaysrain">0.0<!--dailyRain--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="rain_rate">0.0<!--rainRate--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="high_rain_rate">0.0<!--hiRainRate--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="storm_rate">0.0<!--dailyRain--></data></realtime>
2020-03-19 13:33:00.874 <!--UNITS-->
2020-03-19 13:33:00.874 <realtime><data units="windunit">m/s<!--windUnit--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data units="rainunit">mm<!--rainUnit--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data units="rateunit">mm/hr-<!--rateUnit--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data units="barunit">mb<!--barUnit--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data units="tempunit">C<!--tempUnit--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data units="humunit">%<!--humUnit--></data></realtime>
2020-03-19 13:33:00.874 <!--CUSTOMDATA-->
2020-03-19 13:33:00.874 <realtime><data realtime="uv_index">0.0<!--uvIndex--></data></realtime>
2020-03-19 13:33:00.874 <realtime><data realtime="radiation">29638<!--radiation--></data></realtime>
2020-03-19 13:33:00.874 </maintag>
2020-03-19 13:33:00.874
2020-03-19 13:33:00.874
2020-03-19 13:33:00.874 ", ["isXML"]=false, ["_contentType"]="application/xml", ["isSecurity"]=false, ["statusText"]="OK", ["isDevice"]=false, ["isJSON"]=false, ["isSystem"]=false, ["statusCode"]=200, ["isHTTPResponse"]=true, ["isGroup"]=false, ["protocol"]="HTTP/1.1", ["isCustomEvent"]=false, ["isHardware"]=false, ["trigger"]="getXML", ["callback"]="getXML", ["baseType"]="httpResponse", ["headers"]={["Content-Length"]="3363", ["Accept-Ranges"]="bytes", ["Server"]="lighttpd/1.4.35", ["Last-Modified"]="Thu, 19 Mar 2020 12:31:01 GMT", ["ETag"]=""1082087333"", ["Date"]="Thu, 19 Mar 2020 12:33:00 GMT", ["Content-Type"]="application/xml"}}
2020-03-19 13:33:00.874 Status: dzVents: Info: getXML: ------ Finished TemperaturDraußen
2020-03-19 13:33:13.723 (ZWaveW) Temp (Boden Sued Temperature)
2020-03-19 13:33:13.834 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-19 13:33:13.929 Status: dzVents: Debug: Processing device-adapter for Boden Sued Temperature: Temperature device adapter
2020-03-19 13:33:13.929 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-19 13:33:13.929 Status: dzVents: Debug: Event triggers:
All the data's are there but how to get them out and update my sensors
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 14:12
by waaren
sailmich wrote: ↑Thursday 19 March 2020 13:39
All the data's are there but how to get them out and update my sensors
Next step:
converting the XML to a table.
Please execute this one and show the result + tell what value needs to go to what device (name or id and type/ subtype)
Code: Select all
local url = 'http://xxx.xxx.xxx.xxx/weewx_pws.xml'
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)
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: Thursday 19 March 2020 15:01
by sailmich
This is what I got.
- Spoiler: show
- 2020-03-19 14:31:00.645 Status: dzVents: > 23:
2020-03-19 14:31:00.645 Status: dzVents: > data:
2020-03-19 14:31:00.645 Status: dzVents: > 1: 7.1
2020-03-19 14:31:00.645 Status: dzVents: > _attr:
2020-03-19 14:31:00.645 Status: dzVents: > realtime: high_dew
2020-03-19 14:31:00.645 Status: dzVents: > 24:
2020-03-19 14:31:00.645 Status: dzVents: > data:
2020-03-19 14:31:00.645 Status: dzVents: > 1: 4.5
2020-03-19 14:31:00.645 Status: dzVents: > _attr:
2020-03-19 14:31:00.646 Status: dzVents: > realtime: low_dew
2020-03-19 14:31:00.646 Status: dzVents: > 25:
2020-03-19 14:31:00.646 Status: dzVents: > data:
2020-03-19 14:31:00.646 Status: dzVents: > 1: 1025.2
2020-03-19 14:31:00.646 Status: dzVents: > _attr:
2020-03-19 14:31:00.646 Status: dzVents: > realtime: barometer
2020-03-19 14:31:00.646 Status: dzVents: > 26:
2020-03-19 14:31:00.646 Status: dzVents: > data:
2020-03-19 14:31:00.646 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.646 Status: dzVents: > _attr:
2020-03-19 14:31:00.646 Status: dzVents: > realtime: changebarometer
2020-03-19 14:31:00.646 Status: dzVents: > 27:
2020-03-19 14:31:00.646 Status: dzVents: > data:
2020-03-19 14:31:00.646 Status: dzVents: > 1: 1025.6
2020-03-19 14:31:00.646 Status: dzVents: > _attr:
2020-03-19 14:31:00.646 Status: dzVents: > realtime: high_barometer
2020-03-19 14:31:00.646 Status: dzVents: > 28:
2020-03-19 14:31:00.646 Status: dzVents: > data:
2020-03-19 14:31:00.646 Status: dzVents: > 1: 1022.8
2020-03-19 14:31:00.647 Status: dzVents: > _attr:
2020-03-19 14:31:00.647 Status: dzVents: > realtime: low_barometer
2020-03-19 14:31:00.647 Status: dzVents: > 29:
2020-03-19 14:31:00.647 Status: dzVents: > data:
2020-03-19 14:31:00.647 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.647 Status: dzVents: > _attr:
2020-03-19 14:31:00.647 Status: dzVents: > realtime: todaysrain
2020-03-19 14:31:00.647 Status: dzVents: > 30:
2020-03-19 14:31:00.647 Status: dzVents: > data:
2020-03-19 14:31:00.647 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.647 Status: dzVents: > _attr:
2020-03-19 14:31:00.647 Status: dzVents: > realtime: rain_rate
2020-03-19 14:31:00.647 Status: dzVents: > 31:
2020-03-19 14:31:00.647 Status: dzVents: > data:
2020-03-19 14:31:00.647 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.647 Status: dzVents: > _attr:
2020-03-19 14:31:00.647 Status: dzVents: > realtime: high_rain_rate
2020-03-19 14:31:00.647 Status: dzVents: > 32:
2020-03-19 14:31:00.647 Status: dzVents: > data:
2020-03-19 14:31:00.647 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.647 Status: dzVents: > _attr:
2020-03-19 14:31:00.648 Status: dzVents: > realtime: storm_rate
2020-03-19 14:31:00.648 Status: dzVents: > 33:
2020-03-19 14:31:00.648 Status: dzVents: > data:
2020-03-19 14:31:00.648 Status: dzVents: > 1: m/s
2020-03-19 14:31:00.648 Status: dzVents: > _attr:
2020-03-19 14:31:00.648 Status: dzVents: > units: windunit
2020-03-19 14:31:00.648 Status: dzVents: > 34:
2020-03-19 14:31:00.648 Status: dzVents: > data:
2020-03-19 14:31:00.648 Status: dzVents: > 1: mm
2020-03-19 14:31:00.648 Status: dzVents: > _attr:
2020-03-19 14:31:00.648 Status: dzVents: > units: rainunit
2020-03-19 14:31:00.648 Status: dzVents: > 35:
2020-03-19 14:31:00.648 Status: dzVents: > data:
2020-03-19 14:31:00.648 Status: dzVents: > 1: mm/hr-
2020-03-19 14:31:00.648 Status: dzVents: > _attr:
2020-03-19 14:31:00.648 Status: dzVents: > units: rateunit
2020-03-19 14:31:00.648 Status: dzVents: > 36:
2020-03-19 14:31:00.648 Status: dzVents: > data:
2020-03-19 14:31:00.648 Status: dzVents: > 1: mb
2020-03-19 14:31:00.648 Status: dzVents: > _attr:
2020-03-19 14:31:00.648 Status: dzVents: > units: barunit
2020-03-19 14:31:00.649 Status: dzVents: > 37:
2020-03-19 14:31:00.649 Status: dzVents: > data:
2020-03-19 14:31:00.649 Status: dzVents: > 1: C
2020-03-19 14:31:00.649 Status: dzVents: > _attr:
2020-03-19 14:31:00.649 Status: dzVents: > units: tempunit
2020-03-19 14:31:00.649 Status: dzVents: > 38:
2020-03-19 14:31:00.649 Status: dzVents: > data:
2020-03-19 14:31:00.649 Status: dzVents: > 1: %
2020-03-19 14:31:00.649 Status: dzVents: > _attr:
2020-03-19 14:31:00.649 Status: dzVents: > units: humunit
2020-03-19 14:31:00.649 Status: dzVents: > 39:
2020-03-19 14:31:00.649 Status: dzVents: > data:
2020-03-19 14:31:00.649 Status: dzVents: > 1: 0.0
2020-03-19 14:31:00.649 Status: dzVents: > _attr:
2020-03-19 14:31:00.649 Status: dzVents: > realtime: uv_index
2020-03-19 14:31:00.649 Status: dzVents: > 40:
2020-03-19 14:31:00.649 Status: dzVents: > data:
2020-03-19 14:31:00.649 Status: dzVents: > 1: 21558
2020-03-19 14:31:00.649 Status: dzVents: > _attr:
2020-03-19 14:31:00.649 Status: dzVents: > realtime: radiation
2020-03-19 14:31:00.649 Status: dzVents: > misc:
2020-03-19 14:31:00.650 Status: dzVents: > misc:
2020-03-19 14:31:00.650 Status: dzVents: > 1: Hannover, Niedersachsen, Deutschland
2020-03-19 14:31:00.650 Status: dzVents: > _attr:
2020-03-19 14:31:00.650 Status: dzVents: > data: station_location
I don't get all data's as in the xml. I copied the domoticz log direct in Domoticz. Do you know where the location at my pi is, I can't find a log file for Domoticz.
xml
- Spoiler: show
- <!--STATION DATA-->
<realtime>
<data realtime="station_date">Thu, 19 Mar 2020</data>
</realtime>
<realtime>
<data realtime="station_time">14:46 CET</data>
</realtime>
<realtime>
<data realtime="sunrise">06:24:22</data>
</realtime>
<realtime>
<data realtime="sunset">
18:33:14
<!--sunsetTime-->
</data>
</realtime>
<realtime>
<data realtime="moonrise">
04:56:48
<!--moonriseTime-->
</data>
</realtime>
<realtime>
<data realtime="moonset">
13:01:27
<!--moonsetTime-->
</data>
</realtime>
<!--TEMPERATURE-->
<realtime>
<data realtime="temp">
13.2
<!--outsideTemp-->
</data>
</realtime>
<realtime>
<data realtime="high_temp">
14.0
<!--hiOutsideTemp-->
</data>
</realtime>
<realtime>
<data realtime="low_temp">
10.7
<!--lowOutsideTemp-->
</data>
</realtime>
<realtime>
<data realtime="heatindex">
13.2
<!--outsideHeatIndex-->
</data>
</realtime>
<realtime>
<data realtime="high_heatindex">
14.0
<!--hiHeatindex-->
</data>
</realtime>
<realtime>
<data realtime="inside_temp">
24.7
<!--inside_temp-->
</data>
</realtime>
<!--HUMIDITY-->
<realtime>
<data realtime="hum">
62
<!--outsideHumidity-->
</data>
</realtime>
<realtime>
<data realtime="high_hum">
71
<!--hiHumidity-->
</data>
</realtime>
<realtime>
<data realtime="low_hum">
60
<!--lowHumidity-->
</data>
</realtime>
<!--WIND-->
<realtime>
<data realtime="winddir" misc="imgwinddir">
NNE
<!--windDirection-->
</data>
</realtime>
<realtime>
<data realtime="windspeed">
1.6
<!--windSpeed-->
</data>
</realtime>
<realtime>
<data realtime="windGust">
2.7
<!--windGust-->
</data>
</realtime>
<realtime>
<data realtime="high_windspeed">
2.7
<!--hiWindSpeed-->
</data>
</realtime>
<realtime>
<data realtime="windchill">
13.2
<!--windChill-->
</data>
</realtime>
<realtime>
<data realtime="low_windchill">
10.7
<!--lowWindchill-->
</data>
</realtime>
<!--DEWPOINT-->
<realtime>
<data realtime="dew">
6.1
<!--outsideDewPt-->
</data>
</realtime>
<realtime>
<data realtime="high_dew">
7.1
<!--hiDewpoint-->
</data>
</realtime>
<realtime>
<data realtime="low_dew">
4.5
<!--lowDewpoint-->
</data>
</realtime>
<!--BAROMETER-->
<realtime>
<data realtime="barometer">
1025.0
<!--barometer-->
</data>
</realtime>
<realtime>
<data realtime="changebarometer">
-0.2
<!--hourchangebarom-->
</data>
</realtime>
<realtime>
<data realtime="high_barometer">
1025.6
<!--hiBarometer-->
</data>
</realtime>
<realtime>
<data realtime="low_barometer">
1022.8
<!--lowBarometer-->
</data>
</realtime>
<!--RAIN-->
<realtime>
<data realtime="todaysrain">
0.0
<!--dailyRain-->
</data>
</realtime>
<realtime>
<data realtime="rain_rate">
0.0
<!--rainRate-->
</data>
</realtime>
<realtime>
<data realtime="high_rain_rate">
0.0
<!--hiRainRate-->
</data>
</realtime>
<realtime>
<data realtime="storm_rate">
0.0
<!--dailyRain-->
</data>
</realtime>
<!--UNITS-->
<realtime>
<data units="windunit">
m/s
<!--windUnit-->
</data>
</realtime>
<realtime>
<data units="rainunit">
mm
<!--rainUnit-->
</data>
</realtime>
<realtime>
<data units="rateunit">
mm/hr-
<!--rateUnit-->
</data>
</realtime>
<realtime>
<data units="barunit">
mb
<!--barUnit-->
</data>
</realtime>
<realtime>
<data units="tempunit">
C
<!--tempUnit-->
</data>
</realtime>
<realtime>
<data units="humunit">
%
<!--humUnit-->
</data>
</realtime>
<!--CUSTOMDATA-->
<realtime>
<data realtime="uv_index">
0.0
<!--uvIndex-->
</data>
</realtime>
<realtime>
<data realtime="radiation">
21320
<!--radiation-->
</data>
</realtime>
</maintag>
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 15:28
by waaren
sailmich wrote: ↑Thursday 19 March 2020 15:01
I don't get all data's as in the xml. I copied the domoticz log direct in Domoticz. Do you know where the location at my pi is, I can't find a log file for Domoticz.
The log file location is set in /etc/init.d/domoticz.sh in the
DAEMON_ARGS section.
I have these but you ports, location of logfile, etc could vary
Code: Select all
DAEMON_ARGS="-daemon"
DAEMON_ARGS="$DAEMON_ARGS -daemonname $NAME -pidfile $PIDFILE"
DAEMON_ARGS="$DAEMON_ARGS -www 8084"
DAEMON_ARGS="$DAEMON_ARGS -sslwww 8443"
DAEMON_ARGS="$DAEMON_ARGS -log /var/log/domoticz.log" # location of logfile
DAEMON_ARGS="$DAEMON_ARGS -loglevel normal,status,error"
if you change something in this file you need a
Code: Select all
sudo systemctl daemon-reload
sudo domoticz stop
sudo domoticz start
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 18:05
by sailmich
All data's are in the log
realtime:temp = idx208 WetterAußen
realtime:windGust =idx213 Boen
realtime:rain_rate =idx216 Regen
- Spoiler: show
- 2020-03-19 17:25:00.376 Status: dzVents: Debug: =====================================================
2020-03-19 17:25:00.377 Status: EventSystem: Script event triggered: /home/pi/domoticz/dzVents/runtime/dzVents.lua
2020-03-19 17:25:00.489 Status: dzVents: Debug: Dumping domoticz data to /home/pi/domoticz/scripts/dzVents/domoticzData.lua
2020-03-19 17:25:00.551 Status: dzVents: Debug: dzVents version: 3.0.1
2020-03-19 17:25:00.551 Status: dzVents: Debug: Event triggers:
2020-03-19 17:25:00.551 Status: dzVents: Debug: - HTTPResponse: getXML
2020-03-19 17:25:00.592 Status: dzVents: Info: Handling httpResponse-events for: "getXML"
2020-03-19 17:25:00.593 Status: dzVents: Info: getXML: ------ Start internal script: Test: HTTPResponse: "getXML"
2020-03-19 17:25:00.628 Status: dzVents: > maintag:
2020-03-19 17:25:00.629 Status: dzVents: > misc:
2020-03-19 17:25:00.629 Status: dzVents: > misc:
2020-03-19 17:25:00.629 Status: dzVents: > 1: Hannover, Niedersachsen, Deutschland
2020-03-19 17:25:00.629 Status: dzVents: > _attr:
2020-03-19 17:25:00.629 Status: dzVents: > data: station_location
2020-03-19 17:25:00.629 Status: dzVents: > realtime:
2020-03-19 17:25:00.629 Status: dzVents: > 1:
2020-03-19 17:25:00.629 Status: dzVents: > data:
2020-03-19 17:25:00.629 Status: dzVents: > 1: Thu, 19 Mar 2020
2020-03-19 17:25:00.629 Status: dzVents: > _attr:
2020-03-19 17:25:00.630 Status: dzVents: > realtime: station_date
2020-03-19 17:25:00.630 Status: dzVents: > 2:
2020-03-19 17:25:00.630 Status: dzVents: > data:
2020-03-19 17:25:00.630 Status: dzVents: > 1: 17:22 CET
2020-03-19 17:25:00.630 Status: dzVents: > _attr:
2020-03-19 17:25:00.630 Status: dzVents: > realtime: station_time
2020-03-19 17:25:00.630 Status: dzVents: > 3:
2020-03-19 17:25:00.630 Status: dzVents: > data:
2020-03-19 17:25:00.630 Status: dzVents: > 1: 06:24:19
2020-03-19 17:25:00.630 Status: dzVents: > _attr:
2020-03-19 17:25:00.630 Status: dzVents: > realtime: sunrise
2020-03-19 17:25:00.630 Status: dzVents: > 4:
2020-03-19 17:25:00.630 Status: dzVents: > data:
2020-03-19 17:25:00.631 Status: dzVents: > 1: 18:33:17
2020-03-19 17:25:00.631 Status: dzVents: > _attr:
2020-03-19 17:25:00.631 Status: dzVents: > realtime: sunset
2020-03-19 17:25:00.631 Status: dzVents: > 5:
2020-03-19 17:25:00.631 Status: dzVents: > data:
2020-03-19 17:25:00.631 Status: dzVents: > 1: 04:56:45
2020-03-19 17:25:00.631 Status: dzVents: > _attr:
2020-03-19 17:25:00.631 Status: dzVents: > realtime: moonrise
2020-03-19 17:25:00.631 Status: dzVents: > 6:
2020-03-19 17:25:00.631 Status: dzVents: > data:
2020-03-19 17:25:00.631 Status: dzVents: > 1: 13:01:30
2020-03-19 17:25:00.631 Status: dzVents: > _attr:
2020-03-19 17:25:00.631 Status: dzVents: > realtime: moonset
2020-03-19 17:25:00.631 Status: dzVents: > 7:
2020-03-19 17:25:00.632 Status: dzVents: > data:
2020-03-19 17:25:00.632 Status: dzVents: > 1: 10.1
2020-03-19 17:25:00.632 Status: dzVents: > _attr:
2020-03-19 17:25:00.632 Status: dzVents: > realtime: temp
2020-03-19 17:25:00.632 Status: dzVents: > 8:
2020-03-19 17:25:00.632 Status: dzVents: > data:
2020-03-19 17:25:00.632 Status: dzVents: > 1: 14.0
2020-03-19 17:25:00.632 Status: dzVents: > _attr:
2020-03-19 17:25:00.632 Status: dzVents: > realtime: high_temp
2020-03-19 17:25:00.632 Status: dzVents: > 9:
2020-03-19 17:25:00.632 Status: dzVents: > data:
2020-03-19 17:25:00.632 Status: dzVents: > 1: 10.1
2020-03-19 17:25:00.632 Status: dzVents: > _attr:
2020-03-19 17:25:00.633 Status: dzVents: > realtime: low_temp
2020-03-19 17:25:00.633 Status: dzVents: > 10:
2020-03-19 17:25:00.633 Status: dzVents: > data:
2020-03-19 17:25:00.633 Status: dzVents: > 1: 10.1
2020-03-19 17:25:00.633 Status: dzVents: > _attr:
2020-03-19 17:25:00.633 Status: dzVents: > realtime: heatindex
2020-03-19 17:25:00.633 Status: dzVents: > 11:
2020-03-19 17:25:00.633 Status: dzVents: > data:
2020-03-19 17:25:00.633 Status: dzVents: > 1: 14.0
2020-03-19 17:25:00.633 Status: dzVents: > _attr:
2020-03-19 17:25:00.633 Status: dzVents: > realtime: high_heatindex
2020-03-19 17:25:00.633 Status: dzVents: > 12:
2020-03-19 17:25:00.634 Status: dzVents: > data:
2020-03-19 17:25:00.634 Status: dzVents: > 1: 25.1
2020-03-19 17:25:00.634 Status: dzVents: > _attr:
2020-03-19 17:25:00.634 Status: dzVents: > realtime: inside_temp
2020-03-19 17:25:00.634 Status: dzVents: > 13:
2020-03-19 17:25:00.634 Status: dzVents: > data:
2020-03-19 17:25:00.634 Status: dzVents: > 1: 70
2020-03-19 17:25:00.634 Status: dzVents: > _attr:
2020-03-19 17:25:00.634 Status: dzVents: > realtime: hum
2020-03-19 17:25:00.634 Status: dzVents: > 14:
2020-03-19 17:25:00.634 Status: dzVents: > data:
2020-03-19 17:25:00.635 Status: dzVents: > 1: 71
2020-03-19 17:25:00.635 Status: dzVents: > _attr:
2020-03-19 17:25:00.635 Status: dzVents: > realtime: high_hum
2020-03-19 17:25:00.635 Status: dzVents: > 15:
2020-03-19 17:25:00.635 Status: dzVents: > data:
2020-03-19 17:25:00.635 Status: dzVents: > 1: 60
2020-03-19 17:25:00.635 Status: dzVents: > _attr:
2020-03-19 17:25:00.635 Status: dzVents: > realtime: low_hum
2020-03-19 17:25:00.635 Status: dzVents: > 16:
2020-03-19 17:25:00.635 Status: dzVents: > data:
2020-03-19 17:25:00.635 Status: dzVents: > 1: N
2020-03-19 17:25:00.635 Status: dzVents: > _attr:
2020-03-19 17:25:00.635 Status: dzVents: > misc: imgwinddir
2020-03-19 17:25:00.636 Status: dzVents: > realtime: winddir
2020-03-19 17:25:00.636 Status: dzVents: > 17:
2020-03-19 17:25:00.636 Status: dzVents: > data:
2020-03-19 17:25:00.636 Status: dzVents: > 1: 0.8
2020-03-19 17:25:00.636 Status: dzVents: > _attr:
2020-03-19 17:25:00.636 Status: dzVents: > realtime: windspeed
2020-03-19 17:25:00.636 Status: dzVents: > 18:
2020-03-19 17:25:00.636 Status: dzVents: > data:
2020-03-19 17:25:00.636 Status: dzVents: > 1: 1.7
2020-03-19 17:25:00.636 Status: dzVents: > _attr:
2020-03-19 17:25:00.636 Status: dzVents: > realtime: windGust
2020-03-19 17:25:00.636 Status: dzVents: > 19:
2020-03-19 17:25:00.637 Status: dzVents: > data:
2020-03-19 17:25:00.637 Status: dzVents: > 1: 2.7
2020-03-19 17:25:00.637 Status: dzVents: > _attr:
2020-03-19 17:25:00.637 Status: dzVents: > realtime: high_windspeed
2020-03-19 17:25:00.637 Status: dzVents: > 20:
2020-03-19 17:25:00.637 Status: dzVents: > data:
2020-03-19 17:25:00.637 Status: dzVents: > 1: 10.1
2020-03-19 17:25:00.637 Status: dzVents: > _attr:
2020-03-19 17:25:00.637 Status: dzVents: > realtime: windchill
2020-03-19 17:25:00.637 Status: dzVents: > 21:
2020-03-19 17:25:00.637 Status: dzVents: > data:
2020-03-19 17:25:00.637 Status: dzVents: > 1: 10.1
2020-03-19 17:25:00.637 Status: dzVents: > _attr:
2020-03-19 17:25:00.638 Status: dzVents: > realtime: low_windchill
2020-03-19 17:25:00.638 Status: dzVents: > 22:
2020-03-19 17:25:00.638 Status: dzVents: > data:
2020-03-19 17:25:00.638 Status: dzVents: > 1: 4.9
2020-03-19 17:25:00.638 Status: dzVents: > _attr:
2020-03-19 17:25:00.638 Status: dzVents: > realtime: dew
2020-03-19 17:25:00.638 Status: dzVents: > 23:
2020-03-19 17:25:00.638 Status: dzVents: > data:
2020-03-19 17:25:00.638 Status: dzVents: > 1: 7.1
2020-03-19 17:25:00.638 Status: dzVents: > _attr:
2020-03-19 17:25:00.638 Status: dzVents: > realtime: high_dew
2020-03-19 17:25:00.638 Status: dzVents: > 24:
2020-03-19 17:25:00.638 Status: dzVents: > data:
2020-03-19 17:25:00.639 Status: dzVents: > 1: 4.5
2020-03-19 17:25:00.639 Status: dzVents: > _attr:
2020-03-19 17:25:00.639 Status: dzVents: > realtime: low_dew
2020-03-19 17:25:00.639 Status: dzVents: > 25:
2020-03-19 17:25:00.639 Status: dzVents: > data:
2020-03-19 17:25:00.639 Status: dzVents: > 1: 1025.2
2020-03-19 17:25:00.639 Status: dzVents: > _attr:
2020-03-19 17:25:00.639 Status: dzVents: > realtime: barometer
2020-03-19 17:25:00.639 Status: dzVents: > 26:
2020-03-19 17:25:00.639 Status: dzVents: > data:
2020-03-19 17:25:00.639 Status: dzVents: > 1: 0.1
2020-03-19 17:25:00.639 Status: dzVents: > _attr:
2020-03-19 17:25:00.639 Status: dzVents: > realtime: changebarometer
2020-03-19 17:25:00.640 Status: dzVents: > 27:
2020-03-19 17:25:00.640 Status: dzVents: > data:
2020-03-19 17:25:00.640 Status: dzVents: > 1: 1025.6
2020-03-19 17:25:00.640 Status: dzVents: > _attr:
2020-03-19 17:25:00.640 Status: dzVents: > realtime: high_barometer
2020-03-19 17:25:00.640 Status: dzVents: > 28:
2020-03-19 17:25:00.640 Status: dzVents: > data:
2020-03-19 17:25:00.640 Status: dzVents: > 1: 1022.8
2020-03-19 17:25:00.640 Status: dzVents: > _attr:
2020-03-19 17:25:00.640 Status: dzVents: > realtime: low_barometer
2020-03-19 17:25:00.640 Status: dzVents: > 29:
2020-03-19 17:25:00.640 Status: dzVents: > data:
2020-03-19 17:25:00.640 Status: dzVents: > 1: 0.0
2020-03-19 17:25:00.640 Status: dzVents: > _attr:
2020-03-19 17:25:00.641 Status: dzVents: > realtime: todaysrain
2020-03-19 17:25:00.641 Status: dzVents: > 30:
2020-03-19 17:25:00.641 Status: dzVents: > data:
2020-03-19 17:25:00.641 Status: dzVents: > 1: 0.0
2020-03-19 17:25:00.641 Status: dzVents: > _attr:
2020-03-19 17:25:00.641 Status: dzVents: > realtime: rain_rate
2020-03-19 17:25:00.641 Status: dzVents: > 31:
2020-03-19 17:25:00.641 Status: dzVents: > data:
2020-03-19 17:25:00.641 Status: dzVents: > 1: 0.0
2020-03-19 17:25:00.641 Status: dzVents: > _attr:
2020-03-19 17:25:00.641 Status: dzVents: > realtime: high_rain_rate
2020-03-19 17:25:00.641 Status: dzVents: > 32:
2020-03-19 17:25:00.641 Status: dzVents: > data:
2020-03-19 17:25:00.642 Status: dzVents: > 1: 0.0
2020-03-19 17:25:00.642 Status: dzVents: > _attr:
2020-03-19 17:25:00.642 Status: dzVents: > realtime: storm_rate
2020-03-19 17:25:00.642 Status: dzVents: > 33:
2020-03-19 17:25:00.642 Status: dzVents: > data:
2020-03-19 17:25:00.642 Status: dzVents: > 1: m/s
2020-03-19 17:25:00.642 Status: dzVents: > _attr:
2020-03-19 17:25:00.642 Status: dzVents: > units: windunit
2020-03-19 17:25:00.642 Status: dzVents: > 34:
2020-03-19 17:25:00.642 Status: dzVents: > data:
2020-03-19 17:25:00.642 Status: dzVents: > 1: mm
2020-03-19 17:25:00.642 Status: dzVents: > _attr:
2020-03-19 17:25:00.642 Status: dzVents: > units: rainunit
2020-03-19 17:25:00.642 Status: dzVents: > 35:
2020-03-19 17:25:00.643 Status: dzVents: > data:
2020-03-19 17:25:00.643 Status: dzVents: > 1: mm/hr-
2020-03-19 17:25:00.643 Status: dzVents: > _attr:
2020-03-19 17:25:00.643 Status: dzVents: > units: rateunit
2020-03-19 17:25:00.643 Status: dzVents: > 36:
2020-03-19 17:25:00.643 Status: dzVents: > data:
2020-03-19 17:25:00.643 Status: dzVents: > 1: mb
2020-03-19 17:25:00.643 Status: dzVents: > _attr:
2020-03-19 17:25:00.643 Status: dzVents: > units: barunit
2020-03-19 17:25:00.643 Status: dzVents: > 37:
2020-03-19 17:25:00.643 Status: dzVents: > data:
2020-03-19 17:25:00.643 Status: dzVents: > 1: C
2020-03-19 17:25:00.644 Status: dzVents: > _attr:
2020-03-19 17:25:00.644 Status: dzVents: > units: tempunit
2020-03-19 17:25:00.644 Status: dzVents: > 38:
2020-03-19 17:25:00.644 Status: dzVents: > data:
2020-03-19 17:25:00.644 Status: dzVents: > 1: %
2020-03-19 17:25:00.644 Status: dzVents: > _attr:
2020-03-19 17:25:00.644 Status: dzVents: > units: humunit
2020-03-19 17:25:00.644 Status: dzVents: > 39:
2020-03-19 17:25:00.644 Status: dzVents: > data:
2020-03-19 17:25:00.644 Status: dzVents: > 1: 0.0
2020-03-19 17:25:00.644 Status: dzVents: > _attr:
2020-03-19 17:25:00.644 Status: dzVents: > realtime: uv_index
2020-03-19 17:25:00.644 Status: dzVents: > 40:
2020-03-19 17:25:00.645 Status: dzVents: > data:
2020-03-19 17:25:00.645 Status: dzVents: > 1: 2044
2020-03-19 17:25:00.645 Status: dzVents: > _attr:
2020-03-19 17:25:00.645 Status: dzVents: > realtime: radiation
2020-03-19 17:25:00.645 Status: dzVents: Info: getXML: ------ Finished Test
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Thursday 19 March 2020 21:06
by waaren
sailmich wrote: ↑Thursday 19 March 2020 18:05
All data's are in the log
Script could look like this. Just comment the devices and updatelines you don't use.
Please feel free to ask if something is not clear.
Code: Select all
local url = 'http://xxx.xxx.xxx.xxx/weewx_pws.xml'
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)
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('Barometer') -- devicetype Barometer
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)))
end
if item.isHTTPResponse then
if item.ok then
-- dz.log(item, dz.LOG_DEBUG)
-- dz.utils.dumpTable(getData(item.data))
updateDevices(getData(item.data))
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: Friday 20 March 2020 11:01
by sailmich
Thank you very much! Your code is working, I already modified your script to get more sensors. I have trouble to get just windgust, I want to use the gust to control my blinds.
Code: Select all
local gust = dz.devices('Gust') --devicetype utility
gust.updateGust(data.windGust)
Domoticz log
- Spoiler: show
- 2020-03-20 10:59:00.902 Error: dzVents: Error: (3.0.1) getXML: An error occurred when calling event handler Wetterstation
2020-03-20 10:59:00.902 Error: dzVents: Error: (3.0.1) getXML: ...ticz/scripts/dzVents/generated_scripts/Wetterstation.lua:96: attempt to call a nil value (field 'updateGust')
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Friday 20 March 2020 11:11
by waaren
sailmich wrote: ↑Friday 20 March 2020 11:01
I have trouble to get just windgust.
The get part is already OK but updateGust() is not a known dzVents method. (see the
wiki )
How does the complete row of your device 'Gust' look like in the devices tab ?
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Friday 20 March 2020 12:51
by sailmich
Got it because it is a custom sensor
gust.updateCustomSensor(data.windGust)
Thank you very much!
One more question. What is 'triggerhulp' for?
Re: Help needed get Data from Weatherstation Lua to dzvents [Solved]
Posted: Friday 20 March 2020 13:36
by waaren
sailmich wrote: ↑Friday 20 March 2020 12:51
One more question. What is 'triggerhulp' for?
triggerhulp is a device I use for testing the script. I don't like to wait during development until the next full minute
So I use a virtual switch to trigger the script immediately after I corrected a typo or a bug. When the script is ready and tested you can remove that part.
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 11:01
by sailmich
Is it possible to get a time stamp for the xml file? Sometimes my weatherstation lost the USB connection to my Rpi. In that case the domoticz script got old data but doesn't remark it. So I have the same datas on my dummy devices for hours:(
I know this code want work but it's just to show what I'm talking about.
If timestamp 5 times equal then
ssh reboot my weatherpi
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 17:37
by waaren
sailmich wrote: ↑Wednesday 25 March 2020 11:01
Is it possible to get a time stamp for the xml file?
Yes, in below example I use station_time for that
You will have to change the ssh bootcommand in line 115 as I don't know what command you need for that.
Code: Select all
local url = 'http://xxx.xxx.xxx.xxx/weewx_pws.xml'
local scriptVar = 'getXML'
return
{
on =
{
timer =
{
'every minute at daytime',
},
devices =
{
'triggerhulp',
},
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('Barometer') -- devicetype Barometer
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)))
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: Wednesday 25 March 2020 18:25
by sailmich
Hello waaren, thx again for your help.
in this line
if dz.data.stationTime == rt.station_time then dz.data.equalCounter = dz.data.equalCounter + 1
I got an error
2020-03-25 18:25:01.209 Error: dzVents: Error: (3.0.1) getXML: ...ticz/scripts/dzVents/generated_scripts/Wetterstation.lua
attempt to index a nil value (field 'data')
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 20:14
by waaren
sailmich wrote: ↑Wednesday 25 March 2020 18:25
I got an error
2020-03-25 18:25:01.209 Error: dzVents: Error: (3.0.1) getXML: ...ticz/scripts/dzVents/generated_scripts/Wetterstation.lua
attempt to index a nil value (field 'data')
Are you sure you copied / paste all new lines ?
I suspect that you missed the data part between logging = and execute =
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 20:19
by sailmich
I try to understand the code and have some questions and remarks. I put them into your code. The error occur in the second line.
Code: Select all
local rt = getData(item.data) --local rt should find and get all datas in xml? Why
if dz.data.stationTime == rt.station_time then dz.data.equalCounter = dz.data.equalCounter + 1
--compare the two times if false then counter +1.
--Where is dz.data.stationTime from? I assume rt.station_time should be station_time from xml?
--rt.station_time because of line before?
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 20:47
by sailmich
You are right. Know it's working! THX again for your help!
Re: Help needed get Data from Weatherstation Lua to dzvents
Posted: Wednesday 25 March 2020 20:53
by waaren
sailmich wrote: ↑Wednesday 25 March 2020 20:19
I try to understand the code and have some questions and remarks. I put them into your code. The error occur in the second line.
--compare the two times if false then counter +1.
No the other way around. When equal increase counter