[lua_parsesr script] XML parsing for HTTP poller help
Posted: Wednesday 04 January 2017 13:34
Hi,
have a air quality internet xml source in my country I would like to add in domoticz for my city.
The XML looks like this:
Before creating my lua script, I used xmllint with xpath option to get value I need for my city (agglomerationCodeInsee=76540)
So on linux I tried:
Result is:
Now, I created a HTTP poller with the URL, and a airquality.lua in the domoticz/scripts/lua_parsers folder.
It looks like this:
Issue I have is I never retrieve the actual value, it's not an integer but a boolean I get.
In domoticz logs:
Is there a bug or I'm doing something wrong ?
have a air quality internet xml source in my country I would like to add in domoticz for my city.
The XML looks like this:
Code: Select all
<!-- -->
<root>
<node>
<dateIndice>2017-01-03</dateIndice>
<agglomerationCodeInsee>97209</agglomerationCodeInsee>
<agglomeration>FORT-DE-FRANCE</agglomeration>
<valeurIndice>3</valeurIndice>
<SousIndiceO3>2</SousIndiceO3>
<SousIndiceNO2>2</SousIndiceNO2>
<SousIndicePM10>3</SousIndicePM10>
<SousIndiceSO2/><Commentaire/>
<sourceAASQA>http://www.lcsqa.org/aasqa/code/39</sourceAASQA>
</node>
<node>
<dateIndice>2017-01-03</dateIndice>
<agglomerationCodeInsee>76540</agglomerationCodeInsee>
<agglomeration>ROUEN</agglomeration>
<valeurIndice>5</valeurIndice>
<SousIndiceO3>1</SousIndiceO3>
<SousIndiceNO2>2</SousIndiceNO2>
<SousIndicePM10>5</SousIndicePM10>
<SousIndiceSO2>1</SousIndiceSO2>
<Commentaire/><sourceAASQA>http://www.lcsqa.org/aasqa/code/25</sourceAASQA>
</node>
...
...
</root>
So on linux I tried:
Code: Select all
$ wget -O test.xml http://www.lcsqa.org/surveillance/indices/prevus/jour/xml/
$ xmllint --xpath '//node[agglomerationCodeInsee=76540]/valeurIndice/text()' test.xml
Code: Select all
5
It looks like this:
Code: Select all
-- ID domoticz
local deviceId = 133
-- Retrieve the request content
s = request['content'];
-- Parse XML values
local iGlobal = domoticz_applyXPath(s,'//node[agglomerationCodeInsee=76540]/valeurIndice/text()')
print('Indice: ' .. iGlobal)
-- Update device
domoticz_updateDevice(deviceId,'',iGlobal)
In domoticz logs:
Code: Select all
2017-01-04 13:24:36.408 CLuaHandler: udevices: Indice: true