Http binding XML state transformation

Hi, just a short question. Cant find any answers that fits.
I have a http binding returning a state which is a XML string.

<status><streamUrl>value</streamUrl></status>

I would like to retrieve the value from the XML within the channel configuration as state tansformation but I can’t find any examples for the XPath transform.

Could someone help me out or point me in the right direction?

Best regards,

https://www.w3schools.com/xml/xpath_intro.asp
http://xpather.com/

Thank you @rlkoshak for your reply
I have the transform set as

XPATH:/status/streamUrl

I’m stuck on the formatting for things read transform in the GUI.

Best regards,

Assuming that the xpath string itself is correct I don’t see anything wrong with how you’ve formatted it in the HTTP binding. But I don’t use the HTTP binding so don’t know if there are some quirks.

But pay attention to case. Case matters. Your example XML is streamurl not streamUrl.

Hi @rlkoshak ,

Thank you for your time and thoughts. After a restart of openhab it works as expected on the thing and on the item.

On the Item " BluOsNAD_Presets" I have a Metadata state description containing two radio stations as options in the format ‘value = label’:

http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO10.mp3 = Radio 10
http://playerservices.streamtheworld.com/api/livestream-redirect/RADIO538.mp3 = Radio 538

From the UI I have a widget that send command ‘label’ to the Item.
The Items resolved the URL and sends it to the the player using a command url extension. That all works fine, the radio changes stream.

Play?url=%2$s

Backwards, the channel requests the player state XML using the state url extension

Status

And retrieves the current playing streamUrl value using the state transformation

XPATH:/status/streamUrl

The Item resolves the station label matching the option list, and the radio station is visible in the Item (‘Radio 10’ or ‘Radio 538’).

If I place a simple text label and select the Item (graphically), it will display the currently playing radio station (‘Radio 10’ or ‘Radio 538’).

So far so good :upside_down_face:

I created a custom Widget using the oh-list-item but it keeps displaying ‘UNDEFINED’ or ‘-’ for .state and for .stateDisplay. I tried it several ways but nothing seems to work

uid: widget_Radio
tags: []
props:
  parameters:
    - description: A text prop
      label: Prop 1
      name: prop1
      required: false
      type: TEXT
    - context: item
      description: An item to control
      label: Item
      name: player
      required: false
      type: TEXT
  parameterGroups: []
timestamp: Sep 15, 2021, 4:20:56 PM
component: oh-list-card
config:
  noHairlinesBetween: true
slots:
  default:
    - component: oh-list-item
      config:
        title: =items[props.player].stateDisplay + items[props.player].state
        after: =items['BluOsNAD_Presets'].stateDisplay
        smartSelect: true
        icon: f7:music_albums
        iconColor: default
        popupOpen: .PopupMusik
        style:
          border: 1px solid lightgray
          border-radius: 5px
    - component: f7-popup
      config:
        class: PopupMusik
      slots:
        default:
          - component: f7-page
            slots:
              default:
                - component: f7-navbar
                  config:
                    title: Radio
                    style:
                      position: sticky
                  slots:
                    left:
                      - component: oh-link
                        config:
                          iconIos: f7:arrow_left
                          iconMd: material:arrow_back
                          iconAurora: f7:arrow_left
                          popup-close: true
                - component: f7-list
                  config:
                    virtualList: true
                  slots:
                    default:
                      - component: oh-repeater
                        config:
                          sourceType: itemStateOptions
                          itemOptions: BluOsNAD_Presets
                          for: option
                          fragment: true
                        slots:
                          default:
                            - component: oh-list-item
                              config:
                                title: =loop.option.label
                                actionFeedback: ='{ "text":"You selected <b>' + loop.option.label + '</b><br>Sending command <b>' +  loop.option.value + '</b> to item", "position":"center","icon":"<i style=\\"color:green\\" class=\\"f7-icons\\">checkmark_alt</i> }'
                                noChevron: true
                                radio: true
                                checked: "=loop.option.value === items['BluOsNAD_Presets'].State ? true : false"
                                popupClose: true
                                action: command
                                actionItem: BluOsNAD_Presets
                                actionCommand: =loop.option.value

I’m missing something :roll_eyes:

The property name is “player”. So you need it use =items[props.player].state.

stateDisplay will only exist if you’ve set the State Description Item metadata.

Hi @rlkoshak ,

Thank you for your time and observation. Indeed, props was missing.
The .state now returns the streamUrl but the .stateDisplay returns empty content.

I’ve set the state description which is shown in the Item

Configuration of the state description
BluOs_Item_StateDescription

Radio station is shown in a simple label card, but not in the oh-list-item as ‘tilte’ or ‘after’.
label-card-state-description

Best regards,

Well, yes. The state is the current state of the Item. The displayState is the current state of the Item with the Pattern defined in the State Description applied to it. Neither contains the the list of Options.

To display the Options you need to set the Action to show them when the widget is clicked on. See Building Pages - Components & Widgets | openHAB. You want “Command Options”.

hi @rlkoshak ,

again thank you for your patience.
I did not post the full widget code, I only posted that what I thought was relevant. Sorry, I updated the Widget posted earlier.

The configuration of the streaming device works fine (action command) what does not work is read back the status as .stateDescription.
The Thing returns the streamUrl to the Item, the items resolves this into the corresponding label, the label should be displayed (but is not).

Best regards,

Well, as I said a couple times now, the stateDescription only exists if you’ve set the Pattern.

Hi @rlkoshak ,

I’ve to configure the Pattern for the state description. You mentioned it once with command action. I was focussing on the command action, sorry for that. There are just soooo many options :exploding_head:

I’ll look into the pattern configuration.
Thank you for helping me out.

Best regards,

And I see a typo, stateDisplay should be displayState. And now it works as expected.
Even without the configuration of Pattern in the Items state-description, somehow the stateDescription exists if the Pattern is not set (because it’s already a string Item?

I’ll post the final configs later on.