Announcement

Collapse
No announcement yet.

Jon00 DataScraper/JSON Parser Script For Homeseer 3 and Homeseer 4

Collapse
This topic is closed.
X
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    I only got the example in Grab1 (Which works if I change Main to 1).
    If I run the event with Main = 1 it creates the pollen devices and updates its values.

    Code:
    [Grab1]
    Path=http://www.wunderground.com/DisplayPollen.asp?Zipcode=Boston
    TextFile=0
    Encoding=
    Username=
    Password=
    Options=
    UserAgent=
    Devicemode=0
    StripHTML=1
    
    Pattern1=(?s)<td class="levels">.*?<p>(.*?)</p>
    Pattern2=(?s)<td class="text-center even-four">.*?<strong>(.*?)</strong>
    Pattern3=(?s)<td class="text-center even-four">.*?<div>(.*?)</div>
    Pattern4=(?s)<td class="levels">.*?background-color: #(.*?);"></div>
    Pattern5=(?s)<h3><strong>Pollen Type:</strong>(.*?)</h3>
    
    DeviceName1=Pollen Index
    DeviceText1=[100] [200]<br>[0]
    DeviceValue1=[0]
    DeviceImage1=[300].png
    Speakbutton1=1
    TriggerString1=
    SearchMode1=1
    TriggerEvent1=
    
    DeviceName2=Pollen Index
    DeviceText2=[101] [201]<br>[1]
    DeviceValue2=[1]
    DeviceImage2=[301].png
    Speakbutton2=1
    TriggerString2=
    SearchMode2=1
    TriggerEvent2=
    
    DeviceName3=Pollen Index
    DeviceText3=[102] [202]<br>[2]
    DeviceValue3=[0]
    DeviceImage3=[302].png
    Speakbutton3=1
    TriggerString3=
    SearchMode3=1
    TriggerEvent3=
    
    DeviceName4=Pollen Index
    DeviceText4=[103] [203]<br>[3]
    DeviceValue4=[3]
    DeviceImage4=[303].png
    Speakbutton4=1
    TriggerString4=
    SearchMode4=1
    TriggerEvent4=
    
    DeviceName5=Pollen Type
    DeviceText5=[400] [Replace ".",""]
    DeviceValue5=
    DeviceImage5=pollen.png
    Speakbutton5=1
    TriggerString5=
    SearchMode5=1
    TriggerEvent5=
    
    [Grab2] 
    Path=http://10.0.0.5:8176/variables/smappeeforbruk.html 
    TextFile=0 
    Encoding= 
    Username= 
    Password= 
    Options= 
    UserAgent= 
    Devicemode=0 
    Pattern1=(?s)<strong>value : </strong>(.*?) W<br /> 
    Pattern2= 
    Pattern3= 
    Pattern4= 
    Pattern5= 
    DeviceName1=Power 
    DeviceText1=[0] W 
    DeviceValue1=[0] 
    DeviceImage1= 
    Speakbutton1=1

    Comment


      That looks fine. So you still getting an error when you change Main to 2?
      Jon

      Comment


        Yepp.

        If I change it to 1+2 it updates the pollen devices but same error for Grab2.

        The URL I try to access for the power value is available through REST so I can get the info in HTML, XML and JSON. I guess the html that I posted should be OK?

        If I access the URL from the homeseer server's browser I get this:
        name : smappeeforbruk
        displayInUI : True
        id : 1181145578
        isFalse : False
        readOnly : False
        value : 8803 W
        Edit Attributes

        So I can access it from the server without problems.

        Comment


          I tried downloading it and pointing to the local file (on the homeseer server) - same error.

          Code:
          Path=C:\Temp\smappeeforbruk.html
          TextFile=0 
          Encoding= 
          Username= 
          Password= 
          Options= 
          UserAgent= 
          Devicemode=0 
          Pattern1=(?s)<strong>value : </strong>(.*?) W<br /> 
          Pattern2= 
          Pattern3= 
          Pattern4= 
          Pattern5= 
          DeviceName1=Power 
          DeviceText1=[0] W 
          DeviceValue1=[0] 
          DeviceImage1= 
          Speakbutton1=1

          Comment


            Now it works, Jon!

            The copy/paste included spaces in the end of all the lines.

            Thanx for the help

            Comment


              Most odd.

              I'm wondering if you have a corrupt ini file. Please try the attached to replace yours (rename to .ini).
              Attached Files
              Jon

              Comment


                Originally posted by jon00 View Post
                Most odd.

                I'm wondering if you have a corrupt ini file. Please try the attached to replace yours (rename to .ini).
                Works like a charm after I found the "white spaces" in the ini-file

                Comment


                  Is it safe to just rename the virtual device's floor/category and room? Or will the script just create a new one with the original text each time its running?

                  Today this is
                  Category: Utility
                  Room: Jon00 DataScraper

                  Comment


                    As long as the device is not deleted, you can rename as you wish.
                    Jon

                    Comment


                      Ahh! Thanx

                      Comment


                        Hi! Just started playing with this, and got it working. I have this section in my ini-file:

                        Code:
                        [Grab2]
                        Path=http://www.vegvesen.no/trafikk/xml/search.rss?searchFocus.roadTypes=Ev&searchFocus.roadTypes=Rv&searchFocus.roadNumber=159
                        TextFile=1
                        Encoding=UTF-8
                        Username=
                        Password=
                        Options=
                        UserAgent=
                        Devicemode=2
                        StripHTML=1
                        
                        Pattern1=(?s)<title>Rv 159.*?<description>(.*?)</description>
                        Pattern2=
                        Pattern3=
                        Pattern4=
                        Pattern5=
                        
                        DeviceName1=TrafikkMldRv159
                        DeviceText1=Veimelding RV159 [0]
                        DeviceValue1=
                        DeviceImage1=
                        Speakbutton1=1
                        TriggerString1=
                        SearchMode1=1
                        TriggerEvent1=
                        This generates the following grab:

                        Code:
                        <?xml version="1.0" encoding="UTF-8"?>
                        <rss xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" 
                        		xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" 
                        		xmlns:dc="http://purl.org/dc/elements/1.1/" 
                        		xmlns:georss="http://www.georss.org/georss" 
                                xmlns:gml="http://www.opengis.net/gml"
                                version="2.0">
                        
                        <channel>
                            
                            <title>Vegrapport(Sortert etter veg)</title>
                            <link>http://www.vegvesen.no/trafikk/public/</link>
                            <description>Statens vegvesen ber om at veg- og trafikkinformasjon som formidles videre følges av en kildehenvisning til Statens vegvesen.</description>
                            <language>no</language>
                            <docs>http://www.vegvesen.no/vegmeldinger/</docs>
                            <generator>Vegmeldingstjenesten</generator>
                            <managingEditor>www-admin@vegvesen.no (www-admin)</managingEditor>
                            <webMaster>www-admin@vegvesen.no (www-admin)</webMaster>
                            <copyright>Statens vegvesen</copyright>
                            
                        
                            
                            
                        	    <item>
                        	      <title>Rv 159 Karihaugen - Lillestr&#xf8;m (Akershus/Oslo) 
                        	      </title>
                        	      <description>
                        			V&#xe6;r- og f&#xf8;reforhold:
                        	      	Bart og v&#xe5;tt.
                        	      	
                        	      	Gjelder fra: 03.01.2016 14:30
                        	      	
                                  </description>
                        	      
                                  <georss:where>
                        		      <gml:Point>
                        		         <gml:pos>59.939058 10.927615</gml:pos>
                        		      </gml:Point>
                        		      <gml:Point>
                                         <gml:pos>59.952894 11.077442</gml:pos>
                                      </gml:Point>
                                  </georss:where>
                        	      
                        	      <guid isPermaLink="false">#23603984</guid>
                        	    </item>
                        	
                            
                        </channel>
                        </rss>
                        ...and the following grabdata:

                        Code:
                        [Grab2Data]
                        0=V&#xe6;r- og f&#xf8;reforhold:
                        	      	Bart og v&#xe5;tt.
                        	      	
                        	      	Gjelder fra: 03.01.2016 14:30
                        (Note that the text looks a bit strange, that's because it's UTF-8 and has a few Norwegian charcters in it)

                        Unfortunately this includes a lot of tabulators in the text that the devicestring is populated with - and the LED-sign (BetaBrite) I want to use the string with doesn't like tabs at all. Any way I can strip out the tabs?

                        Comment


                          You could try the replace function i.e.

                          DeviceText1=Veimelding RV159 [0] [replace "<add a tab here>",""]
                          Jon

                          Comment


                            Originally posted by jon00 View Post
                            You could try the replace function i.e.

                            DeviceText1=Veimelding RV159 [0] [replace "<add a tab here>",""]
                            Yeah, sorry - forgot to say I already tried that.

                            Comment


                              Would you please post the grab2.txt file (as a file) and I'll take a look here.
                              Jon

                              Comment


                                Thanks, included here.
                                Attached Files

                                Comment

                                Working...
                                X