Ankündigung

Einklappen
Keine Ankündigung bisher.

Spritpreise per HTTP-Binding und JSON

Einklappen
X
 
  • Filter
  • Zeit
  • Anzeigen
Alles löschen
neue Beiträge

    #76
    Hallo zusammen,

    ich habe nun auch auf das neue script umgestellt (detail.php führte zu vielen abfragen)

    Folgenden Teil der Sortierung möchte ich gerne wie folgt erweitern:
    Den größten und kleinsten Wert seperat ablegen, mit Ausnahme der "0", das bedeutet entweder einen falschen wert, oder, die Station ist geschlossen.

    Vielen Dank für eure Mithilfe!

    Code:
        // Map nach Preisen sortieren und die Werte dann dem Anzeigearray zuweisen
        for (PriceEntry : E5PricesMap.entrySet.sortBy[value]) {
            if(PriceEntry.getValue()!=0){E5sortItems.get(i).postUpdate(String::format("%s - %.3f €", PriceEntry.getKey(), PriceEntry.getValue()))}
            if(PriceEntry.getValue()==0){E5sortItems.get(i).postUpdate("geschlossen")}
            i = i+1
        }
        lockE5.unlock()
        postUpdate(E5_LastUpdate, new DateTimeType())

    Kommentar


      #77
      @tatzemax im Beitrag 16 ist beschrieben wie man das neue Zertifikat einfügt. Ich nutze auch Ubuntu (allerdings die Server Version) und so hat es bei mir auch funktioniert.

      @Dom1n1c Hast du OH 1.8.x oder bist du schon auf die neue zweier Version umgestiegen?

      Viele Grüße
      Torsten

      Kommentar


        #78
        toto1975 ich nutze OH 1.8.3 / die neuste 1.8.x Version permanent.
        Unter 2.0 / Beta 2 lief die Spritpreise Rule auch.
        OH2 ist zwar installiert, allerdings nicht per Autostart hinterlegt, da einige Dinge nicht funktionieren... Noch nicht. Quasi meine Bastelumgebung / OH2

        Kommentar


          #79
          Dom1n1c hast du es in der 1.8.x so gemacht wie im Beitrag 56? Ich bekomme da immer eine Fehlermeldung
          Code:
          - Couldn't resolve reference to JvmIdentifiableElement 'Double'.
          - Couldn't resolve reference to JvmIdentifiableElement 'parseDouble'.
          habe auch alle möglichen Imports gemacht.... leider ohne Erfolg

          Kommentar


            #80
            Das sind meine Imports.. bisschen viele...

            Code:
            import     org.joda.time.*
            import    org.openhab.core.types.*
            import     org.openhab.core.library.types.*
            import    org.openhab.core.library.items.*
            import     org.openhab.core.items.*
            import     org.openhab.core.persistence.*
            import     org.openhab.model.script.actions.*
            import     org.eclipse.xtext.xbase.lib.*
            import     org.java.math.*
            import    java.util.concurrent.locks.*
            import    java.util.*
            und das ist der eigentliche teil der Rule:

            Code:
            rule "E5 Update"
            when
                Item Gas_Prices_E5 received update
            then
                var Lock lockE5 = new ReentrantLock()
                var Map <String, Double> E5PricesMap = new HashMap <String, Double>()    // Stationsnamen und Preise für den Kraftstoff
                var ArrayList <StringItem> E5sortItems =  new ArrayList <StringItem>()
                var i = 0
                lockE5.lock()        
                E5sortItems.add(0, Tankstelle1_E5_TXT)
                E5sortItems.add(1, Tankstelle2_E5_TXT)
                E5sortItems.add(2, Tankstelle3_E5_TXT)
                E5sortItems.add(3, Tankstelle4_E5_TXT)
                E5sortItems.add(4, Tankstelle5_E5_TXT)
                E5sortItems.add(5, Tankstelle6_E5_TXT)
            
                if(Tankstelle1Closed.state=="open"){E5PricesMap.put("Shell Nord",    (Tankstelle1_E5.state as DecimalType).doubleValue())}
                if(Tankstelle2Closed.state=="open"){E5PricesMap.put("Esso ",        (Tankstelle2_E5.state as DecimalType).doubleValue())}
                if(Tankstelle3Closed.state=="open"){E5PricesMap.put("Star ",        (Tankstelle3_E5.state as DecimalType).doubleValue())}
                if(Tankstelle4Closed.state=="open"){E5PricesMap.put("SB Tank",        (Tankstelle4_E5.state as DecimalType).doubleValue())}
                if(Tankstelle5Closed.state=="open"){E5PricesMap.put("Aral",            (Tankstelle5_E5.state as DecimalType).doubleValue())}
                if(Tankstelle6Closed.state=="open"){E5PricesMap.put("Shell West",    (Tankstelle6_E5.state as DecimalType).doubleValue())}
            
                if(Tankstelle1Closed.state=="closed")    {E5PricesMap.put("geschlossen1",    (0).doubleValue())}
                if(Tankstelle2Closed.state=="closed")    {E5PricesMap.put("geschlossen2",    (0).doubleValue())}
                if(Tankstelle3Closed.state=="closed")    {E5PricesMap.put("geschlossen3",    (0).doubleValue())}
                if(Tankstelle4Closed.state=="closed")    {E5PricesMap.put("geschlossen4",    (0).doubleValue())}
                if(Tankstelle5Closed.state=="closed")    {E5PricesMap.put("geschlossen5",    (0).doubleValue())}
                if(Tankstelle6Closed.state=="closed")    {E5PricesMap.put("geschlossen6",    (0).doubleValue())}
                
                // Map nach Preisen sortieren und die Werte dann dem Anzeigearray zuweisen
                for (PriceEntry : E5PricesMap.entrySet.sortBy[value]) {
                    if(PriceEntry.getValue()!=0){E5sortItems.get(i).postUpdate(String::format("%s - %.3f €", PriceEntry.getKey(), PriceEntry.getValue()))}
                    if(PriceEntry.getValue()==0){E5sortItems.get(i).postUpdate("geschlossen")}
                    i = i+1
                }
                lockE5.unlock()
                postUpdate(E5_LastUpdate, new DateTimeType())
            end
            items jeweils

            Code:
            Number         Tankstelle2_E5             "E5 Preis Tankstelle 2"                    (Gas_Prices_E5) {http="<[tankstellen:180000:JSONPATH($.prices.+++Tankstellen-ID+++.e5)]"}
            Sowie die sortierten String items für die Sitemap, Zeitpunkt des letzten Updates usw..

            Kommentar


              #81
              Hallo,
              ich nutze Tankerkönig um Spritpreise per OpenHAB2 (auf Raspi 2) zu loggen. Das funktionert auch sehr gut.
              Nun versuche ich meine Installation auf eine neue/größere SD-Karte zu bringen, da bekomme ich aber immer nur eine Fehlermeldung wenn ich die Abfrage (.detail oder prices) sende.
              Fehlermeldung:
              Code:
              17:17:50.070 [ERROR] [lipse.smarthome.io.net.http.HttpUtil] - Fatal transport error: java.util.concurrent.ExecutionException: java.lang.NullPointerException
              In solch einem Fall hat mir immer das einefügen des Zertifikats wie in Post #16 geholfen, das geht aber diesmal nicht????

              Sende ich die https-Abfragen im Browser bekomme ich das erwartete JSON-Script.
              Hat hier jemand eine Idee woran es noch hängen könte?

              Ich nutze eine Regel mit Cron-Job, siehe hier:

              Code:
              import org.openhab.core.library.types.*
              val String Tankstelle1_ID="ID1"
              val String Tankstelle2_ID="ID2"
              val String Tankstelle3_ID="ID3"
              val String API_Key="MeineID"
              var String Status
              var Number E10
              var Number E5
              var Number Diesel
              var String TankstellenMarke
              var String TankstellenStrasse
              var String TankstellenOrt
              
              rule "Benzinpreise"
              when
                  Time cron "50 2,7,12,17,22,27,32,37,42,47,52,57 * * * ?"
              then
                  var String URL= "https://creativecommons.tankerkoenig.de/json/prices.php?ids=" + Tankstelle1_ID + "\," +Tankstelle2_ID + "\," + Tankstelle3_ID + "&apikey=" + API_Key
                  logInfo ("Benzinpreise", "URL = {}", URL)
                  var String json = sendHttpGetRequest(URL)
                  //logInfo("Benzinpreise","JSON-String = {}", json)
                  if (json!=null)  {
                      var Boolean  OK = transform("JSONPATH", "$.ok", json)
                      //logInfo("Benzinpreise", "OK = {}", OK)
                      if (OK=true) {
                          Status = transform("JSONPATH", "$.prices." + Tankstelle1_ID + ".status", json)
                          //logInfo("Benzinpreise", "Status = {}", Status)
                          if (Status=="open") {
                              E10 = transform("JSONPATH",  "$.prices." + Tankstelle1_ID + ".e10", json)
                              E5  = transform("JSONPATH",  "$.prices." + Tankstelle1_ID + ".e5", json)
                              Diesel  = transform("JSONPATH",  "$.prices." + Tankstelle1_ID + ".diesel", json)
                              E10_1.postUpdate(E10.toString)
                              E5_1.postUpdate(E5.toString)
                              Diesel_1.postUpdate(Diesel.toString)
                              //logInfo("Benzinpreise", "E10 = {}", E10)
                              //logInfo("Benzinpreise", "E5 = {}", E5)
                              //logInfo("Benzinpreise", "Diesel = {}", Diesel)
                          }
                          else {
                              //logInfo("Benzinpreise", "Status = {}", Status)
                          }
                          Status = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".status", json)
                          //logInfo("Benzinpreise", "Status = {}", Status)
                          if (Status=="open") {
                              E10 = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".e10", json)
                              E5  = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".e5", json)
                              Diesel  = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".diesel", json)
                              E10_2.postUpdate(E10.toString)
                              E5_2.postUpdate(E5.toString)
                              Diesel_2.postUpdate(Diesel.toString)
                              //logInfo("Benzinpreise", "E10 = {}", E10)
                              //l6ogInfo("Benzinpreise", "E5 = {}", E5)
                              //logInfo("Benzinpreise", "Diesel = {}", Diesel)
                            }
                            else {
                              //logInfo("Benzinpreise", "Status = {}", Status)
                          }
                          Status = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".status", json)
                          //logInfo("Benzinpreise", "Status = {}", Status)
                          if(Status=="open") {
                              E10 = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".e10", json)
                              E5  = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".e5", json)
                              Diesel  = transform("JSONPATH",  "$.prices." + Tankstelle3_ID + ".diesel", json)
                              E10_3.postUpdate(E10.toString)
                              E5_3.postUpdate(E5.toString)
                              Diesel_3.postUpdate(Diesel.toString)
                              //logInfo("Benzinpreise", "E10 = {}", E10)
                              //logInfo("Benzinpreise", "E5 = {}", E5)
                              //logInfo("Benzinpreise", "Diesel = {}", Diesel)
                          }
                          else {
                              //logInfo("Benzinpreise", "Status = {}", Status)
                          }
                      }
                      else {
                          logInfo("Benzinpreise", "OK = {}", OK)
                          var String HttpError = transform("JSONPATH",  "$.message", json)
                          logInfo("Benzinpreise", "HttpError = {}", HttpError)
                      }
                  }    
                  else {
                      logInfo("Benzinpreise", "Empty Return from HTTPRequest")        
                  }
                  
              
              end
              
              rule "Tankstellendaten"
              
              when
                  Time cron "50 3 0 * * ?" or System started
              then
                  logInfo ("Tankstellendaten", "Start")
                  var String URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle1_ID + "&apikey=" + API_Key
                  //logInfo ("Tankstellendaten1", "URL = {}", URL)
                  var String json = sendHttpGetRequest(URL)
                  //logInfo("Tankstellendaten1","JSON-String = {}", json)
                  if (json!=null) {
                      var Boolean OK = transform("JSONPATH", "$.ok", json)
                      //logInfo("Tankstellendaten1", "OK = {}", OK)
                      if (OK=true) {
                          TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                          TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                          TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                          Name_1.postUpdate(TankstellenMarke + " " +TankstellenStrasse + " " + TankstellenOrt)
                      }
                      else {
                          var String HttpError = transform("JSONPATH",  "$.message", json)
                          logInfo("Tankstellendaten1", "HttpError = {}", HttpError)
                      }        
                  }
                  else {
                      logInfo("Tankstellendaten1", "Empty Return from HTTPRequest")
                  }    
                  URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle2_ID + "&apikey=" + API_Key
                  //logInfo ("Tankstellendaten2", "URL = {}", URL)
                  json = sendHttpGetRequest(URL)
                  //logInfo("Tankstellendaten2","JSON-String = {}", json)
                  if (json!=null) {
                      var Boolean OK = transform("JSONPATH", "$.ok", json)
                      //logInfo("Tankstellendaten2", "OK = {}", OK)
                      if (OK=true) {
                          TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                          TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                          TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                          Name_2.postUpdate(TankstellenMarke + " " +TankstellenStrasse + " " + TankstellenOrt)
                      }
                      else {
                          var String HttpError = transform("JSONPATH",  "$.message", json)
                          logInfo("Tankstellendaten2", "HttpError = {}", HttpError)
                      }    
                  }
                  else {
                      logInfo("Tankstellendaten2", "Empty Return from HTTPRequest")
                  }     
                  URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle3_ID + "&apikey=" + API_Key
                  //logInfo ("Tankstellendaten3", "URL = {}", URL)
                  json = sendHttpGetRequest(URL)
                  //logInfo("Tankstellendaten3","JSON-String = {}", json)
                  if (json!=null) {
                      var Boolean OK = transform("JSONPATH", "$.ok", json)
                      //logInfo("Tankstellendaten3", "OK = {}", OK)
                      if (OK=true) {
                          TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                          TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                          TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                          Name_3.postUpdate(TankstellenMarke + " " +TankstellenStrasse + " " + TankstellenOrt)
                      }
                      else {
                          var String HttpError = transform("JSONPATH",  "$.message", json)
                          logInfo("Tankstellendaten3", "HttpError = {}", HttpError)
                      }
                  }
                  else {
                      logInfo("Tankstellendaten3", "Empty Return from HTTPRequest")
                  }    
              end

              Kommentar


                #82
                Der oben beschriebene Fehler wurde von @KayKreuzer unter folgendem Link angenommen.

                Kommentar


                  #83
                  ..und schon ist dieser Fehler wieder behoben.
                  Geprüft mit der Nigthly-Build Version #462. Einziges "HickUp", ich hatte das Http-Binding noch geladen (ich war der irrigen Annahme es zu brauchen), mit dem Binding blieb der Fehler, ohne es läuft alles wie gehabt. Meine .RRD4J-Datenbank wird wieder gefüllt!
                  Zuletzt geändert von Gast; 30.08.2016, 20:20.

                  Kommentar


                    #84
                    Hallo in die Runde,

                    ich habe mal wieder eine Fehlermeldung beim Abruf der Daten die auf ein Problem mit dem SSL Zertifikat hindeuten
                    Code:
                    2016-12-26 00:00:51.457 [ERROR] [g.openhab.io.net.http.HttpUtil] - Fatal transport error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorExcept$
                    2016-12-26 00:00:51.458 [ERROR] [.o.b.http.internal.HttpBinding] - No response received from 'tankstellen'
                    Ich habe daraufhin das bestehende SSL Zertifikat erneuert (das alte gelöscht und ein neues installiert, wie hier auch beschrieben) allerdings ohne Erfolg. Hat einer eine Ahnung ob hier etwas umgestellt worden ist?

                    Der Aufruf der URL im Web Browser funktioniert ohne Probleme.

                    Viele Grüße
                    Torsten


                    Kommentar


                      #85
                      Hallo Torsten,

                      mit diesem Problem scheinst Du nicht allein zu sein. Ich habe die gleiche Fehlermeldung seit 4 Tagen. Die Erneuerung des SSL Zertifikats hat bei mit auch nichts gebracht.
                      Leider habe ich auch keine Lösung dazu.

                      Gruß
                      Dirk

                      Kommentar


                        #86
                        Ich bin auf eine Rule mit "sendHttpGetRequest" umgestiegen und es funktioniert problemlos.

                        Kommentar


                          #87
                          Hallo opus42,

                          hast du ein kleines Beispiel?

                          Gruß
                          Torsten

                          Kommentar


                            #88
                            Schau doch mal unter #81

                            ..und hier mit den aktuellen Einstellungen:

                            val String Tankstelle1_ID="ID1"
                            val String Tankstelle2_ID="ID2"
                            val String Tankstelle3_ID="ID3"
                            val String API_Key="MeineID"
                            var String Status
                            var Number E10
                            var Number E5
                            var Number Diesel
                            var String TankstellenMarke
                            var String TankstellenStrasse
                            var String TankstellenOrt

                            rule Benzinpreise
                            when
                            Time cron "50 7,17,27,37,47,57 * * * ?"
                            then
                            var String URL= "https://creativecommons.tankerkoenig.de/json/prices.php?ids=" + Tankstelle1_ID + "," +Tankstelle2_ID + "," + Tankstelle3_ID + "&apikey=" + API_Key
                            //logInfo ("Benzinpreise", "URL = {}", URL)
                            var String json = sendHttpGetRequest( URL)
                            var Number PreisGeschlossen=0
                            //logInfo("Benzinpreise","JSON-String = {}", json)
                            if (json!=null) {
                            var Boolean OK = transform("JSONPATH", "$.ok", json)
                            //logInfo("Benzinpreise", "OK = {}", OK)
                            if (OK=true) {
                            Status = transform("JSONPATH", "$.prices." + Tankstelle1_ID + ".status", json)
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            if (Status=="open") {
                            E10 = transform("JSONPATH", "$.prices." + Tankstelle1_ID + ".e10", json)
                            E5 = transform("JSONPATH", "$.prices." + Tankstelle1_ID + ".e5", json)
                            Diesel = transform("JSONPATH", "$.prices." + Tankstelle1_ID + ".diesel", json)
                            E10_1.postUpdate(E10.toString)
                            E5_1.postUpdate(E5.toString)
                            Diesel_1.postUpdate(Diesel.toString)
                            //logInfo("Benzinpreise", "E10 = {}", E10)
                            //logInfo("Benzinpreise", "E5 = {}", E5)
                            //logInfo("Benzinpreise", "Diesel = {}", Diesel)
                            }
                            else {
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            //E10_1.postUpdate(PreisGeschlossen.toString)
                            //E5_1.postUpdate(PreisGeschlossen.toString)
                            //Diesel_1.postUpdate(PreisGeschlossen.toString)
                            }
                            Status = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".status", json)
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            if (Status=="open") {
                            E10 = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".e10", json)
                            E5 = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".e5", json)
                            Diesel = transform("JSONPATH", "$.prices." + Tankstelle2_ID + ".diesel", json)
                            E10_2.postUpdate(E10.toString)
                            E5_2.postUpdate(E5.toString)
                            Diesel_2.postUpdate(Diesel.toString)
                            }
                            else {
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            //E10_2.postUpdate(PreisGeschlossen.toString)
                            //E5_2.postUpdate(PreisGeschlossen.toString)
                            //Diesel_2.postUpdate(PreisGeschlossen.toString)
                            }
                            Status = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".status", json)
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            if(Status=="open") {
                            E10 = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".e10", json)
                            E5 = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".e5", json)
                            Diesel = transform("JSONPATH", "$.prices." + Tankstelle3_ID + ".diesel", json)
                            E10_3.postUpdate(E10.toString)
                            E5_3.postUpdate(E5.toString)
                            Diesel_3.postUpdate(Diesel.toString)
                            }
                            else {
                            //logInfo("Benzinpreise", "Status = {}", Status)
                            //E10_3.postUpdate(PreisGeschlossen.toString)
                            //E5_3.postUpdate(PreisGeschlossen.toString)
                            //Diesel_3.postUpdate(PreisGeschlossen.toString)
                            }
                            }
                            else {
                            logInfo("Benzinpreise", "OK = {}", OK)
                            var String HttpError = transform("JSONPATH", "$.message", json)
                            logInfo("Benzinpreise", "HttpError = {}", HttpError)
                            }
                            }
                            else {
                            logInfo("Benzinpreise", "Empty Return from HTTPRequest")
                            }
                            end

                            rule "Tankstellendaten"

                            when
                            Time cron "50 3 0 * * ?"
                            then
                            logInfo ("Tankstellendaten", "Start")
                            var String URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle1_ID + "&apikey=" + API_Key
                            //logInfo ("Tankstellendaten1", "URL = {}", URL)
                            var String json = sendHttpGetRequest(URL)
                            //logInfo("Tankstellendaten1","JSON-String = {}", json)
                            if (json!=null) {
                            var Boolean OK = transform("JSONPATH", "$.ok", json)
                            //logInfo("Tankstellendaten1", "OK = {}", OK)
                            if (OK=true) {
                            TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                            TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                            TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                            //logInfo("Tankstellendaten1", "Tankstellenmarke = {}", TankstellenMarke)
                            Name_1.postUpdate(TankstellenMarke + " " + TankstellenOrt)
                            }
                            else {
                            var String HttpError = transform("JSONPATH", "$.message", json)
                            logInfo("Tankstellendaten1", "HttpError = {}", HttpError)
                            }
                            }
                            else {
                            logInfo("Tankstellendaten1", "Empty Return from HTTPRequest")
                            }
                            URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle2_ID + "&apikey=" + API_Key
                            //logInfo ("Tankstellendaten2", "URL = {}", URL)
                            json = sendHttpGetRequest(URL)
                            //logInfo("Tankstellendaten2","JSON-String = {}", json)
                            if (json!=null) {
                            var Boolean OK = transform("JSONPATH", "$.ok", json)
                            //logInfo("Tankstellendaten2", "OK = {}", OK)
                            if (OK=true) {
                            TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                            TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                            TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                            Name_2.postUpdate(TankstellenMarke + " " + TankstellenOrt)
                            }
                            else {
                            var String HttpError = transform("JSONPATH", "$.message", json)
                            logInfo("Tankstellendaten2", "HttpError = {}", HttpError)
                            }
                            }
                            else {
                            logInfo("Tankstellendaten2", "Empty Return from HTTPRequest")
                            }
                            URL= "https://creativecommons.tankerkoenig.de/json/detail.php?id=" + Tankstelle3_ID + "&apikey=" + API_Key
                            //logInfo ("Tankstellendaten3", "URL = {}", URL)
                            json = sendHttpGetRequest(URL)
                            //logInfo("Tankstellendaten3","JSON-String = {}", json)
                            if (json!=null) {
                            var Boolean OK = transform("JSONPATH", "$.ok", json)
                            //logInfo("Tankstellendaten3", "OK = {}", OK)
                            if (OK=true) {
                            TankstellenMarke = transform("JSONPATH", "$.station.brand", json)
                            TankstellenStrasse = transform("JSONPATH", "$.station.street", json)
                            TankstellenOrt = transform("JSONPATH", "$.station.place", json)
                            Name_3.postUpdate(TankstellenMarke + " " + TankstellenOrt)
                            }
                            else {
                            var String HttpError = transform("JSONPATH", "$.message", json)
                            logInfo("Tankstellendaten3", "HttpError = {}", HttpError)
                            }
                            }
                            else {
                            logInfo("Tankstellendaten3", "Empty Return from HTTPRequest")
                            }
                            end

                            Kommentar


                              #89
                              Moin Zusammen,

                              hier nochmal meine Rules für das Sprit Thema. Ich habe sechs Tankstellen, die ich nach Dieselpreisen abfrage. Die Preise werden sortiert und der günstigste wird direkt angezeigt. Weiterhin werden die Label der Items mit den Tankstellennamen dynamisch angepasst.

                              Sitemap:
                              Code:
                                      Text item=PriceFuelStation01 {
                              
                                          Text item=PriceFuelStation01 
                                          Text item=PriceFuelStation02 
                                          Text item=PriceFuelStation03 
                                          Text item=PriceFuelStation04 
                                          Text item=PriceFuelStation05 
                                          Text item=PriceFuelStation06 
                              
                                      }
                              Items:
                              Code:
                              //------------------------------------------------------------------------------------------------------------------------
                              //    Items to display fuel prices using www.Tankerkoenig.de
                              //------------------------------------------------------------------------------------------------------------------------
                              Group gFuelStations "Tankstellen"  <edit_settings> (gInternet)
                              String PriceFuelStation01 "Billigste Tankstelle [%s]" <scene_gas_station> (gFuelStations) 
                              String PriceFuelStation02 "2. Tankstelle [%s]" <scene_gas_station> (gFuelStations)
                              String PriceFuelStation03 "3. Tankstelle [%s]" <scene_gas_station> (gFuelStations)
                              String PriceFuelStation04 "4. Tankstelle [%s]" <scene_gas_station> (gFuelStations)
                              String PriceFuelStation05 "5. Tankstelle [%s]" <scene_gas_station> (gFuelStations)
                              String PriceFuelStation06 "6. Tankstelle [%s]" <scene_gas_station> (gFuelStations)
                              Rules:
                              Code:
                              import java.util.ArrayList
                              import java.util.Map
                              import java.util.HashMap
                              
                              //------------------------------------------------------------------------------------------------------------------------
                              //
                              //    Rule: Update Fuel Prices
                              //
                              //------------------------------------------------------------------------------------------------------------------------
                              rule "Update Fuel Prices"
                              when
                              
                                  Time cron "0 0/15 * * * ?" or // Every 15 min.
                                  System started
                              
                              then
                              
                                  val String IdStation01 = "3d8c2dfb-4612-4aff-8ae7-96e3f88eafe6" //Nordoel Uetersen
                                  val String IdStation02 = "1ceea95b-d46e-4159-91f6-71f57d612bdb"    // Nordoel Elmshorn
                                  val String IdStation03 = "e1a15081-24e2-9107-e040-0b0a3dfe563c"    // HEM Elmshorn
                                  val String IdStation04 = "005056ba-7cb6-1ed2-bceb-bc577a5e6d4e"    // Star Elmshorn
                                  val String IdStation05 = "e1a15081-254f-9107-e040-0b0a3dfe563c"    // HEM Wedel
                                  val String IdStation06 = "65c348cf-5ce7-4820-a24a-da0dbf816204"    // SB Wedel
                                  val String ApiKey = "xxxxxxxxxxxxxxxxxxxxx"
                              
                                  var String json
                                  var Integer i
                              
                                  var Map <String, String> StationNames = new HashMap<String, String>() //Map station id to names
                                  var Map <String, Double> StationPrices = new HashMap<String, Double>() // Map station id to price
                              
                                  var ArrayList<StringItem> openHABItems =  new ArrayList<StringItem>()
                              
                              
                                  // Build URL and get prices as json
                                  json = sendHttpGetRequest("https://creativecommons.tankerkoenig.de/json/prices.php?ids=" + IdStation01 + "," + IdStation02 + "," + IdStation03  + "," + IdStation04  + "," + IdStation05 + "," + IdStation06 + "&apikey=" + ApiKey)
                              
                                  // Check result and work on it
                                  if (transform("JSONPATH",  "$.ok", json) == "true") {
                              
                                      // Build map of station names
                                      StationNames.put(IdStation01, "Nordoel (Uetersen)")
                                      StationNames.put(IdStation02, "Nordoel (Elmshorn)")
                                      StationNames.put(IdStation03, "HEM (Elmshorn)")
                                      StationNames.put(IdStation04, "Star (Elmshorn)")
                                      StationNames.put(IdStation05, "HEM (Wedel)")
                                      StationNames.put(IdStation06, "SB (Wedel)")
                              
                                      // Build map of prices. if station is closes price equals MAx_Value
                                      for (MapEntry : StationNames.entrySet) {
                              
                                          if (transform("JSONPATH",  "$.prices." + MapEntry.getKey() + ".status", json) != "closed") {
                              
                                              StationPrices.put(MapEntry.getKey(), Double.parseDouble(transform("JSONPATH",  "$.prices." + MapEntry.getKey() + ".diesel", json)))
                              
                                          } else { 
                              
                                              StationPrices.put(MapEntry.getKey(), Double.MAX_VALUE)
                              
                                          }
                              
                                      }
                              
                                      // Sort prices and display
                                      openHABItems.add(0, PriceFuelStation01)
                                      openHABItems.add(1, PriceFuelStation02)
                                      openHABItems.add(2, PriceFuelStation03)
                                      openHABItems.add(3, PriceFuelStation04)
                                      openHABItems.add(4, PriceFuelStation05)
                                      openHABItems.add(5, PriceFuelStation06)
                              
                                      i = 0
                                      for (MapEntry : StationPrices.entrySet.sortBy[value]) {
                              
                                          // Set the item label to station name
                                          openHABItems.get(i).label = StationNames.get(MapEntry.getKey())
                              
                                          // Set price
                                          if (MapEntry.getValue() != Double.MAX_VALUE) {
                              
                                              openHABItems.get(i).postUpdate(String::format("%.3f €", MapEntry.getValue()))
                              
                                          } else {
                              
                                              openHABItems.get(i).postUpdate("geschlossen")
                              
                                          }
                                          i++
                              
                                      }
                              
                                      logInfo("rule.internet.UpdateFuelPrices", "Fuel prices are updated")
                              
                                  } else
                                  {
                              
                                      logInfo("rule.internet.UpdateFuelPrices", "Error accessing www.tankerkoenig.de -> next try in 15 min.")
                              
                                  }
                              
                              end
                              So das ist es. Bei Fragen einfach fragen.

                              Thomas

                              Kommentar


                                #90
                                Hallo,

                                leider funktioniert bei mir auch das Beispiel von dibbler42 nicht.

                                2017-01-11 17:45:00.176 [ERROR] [g.openhab.io.net.http.HttpUtil] - Fatal transport error: javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderE xception: unable to find valid certification path to requested target
                                2017-01-11 17:45:00.182 [ERROR] [o.o.c.t.actions.Transformation] - Error executing the transformation 'JSONPATH': the given parameters 'JSonPath' and 'source' must not be null
                                2017-01-11 17:45:00.186 [INFO ] [.s.r.internet.UpdateFuelPrices] - Error accessing www.tankerkoenig.de -> next try in 15 min.

                                Die Erneuerung des SSL Zertifikats hat bei mir auch nichts gebracht.

                                Hat noch jemand eine Idee woran es noch liegen könnte?

                                P.S. Ich habe die Vermutung das es am http-binding liegen könnte, aber eine Neuinstallation vom binding hat auch nicht geholfen.

                                mfg

                                Andre
                                Zuletzt geändert von Haupty; 11.01.2017, 21:04.

                                Kommentar

                                Lädt...
                                X