Reading XML data and display specific element value

Hi. I am after reading the XML data from the following URL: https://uvdata.arpansa.gov.au/xml/uvvalues.xml and display only the UV index value for a certain city, say “Sydney”

Anyone can help how can I achieve this?

1 Like

Have a look at the scrape sensor.

It should be able to do what you want

Or

'curl -k --silent "https://uvdata.arpansa.gov.au/xml/uvvalues.xml" | sed -n '122p' | cut -c 12-14'

will work as a command line sensor, although it will break if any changes are made to the page

1 Like

Hi @muhammad.taimur did you ever get this to work for web scrape?

DW i got it to work. If anyone else wants here is the code

  - platform: scrape
    resource: https://uvdata.arpansa.gov.au/xml/uvvalues.xml
    name: UV Index Sydney ARPANSA
    select: "location > index"
    index: 15
    unit_of_measurement: "UV Index"
2 Likes

Thanks @vijaykbhatia I never came back to this post. But your code also works for me:

sensor:
  - platform: scrape
    resource: https://uvdata.arpansa.gov.au/xml/uvvalues.xml
    name: UV Index Sydney ARPANSA
    select: "location > index"
    index: 15
    unit_of_measurement: "UV Index"
2 Likes

This also worked for me:

sensor:
  - platform: rest
    name: ARPANSA UV Melbourne
    resource: https://uvdata.arpansa.gov.au/xml/uvvalues.xml
    state_class: measurement
    unique_id: arpansa_uv_melbourne
    value_template: "{{ value_json.stations.location[12].index }}"