Need help parsing XML

Running HA version 0.65.4 on raspberry pi 3

I’m trying to extract a value (Bose Soundtouch Presets Name) from an API result in xml

The local url looks like this http://192.168.1.100:8090/presets

And the result looks like this

 <presets>
   <preset id="1" createdOn="1436994663" updatedOn="1445530963">
     <ContentItem source="INTERNET_RADIO" location="61294" sourceAccount="" isPresetable="true">
       <itemName>NRJ Dance Hits</itemName>
     </ContentItem>
   </preset>
   <preset id="2" createdOn="1436994668" updatedOn="1436994705">
     <ContentItem source="INTERNET_RADIO" location="61264" sourceAccount="" isPresetable="true">
       <itemName>NRJ Glee</itemName>
     </ContentItem>
   </preset>
   <preset id="3" createdOn="1434477206" updatedOn="1461459255">
     <ContentItem source="INTERNET_RADIO" location="43663" sourceAccount="" isPresetable="true">
       <itemName>Ambiance Radio</itemName>
     </ContentItem>
   </preset>
   <preset id="4" createdOn="1434398243" updatedOn="1434398243">
     <ContentItem source="INTERNET_RADIO" location="21300" sourceAccount="" isPresetable="true">
       <itemName>NRJ Hits</itemName>
     </ContentItem>
   </preset>
   <preset id="5" createdOn="1434398137" updatedOn="1465177344">
     <ContentItem source="INTERNET_RADIO" location="38659" sourceAccount="" isPresetable="true">
       <itemName>Ambient Meditation Music</itemName>
     </ContentItem>
   </preset>
   <preset id="6" createdOn="1504992472" updatedOn="1504994950">
     <ContentItem source="INTERNET_RADIO" location="18305" sourceAccount="" isPresetable="true">
       <itemName>1.fm Chillout Lounge</itemName>
       <containerArt>
         http://item.radio456.com/007452/logo/logo-18305.jpg
       </containerArt>
     </ContentItem>
   </preset>
 </presets>

I want to get those <itemName>######</itemName>

I’v been trying with multiple platform like rest, command_line, scrape…etc, for few days with no success

I used Node Red to read the Rubbish Day which Then Send a MQTT message

this is what i get.

Then i node red it

