According to the log file, i only get the following message:
[INFO ] [inding.http.internal.HttpThingHandler] - Using the secure client for thing 'http:url:xpath_zamg'
[INFO ] [openhab.event.ItemStateChangedEvent ] - Item 'xpath_zamg_location' changed from NULL to
It should work on HTML but only if itās xhtml, meaning that it conforms to the XML standard. That means every open tag must have a closing tag and a few other similar requirements. Browsers are not as strict and will be happy to render a page that is missing such things.
But the header shows that the page is claiming to be XHTML so XPath shouldnāt have a problem with it.
Given the data is pulled by the HTTP binding, why not apply the transform there? If there is an error it will be more apparent there as I think the Profile fails silently.
Hi @rlkoshak , thank you for your feedback.
Iāve also read that XHTML should work with XPATH. You mean the XPATH command can be executed directly via the binding? Iāve tried this now and iām one step further. But now the whole XHTML code is downloaded and the desired value is not selected.
That indicates that the actual xpath is not being found. I canāt explain why the online tester works and this does not. Often different programming languages will have slightly different behaviors. Perhaps Java works a little differently.
Hi @rlkoshak, thanks, then i will try another wayā¦
I have now extracted the data via Python-script and BeautifulSoup and saved it in a file. Now i would like to import this output (file) using HTTP binding and output it using an item. In your opinion, is it better to save the data in a csv-file or in a txt-file? (only the values are listed one below the other) Unfortunately, i havenāt found much for OH3 - can i configure everything via the GUI or does a script have to be created for this?
The HTTP binding doesnāt load files. What exactly are you trying to do with the binding here?
The best depends on the nature of the data and your ability to code what needs to load and process that data in a rule.
Thatās not an either or. You can create Script Actions in UI rules which is where you write code for a rule. But to load and parse a file you will have to write some code.
I thought, i might be able to load the file via the binding and process the content in OH.
But what i actually want to do, i fetch the content of the website once an hour using a Python-script and save the content in a file. I store this file in a defined location, from which OH reads the content of the file and displays it in/with an item. For example, the content of the file looks like this:
Kitzbühel 767m 28.5° 29 % Südost, 13 km/h 29 km/h 0.0 mm 81 % 1002.3 hPa
Unfortunately, i donāt really know how to approach this matter. I can certainly look up the individual steps via the forum, but i donāt know what options there are in general and which of them are also useful for my project.
I am currently in the process of familiarizing myself with HABApp, so I would like to implement it in Python if possible.
I canāt help with HABApp. Thatās a completely separate rule engine. You definitely cannot use the OH UI to create or manage HABApp rules.
The HTTP binding can only interact with HTTP servers. It canāt load some random file from your file system.
If you are planning on using HABApp youāll need to learn how to load a file using Python 3 and parse its contents. Then use HABApp features to issue the updates and commands to the relevant Items.
Okay i understand, thanks for the explanation. And if i wanted to do everything with OH, how would that go about here? The rule engine HABApp is not so important to me now, if i could solve this via the internal rule engine, i would honestly prefer that. The only thing that matters to me is that i can do it with Python. The OH Python-binding has already been installed and also works.
Youāve done the hard part, getting the raw data into openHAB.
Manipulating it to extract a value can be done directly in rules, or via a transformation. If you canāt make XPATH work with it, the whole of javascript is available too.
EDIT - the XPATH trouble is about namespace.
The returned webpage includes <html xmlns="http://www.w3.org/1999/xhtml" lang="de">
so all the enclosed html tags are in that namespace.
I had a play in a rule; XPath with "/html/head/title/text()"
returns nothing, because it searches for no-namespace tags. "/*[name()='html']/*[name()='head']/*[name()='title']/text()"
returns Tirol ZAMG from the <title>Tirol — ZAMG</title>
section, using namespace.
Thank you very much @rossko57 you gave me the right hint, now it works!
For all those who find it a little difficult to create the path, chrome has the option of displaying the XPATH path in the developer tools. You still have to modify the output a bit, but it makes the creation of the path a lot easier.
@boogie, are you able to able to provide any more details on what your final XPATH expression was here?
In the XHTML I am trying to parse through (from my old-ish Brother printer), the XPATH expression should ideally be something like:
The value that I want is the ā50ā. It is representative of my printer toner quantity remaining.
I have tried expanding out my XPATH string, something like: "/*[name()='html']/*[name()='body']/*[name()='div']/*[name()='div']/*[name(2)='div']/*[name(2)='div']/ ⦠etc. but that did not seem to work.
The XPATH documentation does not provide any details on how to delve into duplicate tags on the same level of the tree, or how to retrieve properties of tags rather than the text contained within the tagsā¦
I need to get the āstatusā 1 or 0 (it means ON or OFF).
On OH3 I created a HTTP Binding Thing, Iām able to control the relay using the commands but Iām not able to poll for the status, can anyone try to help me please?
There are lots of Xpath testers online where you can paste in the XML and experiment with Xpath expressions until you get it right. They are often also associated with a tutorial. https://codebeautify.org/Xpath-Tester is one but there are others.
Itās been too long since Iāve done Xpath to guess at the right syntax.