XML to rest_sensor

Hi,

I have a NAD receiver (368) with BlueOS.

  • The BlueOS integration has no functionality to switch input sources or adjust volume

With a rest_command i’m able to switch the input source of the NAD receiver.

The next step is to show the status of the current source (HDM1, HDMI 2, Optical, etc)

With a browser request i’m able to get the followwing XML:

<SyncStatus icon="/images/players/C368_nt.png" db="-48.5" modelName="C368" model="C368" brand="NAD" initialized="true" id="192.168.1.145:11000" mac="90:56:82:0E:82:27" volume="31" name="Woonkamer receiver" etag="117" schemaVersion="34" syncStat="117">
<externalSource id="9" isBluos="true" name="BluOS">
<item id="1" name="Optical 1"/>
<item id="2" name="Optical 2"/>
<item id="3" name="Coaxial 1"/>
<item id="4" name="Coaxial 2"/>
<item id="5" name="Phono"/>
<item id="6" name="Line 1"/>
<item id="7" name="Line 2"/>
<item id="8" name="Bluetooth"/>
<item id="9" isBluos="true" name="BluOS"/>
<item id="10" name="HDMI 1"/>
<item id="11" name="HDMI 2"/>
<item id="12" name="HDMI 3"/>
<item id="13" name="HDMI ARC"/>
</externalSource>
</SyncStatus>

The status I want to display is the ‘name’ of the ‘externalSource’ → ‘BluOS

Content-type: text/xml; charset=utf-8

I used the following code within the configuration.yml:

rest:
  # NAD XML webservice
  - resource: "http://192.168.1.145:11000/SyncStatus"
    scan_interval: 5

    sensor:
      - name: "Actual source"
        value_template: "{{value_json.SyncStatus.externalSource._name}}"

In the Home Assistant log I only see the followwing line:

Template variable warning: 'dict object' has no attribute 'name' when rendering '{{value_json.SyncStatus.externalSource.name}}'

I don’t know what is wrong.

Regards,

Daniël

Try:

        value_template: "{{ value_json['SyncStatus']['externalSource']['@name'] }}"

Conversion spec, referenced from REST sensor docs:
https://www.xml.com/pub/a/2006/05/31/converting-between-xml-and-json.html

You make my day!

1 Like

Hi @Daniel_Bolt just started new with 2 BluoOS devices and likely because we are 7 months later the Bluesound integration matured more in this respect. Included automation will adjust the volume and select the station (which is under a prefix)

alias: Audio - Roksan Actions
description: Audio - Roksan in the morning
trigger:
  - platform: state
    entity_id:
      - binary_sensor.frient_occupancy
    to: "on"
condition:
  - condition: time
    after: "06:40:00"
    before: "09:00:00"
action:
  - service: media_player.volume_set
    metadata: {}
    data:
      volume_level: 0.18
    target:
      entity_id: media_player.roksan
  - service: media_player.select_source
    target:
      entity_id: media_player.roksan
    data:
      source: 92.6 | NPO Radio 2
  - service: media_player.media_play
    metadata: {}
    data: {}
    target:
      entity_id: media_player.roksan
mode: single

I also got hold on a copy the “BluOS Custom Integration API” and the rest_command for volume would be: http://192.168.1.100:11000/Volume?level=15.
for skipping through your presets you might want to try

rest_command:
  bluos_preset_roksan:
    url: "http://192.168.x.x:11000/Preset?id=+1"

Most likely you are already aware of all above but if not hope it is helpful.