XML or RSS feed loading into text item and display in OH (e.g Traffic)

Hi,

i am looking for a solution to load data from an RSS feed into a text item.

Is this something that someone had implemented already?

thx
Karsten

i am a bit further down the road so far - tried to create an XSLT for reading the following UR:
http://www.deutschlandradio.de/verkehrsmeldungen.438.de.rss

XSLT:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
        
        <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />

        <xsl:template match="/">
						    <xsl:for-each select="rss/channel/item/titel">
				    			<xsl:if test="A81 Stuttgart Richtung Singen">
						      <xsl:value-of select="description"/>
						    </xsl:if>
						    </xsl:for-each>
        </xsl:template>

</xsl:stylesheet>

Item declaration:
String VerkehrA81 “Verkehr A81” { http="<[travel:50000:XSLT(verkehr.xsl)]" }

but ending up in error messages in OH:

2015-10-06 12:42:59.889 [ERROR] [.i.s.XsltTransformationService] - transformation throws exception
javax.xml.transform.TransformerConfigurationException: file:/opt/openhab/configurations/transform/verkehr.xsl: line 8: Erforderliches Attribut "test" fehlt.
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:994) ~[na:1.8.0]
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:766) ~[na:1.8.0]
        at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:82) ~[na:na]
        at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:179) [bundlefile:na]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.7.0.jar:na]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.7.0.jar:na]
2015-10-06 12:42:59.901 [ERROR] [.o.b.http.internal.HttpBinding] - transformation throws exception [transformation=XSLT(verkehr.xsl), response=<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title xmlns:func="http://exslt.org/functions">Deutschlandradio - Verkehrsmeldungen</title>
    <link xmlns:func="http://exslt.org/functions">http://www.deutschlandradio.de/</link>
    <description xmlns:func="http://exslt.org/functions">Aktuelle Verkehrsmeldungen</description>
    <category xmlns:func="http://exslt.org/functions">Info</category>
    <language>de-DE</language>
    <copyright>Deutschlandradio - dradio.de</copyright>
    <pubDate>Tue, 06 Oct 2015 12:42:59 +0200</pubDate>
    <lastBuildDate>Tue, 06 Oct 2015 12:42:59 +0200</lastBuildDate>
    <image>
      <url>http://www.deutschlandradio.de/themes/dradio/img/dradio-de-logo-neutral.gif</url>
      <title>Deutschlandradio Logo</title>
      <link>http://www.deutschlandradio.de/</link>
      <description>Feed provided by Deutschlandradio. Click to visit.</description>
    </image>
    <item xmlns:func="http://exslt.org/functions">
      <title>A8 Karlsruhe Richtung Stuttgart</title>
      <description>A8 Karlsruhe Richtung Stuttgart zwischen Dreieck Karlsruhe und Karlsbad Wanderbaustelle, die linke Spur ist gesperrt.</description>
    </item>
    <item xmlns:func="http://exslt.org/functions">
      <title>A8 Karlsruhe Richtung Stuttgart</title>
      <description>A8 Karlsruhe Richtung Stuttgart zwischen Karlsbad und Pforzheim-West Wanderbaustelle, die linke Spur ist gesperrt.</description>
    </item>
    <item xmlns:func="http://exslt.org/functions">
      <title>A81 Stuttgart Richtung Singen</title>
      <description>A8 Stuttgart Richtung Karlsruhe zwischen Heimsheim und Pforzheim-Nord 10 km stockender Verkehr.</description>
    </item>
    <item xmlns:func="http://exslt.org/functions">
      <title>A8 Stuttgart Richtung Karlsruhe</title>
      <description>A8 Stuttgart Richtung Karlsruhe zwischen Pforzheim-West und Karlsbad Wanderbaustelle, die linke Spur ist gesperrt.</description>
    </item>
  </channel>
</rss>
]
org.openhab.core.transform.TransformationException: transformation throws exception
        at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:86) ~[na:na]
        at org.openhab.binding.http.internal.HttpBinding.execute(HttpBinding.java:179) ~[na:na]
        at org.openhab.core.binding.AbstractActiveBinding$BindingActiveService.execute(AbstractActiveBinding.java:156) [org.openhab.core_1.7.0.jar:na]
        at org.openhab.core.service.AbstractActiveService$RefreshThread.run(AbstractActiveService.java:173) [org.openhab.core_1.7.0.jar:na]
Caused by: javax.xml.transform.TransformerConfigurationException: file:/opt/openhab/configurations/transform/verkehr.xsl: line 8: Erforderliches Attribut "test" fehlt.
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:994) ~[na:1.8.0]
        at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:766) ~[na:1.8.0]
        at org.openhab.core.transform.internal.service.XsltTransformationService.transform(XsltTransformationService.java:82) ~[na:na]
        ... 3 common frames omitted

any idea/ assistance?

thx

There may be other issues but in the feed URI:
titel -> title

There is an openHAB 2 binding that already support RSS. If you are still interested, take a look at this https://github.com/openhab/openhab2-addons/issues/724.

try

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
        <xsl:output indent="no" method="text" encoding="UTF-8" standalone="yes" omit-xml-declaration="yes"/>
	<xsl:template match="/">        
		<xsl:if test="/rss/channel/item[contains(title,'A81 Stuttgart Richtung Singen')]">
			<xsl:value-of select="(//rss/channel/item/description)"/>
		</xsl:if>
	</xsl:template>
</xsl:stylesheet>

One more issue on a HTTP binding on RSS feed.
The Value(Ill moyenne - Lauch : Vert) does not appear on sitemap log info is OK !

What’s wrong ?

2016-10-21 10:06:26.342 [INFO ] [runtime.busevents             ] - Vigicrue state updated to Ill moyenne - Lauch : Vert

Here my item and sitemap

String Vigicrue "Vigicrue" { http="<[http://www.vigicrues.gouv.fr/rss/?CdEntVigiCru=SA5:5000:XSLT(vigicrue.xsl)]" }
Text item=Vigicrue

and here the vigicrue.xsl file

<?xml version="1.0"?>
<xsl:stylesheet 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
    
    
    <xsl:output indent="no" method="text" encoding="UTF-8" standalone="yes" omit-xml-declaration="yes"/>
    
    <xsl:template match="/">
        <xsl:value-of select="(//rss/channel/item/title)"/>
    </xsl:template>
    
</xsl:stylesheet>

and finaly the RSS file

<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Vigicrues : Tronçon(s) de cours d'eau en vigilance crues</title>
        <link>http://www.vigicrues.gouv.fr</link>
        <atom:link href="http://www.vigicrues.gouv.fr/rss/index.php" rel="self" type="application/rss+xml" />
        <description>MEEM/DGPR/SRNH/SCHAPI-SPC : Carte de vigilance crues</description>
        <docs>http://www.vigicrues.gouv.fr/faq.php?rub=19#q_51</docs>
        <category>vigilance crues</category>
        <language>fr-fr</language>
        <image>
            <title>Vigicrues : Tronçon(s) de cours d'eau en vigilance crues</title>
            <link>http://www.vigicrues.gouv.fr</link>
            <url>http://www.vigicrues.gouv.fr/ftp/cruemax.png</url>
        </image>
        <pubDate>Thu, 20 Oct 2016 15:50:00 +0200</pubDate>
        <lastBuildDate>Thu, 20 Oct 2016 15:50:00 +0200</lastBuildDate>
        <ttl>15</ttl>
        <item>
            <title>Ill moyenne - Lauch : Vert</title>
            <link>http://www.vigicrues.gouv.fr/niveau2.php?CdEntVigiCru=3#bul_spc</link>
            <description>
            &lt;p&gt;Actualisation du site Vigicrues le &lt;i&gt;&lt;b&gt;jeudi 20 octobre 2016 à 15h50&lt;/b&gt;.&lt;/i&gt;&lt;/p&gt;
            &lt;p&gt;Nom du tronçon : &lt;b&gt;Ill moyenne - Lauch&lt;/b&gt; (SA5)
            &lt;br /&gt;Couleur de vigilance crues du tronçon : &lt;b&gt;Vert&lt;/b&gt;
            &lt;br/&gt;Nom du SPC : Rhin-Sarre&lt;/p&gt;
            &lt;p&gt;Tenez vous régulièrement informé de la situation.
            &lt;br /&gt;Abonnez vous à ce flux ou consultez le site &lt;a href=&quot;http://www.vigicrues.gouv.fr&quot; target=&quot;_blank&quot;&gt;Vigicrues&lt;/a&gt;.
            &lt;br /&gt;Pour plus d&apos;informations sur le fil RSS, cliquez &lt;a href=&quot;http://www.vigicrues.gouv.fr/rss.php&quot; target=&quot;_blank&quot;&gt;ici&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;
            </description>
            <comments>http://www.vigicrues.gouv.fr/niveau2.php?CdEntVigiCru=3#SA5</comments>
            <pubDate>Thu, 20 Oct 2016 15:50:00 +0200</pubDate>
            <guid>http://www.vigicrues.gouv.fr/niveau2.php?CdEntVigiCru=3#SA5</guid>
        </item>
    </channel>
</rss>

what line are you trying to get back?

Im trying to catch the content in rss/channel/item/title in the RSS file ->

Ill moyenne - Lauch : Vert

I suspect wrong output parameters in the vigicrue.xsl file ??

I’ve taken another look in the code. The http binding work well on Vigicrue item
(see --> 2016-10-21 10:06:26.342 [INFO ] [runtime.busevents ] - Vigicrue state updated to Ill moyenne - Lauch : Vert).

Sorry for this question but is there a good reason why the sitemap (Text item=Vigicrue) doesn’t display the String ?

you might just need to add the [%s] to the item description

String Vigicrue "Vigicrue [%s]" { http="<[http://www.vigicrues.gouv.fr/rss/?CdEntVigiCru=SA5:5000:XSLT(vigicrue.xsl)]" }

OK 'works fine !

Sorry for this question…