Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. webseite auslesen und in Datenpunkte darstellen json

    NEWS

    • Wir empfehlen: Node.js 22.x

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker goes Matter ... Matter Adapter in Stable

    webseite auslesen und in Datenpunkte darstellen json

    This topic has been deleted. Only users with topic management privileges can see it.
    • Homoran
      Homoran Global Moderator Administrators @LukyLuke last edited by

      @LukyLuke sagte in webseite auslesen und in Datenpunkte darstellen json:

      Nur fehlt mir sämtliches Wissen dazu. Leider.

      mir leider auch, aber mit getstate kannst du keine Website auslesen sondern nur den bisherigen Datenpunkt, in den du das JSON geschrieben hast

      1 Reply Last reply Reply Quote 0
      • bahnuhr
        bahnuhr Forum Testing Most Active @Gargano last edited by

        @Gargano sagte in webseite auslesen und in Datenpunkte darstellen json:

        @LukyLuke
        TorConnected und TorHi vorher als Objekt anlegen

        
        var Tor =JSON.parse(getState('Torzustand').val);
        log (Tor.connected);
        log (Tor.hi);
        
        setState('TorConnected',Tor.connected);
        setState('TorHi',Tor.hi);
        
        

        Bei mir steht stringify !
        Warum nimmst du parse ?

        Gargano 1 Reply Last reply Reply Quote 0
        • Gargano
          Gargano @bahnuhr last edited by

          @bahnuhr Ein JSON.stringify wandelt ein JSON Objekt in einen String. JSON.parse macht dies umgekehrt.

          bahnuhr 1 Reply Last reply Reply Quote 0
          • bahnuhr
            bahnuhr Forum Testing Most Active @Gargano last edited by

            @Gargano sagte in webseite auslesen und in Datenpunkte darstellen json:

            @bahnuhr Ein JSON.stringify wandelt ein JSON Objekt in einen String. JSON.parse macht dies umgekehrt.

            Genau.
            Und mit parse klappt es nicht.

            Gargano 1 Reply Last reply Reply Quote 0
            • Gargano
              Gargano @bahnuhr last edited by

              @bahnuhr In dem Datenpunkt Torzustand steht doch ein String drin,oder nicht ?

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

                @Gargano nee, ein json!
                deshalb müsste @LukyLuke diesen zum parsen ja aufrufen, wenn er getstate nuten will

                1 Reply Last reply Reply Quote 0
                • paul53
                  paul53 @LukyLuke last edited by

                  @LukyLuke sagte:

                  möchte ich die zwei Variablen in zwei Datenpunkte schreiben.

                  Blockly_temp.JPG

                  LukyLuke 1 Reply Last reply Reply Quote 1
                  • LukyLuke
                    LukyLuke @paul53 last edited by

                    @paul53
                    @bahnuhr
                    @Gargano
                    @Homoran

                    Danke, das klappt so. Ich habe die Datenpunkte TorConnected und TorHi angelegt und dann das blockly von Paul53 übernommen. Die Zustände werden jetzt korrekt angezeigt.
                    Hoffentlich versteh ich irgendwann wie man sowas als script richtig erstellt.

                    Fall gelöst.
                    Nochmals vielen Dank!!

                    paul53 Gargano 2 Replies Last reply Reply Quote 0
                    • paul53
                      paul53 @LukyLuke last edited by

                      @LukyLuke sagte:

                      Fall gelöst.

                      So wird die Abfrage aber nur einmal bei Skript-Start ausgeführt. Für eine zyklische Abfrage sollte request innerhalb eines Zeitplans ausgeführt werden.

                      LukyLuke 1 Reply Last reply Reply Quote 0
                      • LukyLuke
                        LukyLuke @paul53 last edited by

                        @paul53

                        Da hast du recht. Ich überlege noch wie ich das am sinnvollsten regele. Das Tor wird von mehreren Funksendern, Handys und zukünftig auch von der Doorstation im Haus bedient.
                        Entweder ich lasse das im Intervall abfragen oder immer nur bei bedarf wenn z.B. das Tor per webrequest bedient werden soll.

                        Das besondere ist das ich auch noch die Teilöffnung mit berücksichtigen möchte. Das Tor öffnet dann nur etwa 1 m.

                        1 Reply Last reply Reply Quote 0
                        • Gargano
                          Gargano @LukyLuke last edited by Gargano

                          @LukyLuke Hier mal das Script zum Anschauen und evtl. Ausprobieren. Liest jede Minute den Zustand des Tores ein und speichert den Zustand in '0_userdata.0.Tor.Connected' und '0_userdata.0.Tor.Hi'

                          Vorher das npm Module axios in de JS Instanz eintragen

                          2c383cee-48f7-403c-9b8b-69a909051265-grafik.png

                          const prefix = '0_userdata.0.'; //'javascript.0.'; //
                          const idTorConnected = prefix+"Tor.Connected";
                          const idTorHi = prefix+"Tor.Hi";
                          
                          const creatStateList = [
                              {name :idTorConnected, type:"boolean", role : "value"},
                              {name :idTorHi, type:"boolean", role : "value"}
                          ]
                          
                          async function createState (item){
                              await createStateAsync(item.name, { 
                                      type: item.type,
                                      min: 0,
                                      def: 0,
                                      role: item.role
                                  });
                          }
                          
                          async function makeStatList() {
                              creatStateList.forEach (function(item) {
                                  createState(item);
                              });
                          }
                          
                          makeStatList();
                          
                          const axios = require('axios');
                          const url = 'https://svr39.supla.org/direct/**************/read?format=json';
                          
                          // mySchedule im JS Editor mit dem Uhrsymbol oben rechts erstellen
                          
                          var mySchedule ='* * * * *';  // jede Minute
                          schedule(mySchedule, getTor);
                          
                          function getTor() {
                              axios.get(url)
                                  .then(function (response) {
                                      // handle success
                                      let tor = response.data;  
                                      console.log ('JSON '+JSON.stringify(tor));
                                      setState(idTorConnected, tor.connected);
                                      setState(idTorHi, tor.hi);
                                  })
                                  .catch(function (error) {
                                      // handle error
                                      console.log(error);
                                  })
                              
                          }
                          
                          
                          
                          1 Reply Last reply Reply Quote 0
                          • First post
                            Last post

                          Support us

                          ioBroker
                          Community Adapters
                          Donate

                          856
                          Online

                          32.0k
                          Users

                          80.4k
                          Topics

                          1.3m
                          Posts

                          5
                          17
                          1175
                          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