I´m trying to use the RESTful integration to get out data from a boiler. The result is in XML format, but as I understood it should convert to JSON according to this page https://xmltodict-debugger.glitch.me/
When using json_attributes the value would only be added as an attribute to the sensor, not as its state.
The JSON you posted does not have a top-level attribute “strValue”, but only an attribute “eta”. You could configure json_attributes_path to extract nested values, but this would still not set the sensor’s state.
What you want is to add value_template: '{{ value_json["eta"]["value"]["@strValue"] }}'. This follows the path through the JSON structure to the value you want to extract.
It should. The integration does that automatically if the webserver providing the XML sends content type text/xml or application/xml as part of the response.
You could for example use Chrome and its developer tools and look for Content-Type in the response header.
(can’t remember if the value should be quoted or not).
[edit]
I should have said that this should load all the data in as an attribute. If that works it is possible to work out the data structure and extract the value(s) required.
That’s the one. That should trigger the conversion from XML to JSON.
One more thing you could try is to increase the log level to debug for this sensor which would give you either “JSON converted from XML…” or “Erroneous XML…”.
Do you get the XML or is it converted to a data attribute of the entity? I would expect for you to get it all. Then create a template sensor to extract it from the attribute.
Look on the states page in HA. Does this entity appear?
[edit]
Looking at the docs, I think you need a
json_attributes_path: $.eta.value.@strValue
to trigger the XML conversion - it may only pull XML data as attributes of an entity. This then needs a template sensor to pull it out of an attribute into a sensor state.
That path just pulls your value into an attribute of the REST sensor.
I edited my suggestion as the OK should be single quoted.
I’ve played around with a similar XML source - it is fussy, but I cannot see why my suggestion won’t work although I wonder if the use of value is the problem.
“Updating from …”: That indicates that the update from that URL is about to happen
Then there is missing a DEBUG message “Data fetched from resource…”.
Then it checks for presence of HTTP response headers.
Next, because there is neither a message “JSON converted from XML…” nor “Erroneous XML…” I assume that either no HTTP response header has been found at all, or no “content-type” header was found, or the content type header does not start with text/xml or application/xml.
The next message “REST result could not be parsed as JSON” occurs because you still have json_attributes configured. But because the conversion from XML to JSON has not actually happened as seen above, this will then of course fail.
A quick test that I have just done is:
Create test.xml in my Apache webserver’s root folder and pasted the XML content you posted in your first post.
This works as expected. Sensor value is set to 79.
So, this all may indicate that your webserver (http://192.168.xxx.xxx:8080/...) does not quite work as expected, i.e. it appears as - despite you getting a correct content-type header in a web browser - the rest integration somehow does not.
Next step that I would take if this was my webserver is to configure the sensor in a developer instance of HA and add more and more DEBUG statements into the code (homeassistant/components/rest/sensor.py) to find out where the HTTP response is not as expected.