Value template for xml response from Jriver

Dear all,
I was trying to create a sensor that listens to Jriver Media Center status (playing, paused, stopped…) to control Audio system via automation. JMC supports Rest API with resource like: JMC_IP:52199/MCWS/v1/Playback/Info?Zone=-1
This will bring the response below.

<Response Status="OK">
<Item Name="ZoneID">0</Item>
<Item Name="State">0</Item>
<Item Name="FileKey">57044</Item>
<Item Name="NextFileKey">57045</Item>
<Item Name="PositionMS">0</Item>
<Item Name="DurationMS">310000</Item>
<Item Name="ElapsedTimeDisplay">0:00</Item>
<Item Name="RemainingTimeDisplay">Live</Item>
<Item Name="TotalTimeDisplay">Live</Item>
<Item Name="PositionDisplay">0:00 / Live</Item>
<Item Name="PlayingNowPosition">30</Item>
<Item Name="PlayingNowTracks">9164</Item>
<Item Name="PlayingNowPositionDisplay">31 of 9164</Item>
<Item Name="PlayingNowChangeCounter">27497</Item>
<Item Name="Bitrate">0</Item>
<Item Name="Bitdepth">0</Item>
<Item Name="SampleRate">0</Item>
<Item Name="Channels">0</Item>
<Item Name="Chapter">0</Item>
<Item Name="Volume">1</Item>
<Item Name="VolumeDisplay">100%</Item>
<Item Name="ImageURL">MCWS/v1/File/GetImage?File=57044</Item>
<Item Name="Artist">Boney M</Item>
<Item Name="Album">The 20 Greatest Christmas Songs</Item>
<Item Name="Name">Medley:</Item>
<Item Name="Status">Stopped</Item>

Now I would like to get the value from the last item (“Status”) as the sensor state to trigger automation. Could you teach me how to create such sensor in HA configuration?
Thanks so much

1 Like

The xml data should be automatically parsed to json. So try this value template:

value_template: "{{ value_json[Response Status] }}"

Edit: actually that may only be for attributes. See the XML example on that page.

Thanks so much for your quick reply. I tried to read the example but could not figure out how to make use up that. Here is what I tried

- platform: rest
    name: JMC_Status
    json_attributes_path: "Response.Item[23][#text]"
    - "#text"
    value_template: "{{ value_json[Response, Status] }}"

The sensor showed “unknown” state.

Have you made any headway in getting HA integrated to JRiver Media Player?

I only could finally get the sensors for the player status that can be used in my automation. Like turn the amplifier on/off based on the play state change.

Can you share what you used to make this happen? Thanks!

Perhaps this is not the most effective way but what I did was create the sensor and get the attribute of the results. Something like this. Remember to put the IP address of your real JMC to the querry.

- platform: rest
    force_update: true
    name: jmc_stat
    json_attributes_path: "Response.Item[-1:]"
      - '#text'
    resource: http://JRiver-IP-Address:52199/MCWS/v1/Playback/Info?Zone=-1
    value_template: '{{ json_value[Response.Item[-1:]["#text"]] }}'
    value_template: 'OK'
  - platform: template
        friendly_name: JMC_Status
        value_template: "{{ state_attr('sensor.jmc_stat', '#text') }}"
1 Like

To get the Status in the original posted XML, this should work provided the status is always the last Item:

- platform: rest
  name: "JMC Status"
  value_template: "{{ value_json['Response']['Item'][-1]['#text'] }}"

Note the difference in the value_template to prior attempts.