Struggling with what should be a simple XML read

Hi, I’m new to the whole HA set-up and Im trying to get some XML read and simply displayed, but although I feel Im close, no cigar yet.
The XML is simple enough:

<xml>
<iKettle>
<status>Not Enough Water</status>
<allowboil>N</allowboil>
<temp>73</temp>
<waterlevel>9</waterlevel>
</iKettle>
</xml>

And I’ve followed the example given here RESTful Sensor - Home Assistant for " FETCH MULTIPLE JSON VALUES AND PRESENT THEM AS ATTRIBUTES" And created the following:

sensor:
  - platform: rest
    name: JSON ikettle2
    resource: http://192.168.x.x:88/iKettle/xml.php
    value_template: "{{ value_json.xml.iKettle }}"
    json_attributes:
      - status
      - allowboil
      - temp
      - waterlevel
  - platform: template
    sensors:
      ikettle2_status:
        friendly_name: "Kettle Status"
        value_template: "{{ state_attr('sensor.json_ikettle2', 'status' }}"
      ikettle2_temperature:
        friendly_name: "Kettle temperature"
        value_template: "{{ state_attr('sensor.json_ikettle2', 'temp') }}"

But I cannot get the Status or temp to appear, and when I look at the JSON iKettle2 sensor it says the following:

{‘status’: ‘Not Enough Water’, ‘allowboil’: ‘N’, ‘temp’: ‘19’, ‘waterlevel’: ‘-34’}

So the data is there, but

Kettle status Unknown
Kettle temperature Unknown

And this is what I cant get my head around. I’ve looked at quite a few posts but they all seem to talk about getting one variable where as I want all of them. - I can get one variable if I do:

sensor:
  - platform: rest
    name: JSON ikettle2
    resource: http://192.168.x.x:88/iKettle/xml.php
    value_template: "{{ value_json.xml.iKettle.status }}"
 json_attributes:
      - status

Any help appreciated or tell me where I’m going wrong.

Is the page actually setting the doc type to xml?

Thanks, and good point. And this might be missed as Im just letting the php output the xml the way it wants to.
So yes on looking at it, it is just saying

<?xml version="1.0" ?>

I will sort out the DOCTYPE and see if it works.

So you are writing the other end as well? If so, it would be a heck easier to send out JSON instead of XML :slight_smile:

I am, but had never output json, however after a quick fiddle I did output json and it works fine now :slight_smile:

1 Like