[{"id":"d414d053.6d6bb","type":"http request","z":"422e1f4b.6e0b2","name":"","method":"GET","ret":"obj","url":"http://gissearchwebapiproxy.npdcapps.co.nz/api/rubbishdays/?assessNo=11662/103.23&_=1519363989900","tls":"","x":127.99999237060547,"y":141.00000953674316,"wires":[["7cbc353e.d7e52c","83d2c160.4d59b","ac5dd61.707c128"]]},{"id":"f3eafcbc.469d2","type":"change","z":"422e1f4b.6e0b2","name":"","rules":[{"t":"set","p":"headers","pt":"msg","to":"{\"Accept\":\"application/json\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":317.00000762939453,"y":41.99999809265137,"wires":[["d414d053.6d6bb"]]},{"id":"ef63f112.973c5","type":"inject","z":"422e1f4b.6e0b2","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"01 05 * * *","once":false,"x":123,"y":42,"wires":[["f3eafcbc.469d2"]]},{"id":"1ea02e2d.d3fa72","type":"mqtt out","z":"422e1f4b.6e0b2","name":"","topic":"home/Rubbish/Colour","qos":"","retain":"","broker":"22618f74.c776d","x":609,"y":423,"wires":[]},{"id":"7cbc353e.d7e52c","type":"function","z":"422e1f4b.6e0b2","name":"Rubbish Colour","func":"var newMsg = { payload: msg.payload.PickupWeek };\nreturn newMsg;","outputs":1,"noerr":0,"x":308,"y":244.99998474121094,"wires":[["1ea02e2d.d3fa72","8b3b22b9.a51ca"]]},{"id":"83d2c160.4d59b","type":"function","z":"422e1f4b.6e0b2","name":"Rubbish Day","func":"var newMsg = { payload: msg.payload.PickupDay + \" - \" + msg.payload.PickupWeek };\nreturn newMsg;","outputs":1,"noerr":0,"x":390.00000381469727,"y":123.99999904632568,"wires":[["d62fb1c6.17f23","71295523.90e58c"]]},{"id":"d62fb1c6.17f23","type":"mqtt out","z":"422e1f4b.6e0b2","name":"","topic":"home/Rubbish/day","qos":"","retain":"","broker":"22618f74.c776d","x":637,"y":222,"wires":[]},{"id":"71295523.90e58c","type":"debug","z":"422e1f4b.6e0b2","name":"","active":true,"console":"false","complete":"false","x":695.9999694824219,"y":57.99999809265137,"wires":[]},{"id":"ac5dd61.707c128","type":"debug","z":"422e1f4b.6e0b2","name":"","active":false,"console":"false","complete":"false","x":248.78689575195312,"y":399.616455078125,"wires":[]},{"id":"8b3b22b9.a51ca","type":"debug","z":"422e1f4b.6e0b2","name":"","active":true,"console":"false","complete":"false","x":595.335205078125,"y":302.5284118652344,"wires":[]},{"id":"22618f74.c776d","type":"mqtt-broker","z":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"willTopic":"","willQos":"0","willPayload":"","birthTopic":"","birthQos":"0","birthPayload":""}]

copy the above code into node red

by clicking the 3 line top right then Import then clipboard

I just wing it

working on changing the icon to match what I (kids) have to take out

image

Installing Node-RED right now

as i said I just wing it Dont know what im doing but what i wanted

as i said I just wing it Dont know what im doing but what i wanted

in your config file

add

panel_iframe:
  nodered:
    title: 'Node-Red'
    icon: 'mdi:shuffle-variant'
    url: 'http://yourIPaddress:1880/'

Ufff, integration successful! I think I’m with love with you XD

Now I only have to understand how to use it with my URL, many many thanks

if i was you I would Copy the node red code and the create a New Tab (just so its tidy)

  1. timestamp is the bit that kick it off I set a timeer on it
  2. just set the Headers
  3. where you would put the http://192.168.1.100:8090/presets make shour that the return is a JSON Object
  4. put a debug on the end turn it on and DEPLOY
    hit the time stamp and you should see some thing in the debug window
    at this stag I was a HAPPY CAMPER
    A day later pulling my hair out
    work had to add a function

and put this in
var newMsg = { payload: msg.payload.PickupWeek };
return newMsg;
think your should say
var newMsg = { payload: msg.payload.ItemName };
return newMsg;

Then I put a New debug thing in and BUGGER I got something

and other day Later I work out add a MQTT Output Had conf to my Machine

went back into HA add a Sensor reading the MQTT message and Bugger it work

so by my maths have save about 3 days work LOL

Let me know how you get on

How do you “expose” the result on the HA interface?

(like this)

image

edit : Stupid 1 AM question LOL sensor:mqtt

  - platform: mqtt
    name: Rubbish Day
    state_topic: "home/Rubbish/day"
    
  - platform: mqtt
    name: Rubbish Colour
    state_topic: "home/Rubbish/Colour"

then add to a group

  Office:
    name: Office
    entities:
      - sensor.rubbish_day
      - sensor.rubbish_colour

I got something,

Invalid connection from (client @=127.0.0.1:43300) : [MQTT-3.1.2-1] Incorrect protocol name: "MQIsdp"

hehe

have you GOT MQTT setup ??

mqtt:
  broker: localhost

Isn’t it embedded in HA by typing mqtt: in the configuration.yaml ? Do I have to setup something else?

if no setup then you have do INSTALL that also

you need to point it some where

mine is localhost

mqtt:
  broker: localhost

read this

It’s what I was doing :smile: , now I’m waiting for it to restart

do have Skype

if you want we could Skype I hate Typeing LOL