I have here a device which controls the floor heaters and gets the room temperatures. Its easy reachable via a local IP adress. No authentification required.
I hope i am right so far: I opened the adress in chrome and also opened this chrome sidebar which shows all the code. I was able to find the little box in the code, which holds the value of the room temperature. See below:
Anyway, i am not able to figure this out by myself. Is there any basic tutorial on how i can “extract” values from a web-page via XPATH into the HTTP-Binding? Tried to understand the documentation, no chance I need more basic step-by-step instructions.
So, for now i installed the XPATH binding. But i dont get, how to work with it. Ofc i found the “copy Xpath” and “copy full Xpath” option in chrome browser. They look like this:
The “stateTransformation” field requires the type of transformation you want to perform on the input.
Try this:
XPATH://*[@id="ControllerTActual1"]
The reason is: XPATH is not the only kind of transformation available in openHAB. There is also JSONPATH, MAP, JS, …
See Transformations | openHAB and Add-ons | openHAB (section “Data Transformation”)
An additional hint, totally unrelated to your question: Since you are dealing with temperatures here, you can check the “Show advanced” checkmark (above the “State Transformation” field) and enter “°C” in the “Unit” field. this makes the result a “temperature” instead of just a unit-less number.
@Fleck
okay, done. Sadly no change, still showing UNDEF on the item.
Does the HTTP-Binding need something else it can read from? Or does it read from the actual page (see photo above)?
Your thing config appears to be correct. I just created a test-thing and test-item, which worked and looked identical to yours.
Try disabling and re-enabling the thing and see if it makes a difference.
Or, the problem could be in the webpage: Perhaps indexdesktop.html loads the temperatures with a Javascript? Can you try to just load indexdesktop.html without a browser? E.g. curl -o http://192.168.178.20/indexdesktop.html | grep ControllerTActual1 from a Linux terminal or $html=Invoke-WebRequest http://192.168.178.20/indexdesktop.html; $html.ParsedHtml.getElementsByClassName("colA")[0].getAttribute("outerHTML") (you might have to try [1] or higher number before .getAttribute) in Windows Powershell.
Or, perhaps simpler, create a second channel of type string, with the same URL but no stateTransformation, link it to a string item and check the result.
If the temperature is present in the raw html I don’t know what could be wrong.
Hi Jens, back on it
I just tested what you supposed with the new channel. However, i found out something new: The device (Heizungssteuerung) has got a XML-API (german: XML-Schnittstelle). So now i can reach another page http://192.168.178.20/data/static.xml
I created a new string channel with this adress and indeed, i can see a lot of text, including the temperature for i.e. Schlafzimmer.
Now, in the browser i opened this side-menu and searched for i.e. the line with the temperature i need. I can click directly on the value (22.0) → copy XPATH. I pasted it into another channel. Sadly it shows “UNDEF.”
I think i am very close Must be something wrong with the XPATH.
The left side and the right side of the screenshot show different things. The right-hand side is probably what the browser made of the xml. Assuming the left screenshot is the actual text retrieved from data/static.xml try this xpath:
XPATH://HEATAREA[@nr="1"]/T_ACTUAL/text()
If it still does not work, try linking a string item to your Test1 channel. This should show the entire xml. You can then copy this text and try the xpath expression in an online XPath tester .
This way you can find out if the problem is in the stateTransformation or if there is a problem even earlier with retrieving the entire xml.
By writing an xml string similar to your screenshot in the input field of some random online xpath tool and then thinking about how to identify the desired node. The rest was trial and error
In the case of xml, the items are sorted in a „tree“. The data we are looking for (22) is the text of the node „T_ACTUAL“, which in turn is part of the node „HEATAREA“. Since HEATAREA might appear more than once (I don‘t know the entire xml) we use the attribute „nr=1“ to identify this exact HEATAREA. The tricky part was only the two slashes at the start, which mean „look in any subnode“ (not just in the „root“ of the xml tree) and the brackets after HEATAREA which are a condition, meaning „HEATAREA where the attribute „nr“ has the value „1“. Simple as that
New device, same problem…
I am trying forever to find out the correct XPATH. Would you mind helping me again?
This is really hard for noobs like me, sigh.
This one is a litte tricky, i guess. Its from my inverter (Photovoltaik). At night (like just right now) these lines at “measurement” sometimes disappear. I Would like to read out the values for i.e. voltage or power (which right now is not visible, because its zero).
The difference to the previous xpath expression is:
We do not want the text contents of an xml node (<nodename>text content</nodename>) but an attribute: This results in /@Value for the last part of the expression.
We want just the value of the attribute („240.123“) instead of the entire attribute (value=„240.123“), this requires enclosing the entire expression the the string() function.