HTTP/HTTPS poller xml parser

Moderator: leecollings

Post Reply
damdub
Posts: 38
Joined: Tuesday 31 December 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

HTTP/HTTPS poller xml parser

Post by damdub »

Hello
I'm aiming to retrieve data from my heat pump. I'm using HTTP/HTTPS poller & an xml parser script.

The heat pump is providing data into an xml file.
The data from this xml wich I'm trying to retrieve is "ACTUAL TEMPERATURE 2"
Here is a litte portion of the xml file (which is pretty big) containing the "ACTUAL TEMPERATURE 2" data. Actual value which I want to retreive in domoticz is "22,1°C".

Code: Select all

<div class="clear"></div></div>
        <form id="werte" action="#" onsubmit="saveValues(this);return false;"><div id="content">
    <div class="span-11 append-1" style="float:left"><table class="info"><tr><th colspan="2" class="round-top">ROOM TEMPERATURE</th></tr>  <tr class="even">
    <td class="key">ACTUAL TEMPERATURE 2</td>
    <td class="value">22,1°C</td>
  </tr>


I've created a lua xml parser script which I want to use to retreive data and use it in domoticz

Code: Select all

s = request['content'];

local ACTUAL_TEMPERATURE_2 = domoticz_applyXPath(s,'<td class="key">ACTUAL TEMPERATURE 2</td><td class="value">(.-)</td>')

domoticz_updateDevice(343,'',ACTUAL_TEMPERATURE_2)
This is not working.
Domoticz logs show an error
" Error getting data from url"

Is there somebody who could help me correct my lua script ?
Thank you in advance
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: HTTP/HTTPS poller xml parser

Post by waltervl »

Could be because it does not look like xml but html data.

The error could also be that it is not getting any data at all due to misconfiguration.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
damdub
Posts: 38
Joined: Tuesday 31 December 2019 16:29
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: HTTP/HTTPS poller xml parser

Post by damdub »

Hello and thank you for your reply

Maybe I'm wrong but I was confident taht it was xml, but maybe xml can be embedded in html ? Sorry for my incompetence

Here are the first lines of the file which I'm trying to parse.

Code: Select all

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="de">
<head>
xml ? html ? parsable ? :?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: HTTP/HTTPS poller xml parser

Post by waltervl »

I am also no expert but normally xml does not have html statements in it.
I think you have to set the path to the value starting with head

Perhaps you can test it with an online Xpath tester: https://www.freeformatter.com/xpath-tester.html
Also take a look at the Xpath examples on the end of that page.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
User avatar
bewo
Posts: 74
Joined: Monday 13 July 2015 12:27
Target OS: Linux
Domoticz version: 2021.1
Location: Bavaria - Germany
Contact:

Re: HTTP/HTTPS poller xml parser

Post by bewo »

Hey damdub,

is your parser working? If not, there are multiple ways to parse your values.

First of all i would check if the heatpump gives you really an html answer. Maybe this is only the browser output.
Just post the whole answer from your heatpump und the request.

Then we'll get this. ;)
Individual projects:
Domoticz on a Intel Xeon Server | AeonLabs Z-Wave Gen.5 | RFXCOM RFXtrx433E USB | ESP-Wifi-Modules | Shellys
Wall-mounted 22" Touch Control Display (self construct) | LUA wind monitor| LUA heating control | and many many more :)
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest