[INFO] Import data from web

Hello,
i don’t know if this is the right section;
I’m currently using wview as weather station (and it reports data to an italian association (meteonetwork.it) and to wunderground).
Currently my weather station report also internal temperature (and humidity).
www.ssai.it/meteo/interna.htm
www.ssai.it/meteo/

There is a way to import this data on openhab?
thanks in advance!

Hi,

There is a weather binding that supports data from weather underground. Weather binding

It works quite well with both OpenHAB1 and 2.

Hello,
thanks for your reply.
I’m already using this weather binding (take data from weather station with wview, send to wunderground and taken with weather binding).
Problem is that i can’t export internal temperature to wunderground!
Thanks!

Ah, I misunderstood. I too, use wview my weather page

I don’t send my internal readings anywhere other than my website though. I don’t know that WU has the ability to receive them either, as their schema seems pre-defined. If they do accept it though, it would probably be easier to alter wview to send the data directly instead of wview to OH to WU. An example of how to post data to WU can be found here: wunderfixer . The third thing that comes to mind, if you want to get data directly into OH is a binding for your weather station directly. Not sure which station you have, but if you have a Davis, there is a binding: davis-binding

Thanks for your help.
Unfortunately i don’t have a davis so i can’t use that binding :frowning:
In wview i can’t modify data sent to WU; i had thought to change a parameter that i didn’t use but it’s impossibile.
Only thing that i can do is export data in a txt file with only interna temperature and himidity.
But then i don’t know how to import on OH!
thanks in advance!

ps: i’d like to buy a vantage because in future opensprinkler can use UV and solar radiation to calcolate evapotranspiration, but now i can’t :smile:

Ok, there is a http binding.

But don’t understand how it works…
Number man_temperature “Temperatura[%.1f °C]” { http="<[10.1.1.229/weather/interna.htm:60000:XSLT(interna.xsl)]" }

obviously XSLT(interna.xsl) isn’t correct, but don’t understand how take information from html page:
this is the code:

#table>
#tr>
#td class=“metric_name”>Temperatura mansarda:
#td class=“metric_value”>24.9 C
#/tr>
#tr>
#td class=“metric_name”>Umidita’ mansarda:
#td class=“metric_value”>52 %
#/tr>
#/table>
-> edited < with #
Thanks in advance

In the http binding, you can use a regular expression to parse data. I don’t have an example available right now, but I’ll reply again when I can with an example. You can also search the documentation for either regex or regular expression on the http binding section.

1 Like

Hello,
i’m sorry; i’m trying to study but really don’t understand how to do.
Do u have any suggestions?
Thanks a lot

The way I have done this in the past is create two String Items, one for each value that I need to retrieve (note that this means that OpenHab makes 2 calls instead of just one, but I’m not sure of a better way right now.)

However, working on pulling the data from the URL you provided is proving tricky, because the label and value are on different lines from each other. I can’t seem to get the OpenHab regex engine to handle this situation. I’ll keep digging and let you know.

Hello,
in the end i understood how to fix it!
If someone need help write here :slight_smile:

  1. create an xml documento with data
  2. create and XLST document to capture this data (help with this tool: http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog)
  3. create item to use it!

Thanks to all!

Hi i’m very beginner
i try to read a led status from remote relay shield on my internal lan.
on browser when i put http://192.168.1.201/status.xml
i receive

> <response>
> <led0>0</led0>
> <led1>0</led1>
> <led2>0</led2>
> <led3>1</led3>
> <led4>0</led4>
> <led5>0</led5>
> <led6>0</led6>
> <led7>0</led7>
> <btn0>up</btn0>
> <btn1>up</btn1>
> <btn2>up</btn2>
> <btn3>up</btn3>
> <btn4>up</btn4>
> <btn5>up</btn5>
> <btn6>up</btn6>
> <btn7>up</btn7>
> </response>

so in OH
this is my items file

String Stato_Led3 "Prova lettura xml [%s] "{ http="<[192.168.1.201/status.xml:6000:XSLT(test.xsl)]" }

this is the file in transform

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
  <xsl:template match="/">
     <xsl:apply-templates select="response/led3"/>
   </xsl:template>
   <xsl:template match="*">
     <xsl:choose>
        <xsl:when test="self::node()[node()=1]">ON</xsl:when>
        <xsl:when test="self::node()[node()=0]">FALSE</xsl:when>
        <xsl:when test="self::node()[node()='up']">UP</xsl:when>
        <xsl:when test="self::node()[node()='dn']">DOWN</xsl:when>
     </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

this is sitemap

sitemap default label="ANT"
{
Frame label="Prova lettura Stato Led " {
        //Number item=SimpleLight
        Text item=Stato_Led3

    }
}
~ 

but nothing happen
can you help me ?

~
~

The following should update state every six seconds. It has the advantage of only pulling the XML every six seconds, but updating multiple items. You will need a different .xsl file for each item.

If you want to have buttons in openHAB change the state on the relay shield, you would have to add the appropriate “>[url:…]” bindings to the button switch items (assuming you can command your relay shield via HTTP).

transform/led3.xsl:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output indent="yes" method="xml" encoding="UTF-8" omit-xml-declaration="yes" />
  <xsl:template match="/">
     <xsl:apply-templates select="response/led3"/>
   </xsl:template>
   <xsl:template match="*">
     <xsl:choose>
        <xsl:when test="self::node()[node()=1]">ON</xsl:when>
        <xsl:when test="self::node()[node()=0]">OFF</xsl:when>
        <xsl:when test="self::node()[node()='up']">OFF</xsl:when>
        <xsl:when test="self::node()[node()='dn']">ON</xsl:when>
     </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

Your openhab.cfg could contain:

http:relayShield.url=http://192.168.1.201/status.xml
http:relayShield.updateInterval=6000

Your items could look like:

//...
Switch Stato_Led2 "Led2" { http="<[relayShield:6000:XSLT(led2.xsl)]" }
Switch Stato_Led3 "Led3" { http="<[relayShield:6000:XSLT(led3.xsl)]" }
//...
Switch Button_Btn3 "Btn3" { http="<[relayShield:6000:XSLT(btn3.xsl)]" }
//...

sitemap:

sitemap default label="ANT"
{
Frame label="Prova lettura Stato Led " {
        Text item=Stato_Led2
        Text item=Stato_Led3
        Switch item=Button_Btn3
    }
}

assuming return from http://192.168.1.201/status.xml is like:

<response>
<led0>0</led0>
<led1>0</led1>
<led2>0</led2>
<led3>1</led3>
<led4>0</led4>
<led5>0</led5>
<led6>0</led6>
<led7>0</led7>
<btn0>up</btn0>
<btn1>up</btn1>
<btn2>up</btn2>
<btn3>up</btn3>
<btn4>up</btn4>
<btn5>up</btn5>
<btn6>up</btn6>
<btn7>up</btn7>
</response>

Great!!
Now i can see the status of Stato_Led3
the only change done is in sitemap

sitemap default label="ANT"
{
Frame label="Prova lettura Stato Led " {
        Text item=Stato_Led2
//        Text item=Stato_Led3
        Switch item=Stato_Led3
        Switch item=Button_Btn3
    }
}