I would like to create a sensor with multiple attributes, or multiple sensors (whichever is more appropriate) parsed from XML that is returned from an HTTP GET call as shown below, to be used in triggers to catch when values of specific items change and in actions to pass the values of the items.
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Response Status="OK">
<Item Name="ZoneID">10086</Item>
<Item Name="ZoneName">Channel 1</Item>
<Item Name="State">2</Item>
<Item Name="FileKey">2088610</Item>
<Item Name="NextFileKey">-1</Item>
<Item Name="PositionMS">47574494</Item>
<Item Name="DurationMS">0</Item>
<Item Name="ElapsedTimeDisplay">13:12:54</Item>
<Item Name="RemainingTimeDisplay">Live</Item>
<Item Name="TotalTimeDisplay">Live</Item>
<Item Name="PositionDisplay">13:12:54 / Live</Item>
<Item Name="PlayingNowPosition">0</Item>
<Item Name="PlayingNowTracks">1</Item>
<Item Name="PlayingNowPositionDisplay">1 of 1</Item>
<Item Name="PlayingNowChangeCounter">35</Item>
<Item Name="Bitrate">0</Item>
<Item Name="Bitdepth">32</Item>
<Item Name="SampleRate">48000</Item>
<Item Name="Channels">2</Item>
<Item Name="Chapter">0</Item>
<Item Name="Volume">-1</Item>
<Item Name="VolumeDisplay">N/A</Item>
<Item Name="ImageURL">MCWS/v1/File/GetImage?File=2088610</Item>
<Item Name="Artist">BBC</Item>
<Item Name="Album">Streaming Radio</Item>
<Item Name="Name">BBC 6 Music</Item>
<Item Name="Status">Playing</Item>
<Item Name="Album Artist">BBC</Item>
</Response>
I’ve read documentation and hints and tried some experiments, but I just don’t understand what I’m doing and nothing I’ve tried works. Note I’m obviously a novice when it comes to “programming” HA and its object models.
For example, I don’t understand the difference between things like
command_line:
- sensor:
command: 'curl <URL call>'
and
rest:
- resource: <URL call>"
and
sensor:
- platform: rest
resource: <URL Call>
and then how to parse the result to create multiple attributes, and I don’t understand the references to lists of JSON attributes.
I followed the reply marked as a solution in this thread REST sensor with multiple attributes - #5 by tom_l, which seemed to be the most straightfoward and simple way of doing it, but I can’t get it working. I’ve got this snippet in my configuration.xml:
rest:
- resource: "<my URL call>"
scan_interval: 5
sensor:
- name: "Album"
value_template: "{{ value_json.album }}"
- name: "ImageURL"
value_template: "{{ value_json.imageurl }}"
But the sensors just have nothing in them. (I’ve also tried camelcasing the json attributes to match the case in the XML). I’m wondering if this YAML isn’t the right thing to do for the format of the XML that is supplied,. but I have no idea what to do.
I am on the latest versions of all the software:
Core 2024.9.1
Supervisor 2024.09.1
Operating System 13.1
Frontend 20240906.0
Can anyone provide some guidance for me?