Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. json aus Tankerkönig Adapter parsen

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    json aus Tankerkönig Adapter parsen

    This topic has been deleted. Only users with topic management privileges can see it.
    • F
      fastfoot @Homoran last edited by

      @Homoran sagte in json aus Tankerkönig Adapter parsen:

      Warum benötigst du den Adapter, wenn du die json selber parsen willst?

      Anders gefragt: Warum bietet der Adapter die json an, wenn sie doch 'unnötig' ist 🙂

      Homoran 1 Reply Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators @fastfoot last edited by

        @fastfoot sagte in json aus Tankerkönig Adapter parsen:

        Warum bietet der Adapter die json an

        weil er sie auch braucht zum auswerten 😉

        Wenn deine Wünsch nicht mit dem Adapter gehen, wäre das doch ggf. ein feature request das in den Adapter einzubauen.

        @sveni_lee sagte in json aus Tankerkönig Adapter parsen:

        das es in das Materialdesign Table widget passt.

        also fehlt da ein bestimmtes format der Ausgabe????

        F S 2 Replies Last reply Reply Quote 0
        • F
          fastfoot @Homoran last edited by

          @Homoran sagte in json aus Tankerkönig Adapter parsen:

          weil er sie auch braucht zum auswerten

          Das wäre ja noch kein Grund, sie nach aussen weiterzugeben, tut der Covid19 Adapter ja auch nicht

          Wenn deine Wünsch nicht mit dem Adapter gehen, wäre das doch ggf. ein feature request das in den Adapter einzubauen.

          mir reicht das json, um meine Wünsche alleine umzusetzen 🙂 Der Adapter dient in meinem Fall tatsächlich nur dazu, eine bequeme Konfiguration zu haben. Da ich jetzt so langsam mit VIS anfange, steht als nächstes eine json Tabelle an, die leicht in die VIS eingebunden werden kann

          1 Reply Last reply Reply Quote 0
          • S
            sveni_lee @Homoran last edited by

            @Homoran sagte in json aus Tankerkönig Adapter parsen:

            @sveni_lee sagte in json aus Tankerkönig Adapter parsen:

            das es in das Materialdesign Table widget passt.

            also fehlt da ein bestimmtes format der Ausgabe????

            ja... lt. GitHub muß e ein Json array aus Objecten sein.

            [
            	{
            		"img": "/vis.0/myImages/erlebnis_50.png",
            		"name": "Empire",
            		"betriebszeit": "4h 06m",
            		"funk": "5G",
            		"ip": "10.0.0.1"
            	},
            	{
            		"img": "/vis.0/myImages/erlebnis_100.png",
            		"name": "Handy",
            		"betriebszeit": "13m",
            		"funk": "5G",
            		"ip": "10.0.0.2"
            	},
            	{
            		"img": "/vis.0/myImages/erlebnis_100.png",
            		"name": "Harmony Hub - Wohnzimmer",
            		"betriebszeit": "18T 07h 21m",
            		"funk": "2G",
            		"ip": "10.0.0.3"
            	}
            ]
            

            da ich aber nicht weiß ob dies für die Allgemeinheit von interesse ist versuche ich es über ein script zu lösen. Ich versuche es zu vermeiden Adapter durch meine speziellen wünsche "aufzublasen".

            bisher ist mein versuch aber och nicht von erfolg gekröhnt... 🙂

            var station_png = {"005056ba-7cb6-1ed5-8cbd-4897fe54e42b" : "/vis.0/Star.png",
                                "aa1c6fb6-439a-4915-8ad8-0f67697a65e2" : "/vis.0/ESSO.png",
                                "5a5ed93f-84aa-4517-dc7c-c888f278b5c7" : "/vis.0/Test/img/Tanken/Gulf-Tankstelle.png",
                                "6649f1c1-5154-4641-945c-96419ea88f01" : "/vis.0/Test/img/Tanken/total.png",
                                "533abf42-a618-4d18-802e-fabdf0429269" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                "528da962-bd28-4f5d-8bd0-cc01ba9b538c" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                "51d4b47c-a095-1aa0-e100-80009459e03a" : "/vis.0/Jet.png"
                                };
            
            var materialDesignWidgets = {};
            on({id:'tankerkoenig.0.json'}, function (obj) {    
            
                let json_tank = getState('0_userdata.0.materialdesignwidgets.tankerkoeningTabelle').val;
             
                if (json_tank) {
                    try {
            
                        json_tank = JSON.parse(json_tank);
            
                    } catch (e) {
                        json_tank = [];
                        console.warn('Wert ist kein JSON string! Wert wird ersetzt!');
                    }
                } else {
                    json_tank = [];
                }
            
            let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray;
            
            let json = JSON.parse(getState('tankerkoenig.0.json').val);
            
            let stations = Object.keys(json.prices);
            
            stations.forEach((station,i) => {
            
                myStations.forEach((arr, j) => {
            
                    if(arr[0] == station) {
              
                        log(arr[1] + ': ' + json.prices[station].diesel + " - " + json.prices[station].status);
            
                        materialDesignWidgets.sendTo = function (img ='', name = '', preis = '', status ='' ) {
                        
                            json_tank.push(
                            {
                                "img": station_png[station],
                                "name": arr[1],
                                "preis": json.prices[station].diesel,
                                "status": json.prices[station].status
                            })
                    
                        setState('0_userdata.0.materialdesignwidgets.tankerkoeningTabelle', JSON.stringify(json_tank), true);
            
                    }}
                });
                
            })
            })
            
            1 Reply Last reply Reply Quote 0
            • S
              sveni_lee last edited by

              so, ich hab's hnbekommen.
              das skript schreibt jetzt ein JSON Array aus Objekten in einen Datenpunkt.
              und den kann man dann im Materialdesignwidget Table verwenden.

              var station_png = {"005056ba-7cb6-1ed5-8cbd-4897fe54e42b" : "/vis.0/Star.png",
                                  "aa1c6fb6-439a-4915-8ad8-0f67697a65e2" : "/vis.0/ESSO.png",
                                  "5a5ed93f-84aa-4517-dc7c-c888f278b5c7" : "/vis.0/Test/img/Tanken/Gulf-Tankstelle.png",
                                  "6649f1c1-5154-4641-945c-96419ea88f01" : "/vis.0/Test/img/Tanken/total.png",
                                  "533abf42-a618-4d18-802e-fabdf0429269" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                  "528da962-bd28-4f5d-8bd0-cc01ba9b538c" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                  "51d4b47c-a095-1aa0-e100-80009459e03a" : "/vis.0/Jet.png"
                                  };
              
              
              on({id:'tankerkoenig.0.json'}, function (obj) {    
              
                  let json_tank = '';
                  json_tank = [];
              
              let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray;
              
              let json = JSON.parse(getState('tankerkoenig.0.json').val);
              
              let stations = Object.keys(json.prices);
              
              stations.forEach((station,i) => {
              
                  myStations.forEach((arr, j) => {
              
                      if(arr[0] == station) {
                          
                              json_tank.push(
                              {
                                  "img": station_png[station],
                                  "name": arr[1],
                                  "preis": json.prices[station].diesel,
                                  "status": json.prices[station].status
                              })
              
                          setState('0_userdata.0.materialdesignwidgets.tankerkoeningTabelle', JSON.stringify(json_tank), true);
              
                      }
                  });
                  
              })
              })
              
              F 1 Reply Last reply Reply Quote 0
              • F
                fastfoot @sveni_lee last edited by

                @sveni_lee sagte in json aus Tankerkönig Adapter parsen:

                so, ich hab's hnbekommen.
                das skript schreibt jetzt ein JSON Array aus Objekten in einen Datenpunkt.
                und den kann man dann im Materialdesignwidget Table verwenden.

                var station_png = {"005056ba-7cb6-1ed5-8cbd-4897fe54e42b" : "/vis.0/Star.png",
                                    "aa1c6fb6-439a-4915-8ad8-0f67697a65e2" : "/vis.0/ESSO.png",
                                    "5a5ed93f-84aa-4517-dc7c-c888f278b5c7" : "/vis.0/Test/img/Tanken/Gulf-Tankstelle.png",
                                    "6649f1c1-5154-4641-945c-96419ea88f01" : "/vis.0/Test/img/Tanken/total.png",
                                    "533abf42-a618-4d18-802e-fabdf0429269" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                    "528da962-bd28-4f5d-8bd0-cc01ba9b538c" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                    "51d4b47c-a095-1aa0-e100-80009459e03a" : "/vis.0/Jet.png"
                                    };
                
                
                on({id:'tankerkoenig.0.json'}, function (obj) {    
                
                    let json_tank = '';
                    json_tank = [];
                
                let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray;
                
                let json = JSON.parse(getState('tankerkoenig.0.json').val);
                
                let stations = Object.keys(json.prices);
                
                stations.forEach((station,i) => {
                
                    myStations.forEach((arr, j) => {
                
                        if(arr[0] == station) {
                            
                                json_tank.push(
                                {
                                    "img": station_png[station],
                                    "name": arr[1],
                                    "preis": json.prices[station].diesel,
                                    "status": json.prices[station].status
                                })
                
                            setState('0_userdata.0.materialdesignwidgets.tankerkoeningTabelle', JSON.stringify(json_tank), true);
                
                        }
                    });
                    
                })
                })
                

                Gratuliere! Auch wenn es funktioniert, das setState() sollte zwischen die Zeilen 41 und 42, sonst wird der State bei jeder Station der Tankerkoenig-json geschrieben

                S liv-in-sky 2 Replies Last reply Reply Quote 0
                • S
                  sveni_lee @fastfoot last edited by

                  @fastfoot

                  ja, danke! habe ich umgesetzt. Ich hab auch noch eine sortierfunktion eingebaut. So ist jetzt immer die günstigste Tankstelle oben...

                  var station_png = {"005056ba-7cb6-1ed5-8cbd-4897fe54e42b" : "/vis.0/Star.png",
                                      "aa1c6fb6-439a-4915-8ad8-0f67697a65e2" : "/vis.0/ESSO.png",
                                      "5a5ed93f-84aa-4517-dc7c-c888f278b5c7" : "/vis.0/Test/img/Tanken/Gulf-Tankstelle.png",
                                      "6649f1c1-5154-4641-945c-96419ea88f01" : "/vis.0/Test/img/Tanken/total.png",
                                      "533abf42-a618-4d18-802e-fabdf0429269" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                      "528da962-bd28-4f5d-8bd0-cc01ba9b538c" : "/vis.0/Test/img/Tanken/Shell_logo.svg.png",
                                      "51d4b47c-a095-1aa0-e100-80009459e03a" : "/vis.0/Jet.png"
                                      };
                  
                  
                  on({id:'tankerkoenig.0.json'}, function (obj) {    
                  
                      let json_tank = '';
                      json_tank = [];
                  
                  let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray;
                  
                  let json = JSON.parse(getState('tankerkoenig.0.json').val);
                  
                  let stations = Object.keys(json.prices);
                  
                  stations.forEach((station,i) => {
                  
                      myStations.forEach((arr, j) => {
                  
                          if(arr[0] == station) {
                              
                                  json_tank.push(
                                  {
                                      "img": station_png[station],
                                      "name": arr[1],
                                      "preis": json.prices[station].diesel,
                                      "status": json.prices[station].status
                                  })
                  
                          }
                      });
                      
                  })
                  
                      json_tank.sort(function (a, b) {
                  
                          return a.preis == b.preis ? 0 : +(a.preis > b.preis) || -1;
                  
                      });
                  
                   setState('0_userdata.0.materialdesignwidgets.tankerkoeningTabelle', JSON.stringify(json_tank), true);
                  })
                  
                  1 Reply Last reply Reply Quote 0
                  • liv-in-sky
                    liv-in-sky @fastfoot last edited by liv-in-sky

                    @fastfoot gelöscht

                    1 Reply Last reply Reply Quote 0
                    • liv-in-sky
                      liv-in-sky last edited by

                      @sveni_lee cooles script - vorallem wie hast du das gefunden :

                      let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray;
                      

                      ist das ok, wenn ich das script klaue und für ein html tabellen script nutze?

                      Image 10.png

                      S 1 Reply Last reply Reply Quote 0
                      • S
                        sveni_lee @liv-in-sky last edited by

                        @liv-in-sky

                        natürlich das okay... dafür ist doch so eine Community da. 🙂

                        dieser spezielle teil kommt aber tatsächlich von @fastfoot

                        let myStations = getObject('system.adapter.tankerkoenig.0').native.stationsarray; 
                        

                        ich kannte getObject() bisher auch nicht aber das eröffnet mir gerade wieder noch mehr Mögichkeiten.

                        liv-in-sky 2 Replies Last reply Reply Quote 0
                        • liv-in-sky
                          liv-in-sky @sveni_lee last edited by

                          @sveni_lee

                          danke dir

                          getObject war mir nicht neu - nur der pfad system.adapter.tank.... - wußte nicht, das da daten sind

                          also auch dank an @fastfood

                          tabelle:

                          https://forum.iobroker.net/topic/37609/html-tabelle-für-tankerkönig

                          1 Reply Last reply Reply Quote 0
                          • liv-in-sky
                            liv-in-sky @sveni_lee last edited by

                            @sveni_lee

                            für welches widget hast du dein script gemacht ?

                            S 1 Reply Last reply Reply Quote 0
                            • S
                              sveni_lee @liv-in-sky last edited by

                              @liv-in-sky
                              bei mir füttert es das "MaterialDesign Table"...
                              das klappt super...

                              1 Reply Last reply Reply Quote 1
                              • First post
                                Last post

                              Support us

                              ioBroker
                              Community Adapters
                              Donate

                              871
                              Online

                              31.8k
                              Users

                              80.0k
                              Topics

                              1.3m
                              Posts

                              4
                              18
                              1374
                              Loading More Posts
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes
                              Reply
                              • Reply as topic
                              Log in to reply
                              Community
                              Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                              The ioBroker Community 2014-2023
                              logo