Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Script geht zeitweise auf Pause

    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

    Script geht zeitweise auf Pause

    This topic has been deleted. Only users with topic management privileges can see it.
    • T
      ticaki Developer @Negalein last edited by ticaki

      @Negalein

      if (!isScriptActive("Test")) {
          runScript("Test");
      // oder sende msg.
      }
      

      Hoffe das hilft.

      Negalein 1 Reply Last reply Reply Quote 0
      • Negalein
        Negalein Global Moderator @ticaki last edited by

        @ticaki sagte in Script geht zeitweise auf Pause:

        Hoffe das hilft.

        Danke

        Das wird als eigenes Script angelegt?

        T 1 Reply Last reply Reply Quote 0
        • T
          ticaki Developer @Negalein last edited by ticaki

          @Negalein

          Ja. Weiß nur nicht wie das Trennzeichen für Unterordner aussieht. 🙂

          EDIT: must du alle x Zeiteinheiten per Cron ausführen lassen.

          var gasStation = JSON.parse(obj.state.val); 
          if (gasStation.length === 0) return;
          gasStation = gasStation.filter(g => g.prices.length > 0);
          

          sieht das in deinem Script so aus?

          Negalein 1 Reply Last reply Reply Quote 0
          • Negalein
            Negalein Global Moderator @ticaki last edited by

            @ticaki sagte in Script geht zeitweise auf Pause:

            sieht das in deinem Script so aus?

            So schaut das Script aus

            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //  "Spritpreise_AT v.0.5"                                                                                                              //
            //  e-control Spritpreise                                                                                                               //    
            //  ursprüngl. Script von steinejo_io vom                                                                                               //
            //                                                                                                                                      //
            //  Zwingend erforderlich sind der Parser Adapter und die URL aus der API. Links und Hilfe zum Erstellemn findet ihr im Folgenden Lnk:  //
            //  https://forum.iobroker.net/topic/20314/skripten-des-e-control-spritpreisrechners                                                    //
            //  Das manuelle Anlegen von Daenpunkten ist nicht mehr notwendig. erledigt das Script beim ersten Aufruf.                              //
            //  Auf das "E" Zeichen habe ich verzichtet, da es in VIS genz einfach an der jeweils gewünschten Stelle produzierbar ist.              //
            //                                                                                                                                      //
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
             
            on({id: "parser.0.Spritpreisrechner"/*Spritpreisrechner*/, change: 'any'}, function(obj)
            {
            log("Start Spritvergleich");
             
                var gasStation = JSON.parse(obj.state.val);
                gasStation = gasStation.filter(g => g.prices.length > 0);
                if (gasStation.length === 0) return;
                //Aral=1, eni=2, Shell=3, OMV=4, avanti=5, bp=6, JET=7, Turmöl=8, Lagerhaus=9, AVIA=10, A1=11, Diskont=12, IQ=13
                var arrMarke = ['Aral', 'eni', 'Shell', 'OMV', 'avanti', 'BP', 'JET', 'Turmöl', 'Lagerhaus', 'AVIA', 'A1', 'Diskont', 'DISKONT', 'IQ', 'SB-Tankstelle', 'bp', 'Land', 'Bp'];
            	var i = 0;
                for (var i = 1; i <= 5; i++) {
                    // console.log(i);
                    // console.log("javascript.0.Sprit_AT.name_"+i);
                    createState("javascript.0.Sprit_AT.Treffer_"+i+".Name_"+i, {type: "string", name: "Platz "+i, read: true, write: true});
                    createState("javascript.0.Sprit_AT.Treffer_"+i+".Preis_"+i, {type: "string", name: "Platz "+i, read: true, write: true});
                    createState("javascript.0.Sprit_AT.Treffer_"+i+".PreisP_"+i, {type: "string", name: "Platz "+i, read: true, write: true});
            		createState("javascript.0.Sprit_AT.Treffer_"+i+".Strasse_"+i, {type: "string", name: "Platz "+i, read: true, write: true});
                    createState("javascript.0.Sprit_AT.Treffer_"+i+".PLZ_Ort_"+i, {type: "string", name: "Platz "+i, read: true, write: true});
                    createState("javascript.0.Sprit_AT.Treffer_"+i+".Logo_"+i, {type: "number", name: "Logo "+i, read: true, write: true});
            		createState("javascript.0.Sprit_AT.Treffer_"+i+".Latitude_"+i, {type: "number", name: "Latitude "+i, read: true, write: true});
            		createState("javascript.0.Sprit_AT.Treffer_"+i+".Longitude_"+i, {type: "number", name: "Longitude "+i, read: true, write: true});
            		createState("javascript.0.Sprit_AT.Treffer_"+i+".offen_"+i, {type: "boolean", name: "offen "+i, read: true, write: true});
            	}
            	
             
                var index = 0;
                //for (index = 0; index < gasStation.length; ++index) {
                for (index = 0; index <= 4; ++index) {
            	if (gasStation[index].prices.length < 1) continue;
            	var arrname = gasStation[index].name.split(' ');
            		if (arrname.length > 0) {
            				var markenname = arrname[0];
            			}
            			else
            			{
            				var markenname = gasStation[index].name;
            			}
            		var station = gasStation[index].name;
                setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Name_"+(index+1), gasStation[index].name);
                setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Preis_"+(index+1), (gasStation[index].prices[0].amount).toString().replace(".",","));
                setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".PreisP_"+(index+1), (gasStation[index].prices[0].amount).toString().replace(".","."));
            	setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Strasse_"+(index+1), (gasStation[index].location.address));
                setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".PLZ_Ort_"+(index+1), (gasStation[index].location.postalCode) + " " + (gasStation[index].location.city));
                setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Latitude_"+(index+1), (gasStation[index].location.latitude));
            	setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Longitude_"+(index+1), (gasStation[index].location.longitude));
            	setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".offen_"+(index+1), (gasStation[index].open));
            	
            	//Aral=1, eni=2, Shell=3, OMV=4, avanti=5, bp=6, JET=7, Turmöl=8, Lagerhaus=9, AVIA=10, A1=11, Diskont=12, IQ=13
            	
            	var markennameklein=markenname.toLowerCase();
            	var x= 0;
            	for (x=0; x < arrMarke.length; x++) {
            		var arrMklein=arrMarke[x].toLowerCase();
            		//console.log("x=" + x + "/ Markennameklein =" + markennameklein + "/ Array =" + arrMklein);
            		if (arrMklein == markennameklein) {
            			setState("javascript.0.Sprit_AT.Treffer_"+(index+1)+".Logo_"+(index+1), (x+1));
            		}
            	}
            	
            	}
             
            log("Ende Spritvergleich");
            });
            

            must du alle x Zeiteinheiten per Cron ausführen lassen.

            Das wird vom Parser geregelt. Der fragt die Adresse alle 10 Sek. ab und das Script reagiert darauf.

            T 1 Reply Last reply Reply Quote 0
            • T
              ticaki Developer @Negalein last edited by ticaki

              @Negalein
              Dein letzter Fehler sieht so aus als wenn der Parser keine Daten geliefert hat und deshalb Zeile 18 gescheitert ist

              Versuche bitte mal folgendes: 2 Zeilen vertauschen und gasStation auf array/object prüfen.

              var gasStation = JSON.parse(obj.state.val);
              if (typeof gasStation != 'object' || gasStation.length === 0) return;
              gasStation = gasStation.filter(g => g.prices.length > 0);
              if (gasStation.length === 0) return;
              

              EDIT: ups

              Negalein 1 Reply Last reply Reply Quote 0
              • Negalein
                Negalein Global Moderator @ticaki last edited by

                @ticaki sagte in Script geht zeitweise auf Pause:

                Versuche bitte mal folgendes: 2 Zeilen vertauschen und gasStation auf array/object prüfen.

                Danke
                Habs eingefügt/vertauscht und werde es die nächsten Tage beobachten.

                T 1 Reply Last reply Reply Quote 0
                • T
                  ticaki Developer @Negalein last edited by

                  @Negalein
                  hab editiert bitte beachten

                  Negalein 1 Reply Last reply Reply Quote 0
                  • Negalein
                    Negalein Global Moderator @ticaki last edited by

                    @ticaki sagte in Script geht zeitweise auf Pause:

                    hab editiert bitte beachten

                    Also

                        var gasStation = JSON.parse(obj.state.val);
                        gasStation = gasStation.filter(g => g.prices.length > 0);
                        if (gasStation.length === 0) return;
                    

                    gegen

                    var gasStation = JSON.parse(obj.state.val);
                    if (typeof gasStation != 'object' || gasStation.length === 0) return;
                    gasStation = gasStation.filter(g => g.prices.length > 0);
                    if (gasStation.length === 0) return;
                    

                    tauschen

                    T 1 Reply Last reply Reply Quote 0
                    • T
                      ticaki Developer @Negalein last edited by ticaki

                      @Negalein
                      Jup, habs nochmal verbessert. Mache zwar viel mit Arrays, mußte aber bis dato noch nicht prüfen, ob es auch eines ist 🙂

                      var gasStation = JSON.parse(obj.state.val);
                      if (!Array.isArray(gasStation) || gasStation.length === 0) return;
                      gasStation = gasStation.filter(g => g.prices.length > 0);
                      if (gasStation.length === 0) return;
                      
                      Negalein 1 Reply Last reply Reply Quote 0
                      • Negalein
                        Negalein Global Moderator @ticaki last edited by

                        @ticaki sagte in Script geht zeitweise auf Pause:

                        habs nochmal verbessert

                        Thx

                        sigi234 1 Reply Last reply Reply Quote 0
                        • sigi234
                          sigi234 Forum Testing Most Active @Negalein last edited by sigi234

                          @Negalein sagte in Script geht zeitweise auf Pause:

                          @ticaki sagte in Script geht zeitweise auf Pause:

                          habs nochmal verbessert

                          Thx

                          Kann man das Skript jetzt oben benutzen? Ist das das aktuelle.

                          Negalein 1 Reply Last reply Reply Quote 0
                          • Negalein
                            Negalein Global Moderator @sigi234 last edited by

                            @sigi234 sagte in Script geht zeitweise auf Pause:

                            Kann man das Skript jetzt oben benutzen? Ist das das aktuelle.

                            Ja, diese 4 Zeilen

                            var gasStation = JSON.parse(obj.state.val);
                            if (!Array.isArray(gasStation) || gasStation.length === 0) return;
                            gasStation = gasStation.filter(g => g.prices.length > 0);
                            if (gasStation.length === 0) return;
                            

                            statt diesen nehmen

                            var gasStation = JSON.parse(obj.state.val);
                            gasStation = gasStation.filter(g => g.prices.length > 0);
                            if (gasStation.length === 0) return;
                            
                            1 Reply Last reply Reply Quote 0
                            • AlCalzone
                              AlCalzone Developer @Negalein last edited by

                              @Negalein Du hast zwar inzwischen die Lösung, aber generell sollte man lieber Fehler abfangen, als Skripte mit Fehlern einfach neu zu starten 😉

                              Z 1 Reply Last reply Reply Quote 1
                              • Z
                                zanabria @AlCalzone last edited by

                                @AlCalzone
                                hallo habe aktuell auch das Problem, dass viele Scripte auf Pause gehen. Woran kann das liegen? Habe alles gecheckt und keinen Fehler gefunden. Das Run Sript wurde kopiert aus dem Pause Script und nur angepasst. Es scheint das Bessere zu sein, siehe Bild.
                                543a46d4-1b5a-40ec-ad68-dc3d81648b81-grafik.png

                                Ich habe mal die beiden Scripte angehängt.
                                Pause-Script.txt
                                Run-Script.txt.
                                Kann man mir hier weiterhelfen.
                                LG Zanabria

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

                                Support us

                                ioBroker
                                Community Adapters
                                Donate

                                789
                                Online

                                31.9k
                                Users

                                80.1k
                                Topics

                                1.3m
                                Posts

                                javascript
                                7
                                32
                                1317
                                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