Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Bestimmten Teil aus Datenpunkt auslesen

    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

    Bestimmten Teil aus Datenpunkt auslesen

    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ein.michael last edited by

      Hallo,

      folgendes Vorhaben:

      Ich erhalte über einen Adapter den Datenpunkt "level" mit folgendem Inhalt:

      {"OBD_FUELLEVEL":{"l":12.76,"percent":27.62,"timestamp":"2019-09-09T06:14:55.000Z"},"USER":{"timestamp":"2019-09-09T06:12:55.000Z","percent":5,"l":2.449824400000012},"MEAS":{"l":12.76,"percent":27.62,"timestamp":"2019-09-09T06:14:55.000Z"}}
      

      Die Zahl hinter percent, sprich in dem Fall 27,62 möchte ich nun in einem neuen Datenpunkt speichern, um einzig diese Zahl in meiner Visualisierung nutzen zu können.
      Ändert sich der Datenpunkt "level" bzw. verändert sich diese Zahl, soll die aktualisierte Zahl auch im entsprechenden Datenpunkt für die Visualisierung aktualisiert werden.
      Wie setze ich mein Vorhaben um? 🙂

      paul53 1 Reply Last reply Reply Quote 0
      • Dr. Bakterius
        Dr. Bakterius Most Active last edited by

        @ein-michael sagte in Bestimmten Teil aus Datenpunkt auslesen:

        Wie setze ich mein Vorhaben um?

        Zum Beispiel so:
        blockly.jpg

        Die Objekt IDs musst du natürlich anpassen.

        Hier noch der Code zum Importieren:


        <xml xmlns="http://www.w3.org/1999/xhtml">
        <variables>
        <variable type="" id="tjq?oPs()ymNXzGQ4bf?">Text</variable>
        <variable type="" id="NicV5Nqp(O%5kefuWX)">Wert</variable>
        </variables>
        <block type="on_ext" id="8Rctl7eB0,O_@IbmE,q^" x="-487" y="63">
        <mutation items="1"></mutation>
        <field name="CONDITION">ne</field>
        <field name="ACK_CONDITION"></field>
        <value name="OID0">
        <shadow type="field_oid" id="GjiqpMwB6S]v|Qo7jR2q">
        <field name="oid">default</field>
        </shadow>
        </value>
        <statement name="STATEMENT">
        <block type="variables_set" id="R)MuZ-s$k5tx0TwSTV"> <field name="VAR" id="tjq?oPs()ymNXzGQ4bf?" variabletype="">Text</field> <value name="VALUE"> <block type="get_value" id="XVw2N?@%MY#_tc*-u.47"> <field name="ATTR">val</field> <field name="OID">ID auswählen</field> </block> </value> <next> <block type="variables_set" id="g@T^pE[!kaJQ+bl1j30J"> <field name="VAR" id="NicV5Nqp(O%5kefuW*X)" variabletype="">Wert</field> <value name="VALUE"> <block type="text_indexOf" id="}.W-JS?Ef-cY_T6S(^}q"> <field name="END">FIRST</field> <value name="VALUE"> <block type="variables_get" id="G,Y1?0%CJQ{pJ|(KNBc">
        <field name="VAR" id="tjq?oPs()ymNXzGQ4bf?" variabletype="">Text</field>
        </block>
        </value>
        <value name="FIND">
        <shadow type="text" id="o,Lc/4dp9w:]p
        ?DLy@A">
        <field name="TEXT">"percent":</field>
        </shadow>
        </value>
        </block>
        </value>
        <next>
        <block type="variables_set" id="KZu6E9ya_jslf7KLZ;+w">
        <field name="VAR" id="NicV5Nqp(O%5kefuW
        X)" variabletype="">Wert</field>
        <value name="VALUE">
        <block type="text_getSubstring" id="uZ8oVzB*]H?#R_0Y4[^J">
        <mutation at1="true" at2="true"></mutation>
        <field name="WHERE1">FROM_START</field>
        <field name="WHERE2">FROM_START</field>
        <value name="STRING">
        <block type="variables_get" id="pPSf;{M}R^q-sf0hth!z">
        <field name="VAR" id="tjq?oPs()ymNXzGQ4bf?" variabletype="">Text</field>
        </block>
        </value>
        <value name="AT1">
        <block type="math_arithmetic" id="uZ^Qd}3nA$48?t/aTQaN">
        <field name="OP">ADD</field>
        <value name="A">
        <shadow type="math_number" id="5aM~9tVWzwHAjeQ.GV4w">
        <field name="NUM">1</field>
        </shadow>
        <block type="variables_get" id="l-8N1]=GKxKa};6P2z,{">
        <field name="VAR" id="NicV5Nqp(O%5kefuWX)" variabletype="">Wert</field>
        </block>
        </value>
        <value name="B">
        <shadow type="math_number" id="89g=[L5A[E+8=K:mS-W4">
        <field name="NUM">10</field>
        </shadow>
        </value>
        </block>
        </value>
        <value name="AT2">
        <block type="math_arithmetic" id="ihUTbI=K.Ocyo!|Ce{|e">
        <field name="OP">ADD</field>
        <value name="A">
        <shadow type="math_number" id="6H:ra{Q;LDtsp@d+N`XX">
        <field name="NUM">1</field>
        </shadow>
        <block type="variables_get" id="p0M}f);aZFu+:_s4x~x-">
        <field name="VAR" id="NicV5Nqp(O%5kefuW
        X)" variabletype="">Wert</field>
        </block>
        </value>
        <value name="B">
        <shadow type="math_number" id="5)?6A2Q$AxTwqAL)}1Ec">
        <field name="NUM">15</field>
        </shadow>
        </value>
        </block>
        </value>
        </block>
        </value>
        <next>
        <block type="variables_set" id="JZCn31Iy;hhW_{#VND(^">
        <field name="VAR" id="NicV5Nqp(O%5kefuWX)" variabletype="">Wert</field>
        <value name="VALUE">
        <block type="convert_tonumber" id="KO3nuLNJ7J+_l5B,6,ea">
        <value name="VALUE">
        <block type="variables_get" id="lp^r2D|HW95-Rcd}Nu}d">
        <field name="VAR" id="NicV5Nqp(O%5kefuW
        X)" variabletype="">Wert</field>
        </block>
        </value>
        </block>
        </value>
        <next>
        <block type="control" id="TOd#R8d%6/[s)0;Qa|d-">
        <mutation delay_input="false"></mutation>
        <field name="OID">Object ID</field>
        <field name="WITH_DELAY">FALSE</field>
        <value name="VALUE">
        <block type="variables_get" id="G%wag.?%KDMuewB3n70+">
        <field name="VAR" id="NicV5Nqp(O%5kefuW*X)" variabletype="">Wert</field>
        </block>
        </value>
        </block>
        </next>
        </block>
        </next>
        </block>
        </next>
        </block>
        </next>
        </block>
        </statement>
        </block>
        </xml>

        1 Reply Last reply Reply Quote 0
        • paul53
          paul53 @ein.michael last edited by paul53

          @ein-michael sagte:

          Die Zahl hinter percent, sprich in dem Fall 27,62 möchte ich nun in einem neuen Datenpunkt speichern

          Ich würde es so machen.

          // IDs eintragen !
          const idLevel = '...';
          const idPercent = '...'; // DP-Typ: Zahl
          
          on(idLevel, function(dp) {
             var percent = JSON.parse(dp.state.val).OBD_FUELLEVEL.percent;
             setState(idPercent, percent, true);
          });
          
          1 Reply Last reply Reply Quote 0
          • A
            ahfreezer last edited by ahfreezer

            @paul53

            Hi Paul53,

            du hattest hier im Thread schon mal geholfen. Vlt kannst du dir mein "Problem" einmal anschauen.
            In einem Datenpunkt wird kontinuierlich das Log weggeschrieben. Jeder neue Eintrag wird in {} eingefasst und beinhaltet
            10 Felder.

            Ich will für diese 10 Felder einzelne Datenpunke anlegen und nach jedem neuen Logeintrag die Datenfelder mit den letzten
            Einträgen aktualisieren.

            Hast du eine Idee wie ich das hinbekomme?

            VG

            [{"id":"99999999999999","smartlockId":1234567,"deviceType":0,"authId":"1234567","name":"userA ","action":3,"trigger":0,"state":0,"autoUnlock":false,"date":"2020-11-02T07:07:06.000Z"},{"id":"99999999999999","smartlockId":1234567,"deviceType":0,"authId":"1234567","name":"userA ","action":3,"trigger":0,"state":0,"autoUnlock":false,"date":"2020-11-02T06:31:00.000Z"},{"id":"99999999999999","smartlockId":1234567,"deviceType":0,"name":"","action":1,"trigger":1,"state":0,"autoUnlock":false,"date":"2020-11-02T06:10:31.000Z"}]
            paul53 1 Reply Last reply Reply Quote 0
            • paul53
              paul53 @ahfreezer last edited by paul53

              @ahfreezer
              Ist der letzte Eintrag immer der aktuelle ? Dann sollte es so funktionieren:

              const idJson = '...'; // Quelle
              const idName = '...'; //
              const idTrigger = '0_userdata.0.xyz.Trigger'; // DP-Typ: Zahl
              // usw.
              
              on(idJson, function(dp) {
                 let arr = JSON.parse(dp.state.val);
                 let obj = arr[0]; // erster Eintrag
                 setState(idName, obj.name, true);
                 setState(idTrigger, obj.trigger, true);
                 // usw.
              });
              
              A 1 Reply Last reply Reply Quote 1
              • A
                ahfreezer @paul53 last edited by

                @paul53 sagte in Bestimmten Teil aus Datenpunkt auslesen:

                                                                                                                                            const idJson = '...'; // Quelle                                                                                                                                                                            const idName = '...';                                                                                                                                                                            // usw.                                                                                                                                                                                                                                                                                                                                                         on(idJson, function(dp) {                                                                                                                                                                               let arr = JSON.parse(dp.state.val);                                                                                                                                                                               let obj = arr[arr.length - 1]; //letzter Eintrag                                                                                                                                                                               setState(idName, obj.name, true);                                                                                                                                                                               // usw.                                                                                                                                                                            });                                            
                

                Hi Paul,

                nein . Es wird immer der aktuellste Eintrag am Anfang gesetzt.
                Ich habs noch nicht ganz verstanden wie das Skript arbeitet. Mit dem ersten Wurf bekomme ich einen Wert ausgelesen mit der Bezeichnung "name"..
                Aber wenn ich versuche einen zweiten Wert aus dem Array (z.B. "Trigger") zu lesen will es bei mir nicht klappen.

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

                  @ahfreezer sagte in Bestimmten Teil aus Datenpunkt auslesen:

                  Es wird immer der aktuellste Eintrag am Anfang gesetzt.

                  Dann ändere:

                     let obj = arr[0]; //erster Eintrag
                  
                  A 1 Reply Last reply Reply Quote 0
                  • A
                    ahfreezer @paul53 last edited by

                    @paul53
                    THX

                    Screenshot 2020-11-02 154648.jpg

                    das klappt soweit...den namen liest er auch brav aus...aber wie bekomme ich noch die Action in ein separates Datenfeld?

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

                      @ahfreezer sagte:

                      wie bekomme ich noch die Action in ein separates Datenfeld?

                         setState(idAction, obj.action, true); // Typ: Zahl
                      
                      1 Reply Last reply Reply Quote 1
                      • A
                        ahfreezer last edited by

                        Wie peinlich...jetzt hab ich es verstanden!

                        Danke dir vielmals... das hilft mir sehr weiter!

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        461
                        Online

                        31.9k
                        Users

                        80.2k
                        Topics

                        1.3m
                        Posts

                        blockly javascript
                        4
                        10
                        1465
                        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