HTTP/HTTPS Poller: Get variables

Moderator: leecollings

Post Reply
McFranky
Posts: 11
Joined: Thursday 10 March 2016 6:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

HTTP/HTTPS Poller: Get variables

Post by McFranky »

Hi
I use the HTTP Poller to get a weather forcast from openweathermap like this:

URL: http://api.openweathermap.org/data/2.5/ ... its=metric

The answer of this call is:

Code: Select all

<weatherdata>
<location>
<name>Berlin</name>
<type/>
<country>DE</country>
<timezone/>
<location altitude="0" latitude="52.524368" longitude="13.41053" geobase="geonames" geobaseid="0"/>
</location>
<credit/>
<meta>
<lastupdate/>
<calctime>0.103</calctime>
<nextupdate/>
</meta>
<sun rise="2016-11-23T06:43:36" set="2016-11-23T15:02:02"/>
<forecast>
<time from="2016-11-23T15:00:00" to="2016-11-23T18:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation/>
<windDirection deg="239.507" code="WSW" name="West-southwest"/>
<windSpeed mps="1.29" name="Calm"/>
<temperature unit="celsius" value="4.97" min="4.97" max="6.25"/>
<pressure unit="hPa" value="1028.4"/>
<humidity value="86" unit="%"/>
<clouds value="broken clouds" all="56" unit="%"/>
</time>
<time from="2016-11-23T18:00:00" to="2016-11-23T21:00:00">
<symbol number="803" name="broken clouds" var="04n"/>
<precipitation/>
<windDirection deg="310.001" code="NW" name="Northwest"/>
<windSpeed mps="1.33" name="Calm"/>
<temperature unit="celsius" value="5.17" min="5.17" max="6.03"/>
<pressure unit="hPa" value="1028.8"/>
<humidity value="88" unit="%"/>
<clouds value="broken clouds" all="64" unit="%"/>
</time>
.
.
. 
With my LUA-Script I get the most important values for me for the first Time table (15:00-18:00). But how I get the values for the second Time table (18:00-21:00)?

Code: Select all

-- Retrieve the request content
s = request['content'];

-- Hole Wetterdaten

local t_from	= domoticz_applyXPath(s,'//weatherdata/forecast/time/@from')
local temp 		= domoticz_applyXPath(s,'//weatherdata/forecast/time/temperature/@value')
local humidity 	= domoticz_applyXPath(s,'//weatherdata/forecast/time/humidity/@value')
local pressure 	= domoticz_applyXPath(s,'//weatherdata/forecast/time/pressure/@value')
local wb 		= domoticz_applyXPath(s,'//weatherdata/forecast/time/windDirection/@deg')
local wd 		= domoticz_applyXPath(s,'//weatherdata/forecast/time/windDirection/@code')
local ws 		= tostring(tonumber(domoticz_applyXPath(s,'//weatherdata/forecast/time/windSpeed/@mps'))*1.60934)
local wg 		= domoticz_applyXPath(s,'//weatherdata/forecast/time/windSpeed/@mps')
local clouds	= domoticz_applyXPath(s,'//weatherdata/forecast/time/clouds/@all')

print('Time: '..t_from)
print('Temperatur: '..temp..' °C')
print('Feuchte: '..humidity..' %')
print('Druck: '..pressure..' hPa')
print('Windrichtung: '..wb..' ° '..wd)
print('Windgeschw.: '..ws..' km/h')
print('Wolken: '..clouds..' %')


--Barometer aktualisieren
domoticz_updateDevice(459,0,temp .. ";" .. humidity .. ";0;" .. pressure .. ";0")
--Wetter aktualisieren
domoticz_updateDevice(460,0,wb .. ";" .. wd .. ";" .. ws .. ";".. wg .. ";".. temp .. ";".. temp )
--Bewölkung in Prozent
domoticz_updateDevice(461,0,clouds)
Greetings from Berlin...
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by pj-r »

LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
McFranky
Posts: 11
Joined: Thursday 10 March 2016 6:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by McFranky »

But how this works in LUA?
I don't find any discription for the 'domoticz_applyXPath' command.
Greetings from Berlin...
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by pj-r »

I assume the second parameter of domoticz_applyXPath method is accepting string in XPath syntax.. its nothing lua special. You are already using XPath syntax in your script.
https://en.wikipedia.org/wiki/XPath
http://www.w3schools.com/xml/xpath_intro.asp
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
McFranky
Posts: 11
Joined: Thursday 10 March 2016 6:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by McFranky »

OK. If I try this

Code: Select all

t_from=domoticz_applyXPath(s,'//weatherdata/forecast[contains(@time,'15:00:00')]')
there is no action...

Any ideas?
Greetings from Berlin...
McFranky
Posts: 11
Joined: Thursday 10 March 2016 6:20
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by McFranky »

OK I got the solution:

Code: Select all

t_from	= domoticz_applyXPath(s,'//weatherdata/forecast/time[contains(@from,'15:00:00')]/@from')
this gets the right variable...

Thanks :D
Greetings from Berlin...
pj-r
Posts: 140
Joined: Wednesday 17 December 2014 17:30
Target OS: Linux
Domoticz version: V3.8650
Location: Jyväskylä, Finland
Contact:

Re: HTTP/HTTPS Poller: Get variables

Post by pj-r »

Good to hear you got it working!
LXC(x64 Ubuntu Xenial), RFXtrx433E, MySensors
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests