XPATH - how can I return a value from this XML

Hi Forum
Please can you help me to return a value from an XML file? I have read all of the other posts around the forum on this, and nothing helps.
My XML file is:

<?xml version="1.0"?>
<response><device><id>2174</id><description>Ciano60l</description><type>1</type><time_diff>0</time_diff><status><disconnected>0</disconnected><slide_serial>m19ry904qr1</slide_serial><slide_expires>1564913415</slide_expires><out_of_water>0</out_of_water><wrong_slide>0</wrong_slide><last_experiment>1564854961</last_experiment></status><exps><temperature><trend>1</trend><critical_in>3</critical_in><avg>25.756</avg><status>0</status><curr>25.750</curr><advises/></temperature><ph><trend>1</trend><critical_in>-1</critical_in><avg>7.25</avg><status>0</status><curr>7.26</curr><advises/></ph><nh3><trend>0</trend><critical_in>-1</critical_in><avg>0.156</avg><status>1</status><curr>0.156</curr><advises/></nh3><light><max_value>100</max_value><status>0</status><curr>19</curr><advises/></light></exps></device></response>

and my Item is as follows:

String myTemp "myTemp [%s]" {http="<[https://api.seneye.com/v1/devices/?IncludeState=1&user=[USERNAME GOES HERE BUT DELETED FOR FORUM POST]&pwd=[PASSWORD DELETED]:300000:XPATH(/response/device/exps/temperature/curr/text())]"}

and the data it returns is the whole thing, not just the Current Temperature (which is what I’m trying to get)

image

Can anyone help? The XPATH transformation and the HTTP binding are both installed, and as you can see, the item is getting values from the api but it is returning everything not just the specific value I want…

Useful stuff in this thread

Thanks rossko but this didn’t help; I read all the XPATH-related threads before posting :slight_smile:

Try working on it in a rule, easier to play with to work out the right form.

Hello, i had the same struggle!

I was trying diffent options. and I found the soulution for the seneye problem.

when I found a website to load the url I saw the problem:


strange it is XML But i was thinking this is more like json!

so I want to check the code:
I was going to the website: jsonpathfinder.com


and i paste the code. I also press the button beautify
on the right side you can check the tree and he show your the JSON Path

So I was thinking lets test this!

Number Aquarium_Temperature "Temperatuur[%.1f °C]"  { http="<[https://api.seneye.com/v1/devices/?IncludeState=1&user=XXX&pwd=XXX:10000:JSONPATH($..exps.temperature.curr)]" }

and it worked!!

2020-01-30 01:25:47.994 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'devices.items'
==> /var/log/openhab2/events.log <==
2020-01-30 01:25:49.083 [vent.ItemStateChangedEvent] - Aquarium_Temperature changed from [{"id":"4920","description":"Juwel Rio 125","type":"1","time_diff":"0","status":{"disconnected":"0","slide_serial":"M38PK166MN3","slide_expires":"1582841419","out_of_water":"0","wrong_slide":"0","last_experiment":"1580342821"},"exps":{"temperature":{"trend":"0","critical_in":"-1","avg":"23.576","status":"0","curr":"23.500","advises":[]},"ph":{"trend":"-1","critical_in":"-1","avg":"7.93","status":"0","curr":"7.92","advises":[]},"nh3":{"trend":"0","critical_in":"-1","avg":"0.035","status":"0","curr":"0.034","advises":[]},"light":{"max_value":"1","status":"0","curr":"100","advises":[]}}}] to **23.500**

This is why XPath not will work!

That worked for me! Thank you so much for your help :smile: