Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Blockly
    5. JSON mit unbekannter Anzahl an DP

    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 mit unbekannter Anzahl an DP

    This topic has been deleted. Only users with topic management privileges can see it.
    • paul53
      paul53 @JoergH last edited by paul53

      @joergh sagte: Format nicht korrekt ist?

          let obj = JSON.parse(dp.state.val)[0];
      

      Die Attribute enthalten viele unzulässige Zeichen, die auch für eine ID schlecht sind.

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

        @paul53 Aaah! Danke. Ist wohl noch in einem Array verpackt...jetzt klappt es. Super, vielen Dank!

        J 1 Reply Last reply Reply Quote 0
        • J
          JoergH @JoergH last edited by JoergH

          @paul53

          Hallo Paul,

          ich hätte noch einmal ein Thema mit der Routine. Und zwar habe ich nun einen mqtt JSON, welches u.a. einen array enthält. Das Script läuft zwar, aber er mault, dass ich ihm einen array an ein object übergeben würde und dass das in Zukunft nicht mehr laufen könnte.

          Das JSON sieht so aus:

          {"sniu":false,"serialNumber":"SMDBEM10201221","deviceID":12,"lastUpdate":1706889837119,"voltageV":53.628,"currentA":0.086,"powerW":4.612007999999999,"capacityP":67.0,"capacityAh":45.63075583333333,"ratedCapacityAh":68.0,"ratedVoltageV":51.2,"ratedChargeCurrentC":1.0588235294117647,"ratedDischargeCurrentC":1.2705882352941176,"storageName":"bank1","remainingTimeSign":0,"dcConnected":true,"available":true,"busName":"bus0","chargeControl":100,"dischargeControl":100,"chargePower":{"sniu":false,"serialNumber":"SMDBEM10201221","deviceID":12,"lastUpdate":1706889837129,"powerW":4.612007999999999,"voltageV":53.628,"currentA":0.086,"ratedPowerW":3686,"powerName":"bank1-chargingPower","energyWh":1696104.19315948,"powerType":"stCharge","available":true},"dischargePower":{"sniu":false,"serialNumber":"SMDBEM10201221","deviceID":12,"lastUpdate":1706889837129,"powerW":0.0,"voltageV":53.628,"currentA":0.0,"ratedPowerW":4423,"powerName":"bank1-dischargingPower","energyWh":1657202.721438139,"powerType":"stDischarge","available":true},"alertMap":{},"updateProgress":null,"cellVoltageVArr":[3.349,3.351,3.352,3.356,3.351,3.353,3.351,3.351,3.35,3.352,3.356,3.345,3.363,3.339,3.363,3.346],"maxCellValue":3363,"maxCellNumber":14,"minCellValue":3339,"minCellNumber":13,"balansingStatus":142,"eventCount":0,"gyroX":null,"gyroY":null,"gyroZ":null,"temp0":36.61,"temp1":null,"temp2":null,"alignedCapacity":-1837154049,"chargeCounter":75219,"dischargeCounter":74942,"remChargeTime":0,"remDischargeTime":0,"maxChargeCurrent":142849,"maxDischargeCurrent":-141185,"maxChargeCurrentDuration":36,"maxDischargeCurrentDuration":983,"maxCellDiff":null,"minCellDiffNum":null,"maxCellDiffNum":null,"maxCellDiffValue":null,"ioDataArr":[{"state":4,"pendingState":255},{"state":4,"pendingState":255},{"state":4,"pendingState":255}],"mainProtectionStatus":0,"mainRelayStatus":1,"warningReg":null,"warningCount":0,"errorReg":null,"errorCount":0,"controlLastUpdate":1706889837119}
          

          und die Warnung im Log dann so:

          javascript.0
          	2024-02-02 17:05:48.274	warn	at processImmediate (node:internal/timers:476:21)
          javascript.0
          	2024-02-02 17:05:48.274	warn	at Immediate._onImmediate (/opt/iobroker/node_modules/@iobroker/js-controller-adapter/src/lib/adapter/adapter.ts:11229:62)
          javascript.0
          	2024-02-02 17:05:48.274	warn	at Object.stateChange (/opt/iobroker/node_modules/iobroker.javascript/main.js:645:29)
          javascript.0
          	2024-02-02 17:05:48.274	warn	at Object.callback (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1266:38)
          javascript.0
          	2024-02-02 17:05:48.274	warn	at Object.<anonymous> (script.js.Energy:12:26)
          javascript.0
          	2024-02-02 17:05:48.274	warn	at Array.forEach (<anonymous>)
          javascript.0
          	2024-02-02 17:05:48.273	warn	at script.js.Energy:13:41
          javascript.0
          	2024-02-02 17:05:48.273	warn	at setState (/opt/iobroker/node_modules/iobroker.javascript/lib/sandbox.js:1740:20)
          javascript.0
          	2024-02-02 17:05:48.272	warn	You are assigning a array to the state "0_userdata.0.Battery10201221.ioDataArr" which expects a object. Please fix your code to use a object or change the state type to array. This warning might become an error in future versions.
          

          Was kann ich machen?

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

            @joergh sagte: Was kann ich machen?

            Ändere den Typ von "0_userdata.0.Battery10201221.ioDataArr" in "array".

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

              @paul53 Achso, einfach manuell?

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

                @joergh sagte: einfach manuell?

                Ja, wie sonst?

                or change the state type to array.
                
                J 1 Reply Last reply Reply Quote 0
                • J
                  JoergH @paul53 last edited by

                  @paul53 Ich habe da zu kompliziert gedacht und vermutet man muss das beim Anlegen programmiertechnisch regeln. Hab sie nun einfach manuell angelegt und jetzt ist Ruhe.
                  Danke für den Tipp!

                  R 1 Reply Last reply Reply Quote 0
                  • R
                    Ralf 8 @JoergH last edited by

                    Hallo,

                    vielen Dank für eure Beiträge. Leider komme ich mit meinem JSON trotzdem nicht zurecht,
                    da mittendrin ein Array liegt. Wenn ich den Skript oben ohne [0] laufen lasse, stehen alle Daten von params in einem neuen JSON.

                    Ich benötige eigentlich nur den Parameter total_act_power.

                    Mit Alias habe ich es auch versucht, aber

                    JSON.parse(val).params.[em:0]
                     JSON.parse(val).params.['em:0'] 
                     JSON.parse(val).params.'em:0'
                    

                    funktionieren nicht.

                    Aus diesem JSON möchte ich einen Datenpunkt für total_act_power erstellen:

                    {
                      "src": "shellypro3em-xyz",
                      "dst": "shellypro3em-xyz/events",
                      "method": "NotifyStatus",
                      "params": {
                        "ts": 1718631165.1,
                        "em:0": {
                          "id": 0,
                          "a_act_power": -153.9,
                          "a_aprt_power": 174.1,
                          "a_current": 0.751,
                          "a_freq": 50,
                          "a_pf": 0.89,
                          "a_voltage": 231.6,
                          "b_act_power": 43.1,
                          "b_aprt_power": 70.7,
                          "b_current": 0.305,
                          "b_freq": 50,
                          "b_pf": 0.61,
                          "b_voltage": 231.5,
                          "c_act_power": 41.1,
                          "c_aprt_power": 81.9,
                          "c_current": 0.354,
                          "c_freq": 50,
                          "c_pf": 0.51,
                          "c_voltage": 231.4,
                          "n_current": null,
                          "total_act_power": -69.696,
                          "total_aprt_power": 326.678,
                          "total_current": 1.411
                        }
                      }
                    }
                    
                    
                    paul53 1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @Ralf 8 last edited by

                      @ralf-8 sagte: Mit Alias habe ich es auch versucht

                      JSON.parse(val).params['em:0'].total_act_power
                      
                      R 1 Reply Last reply Reply Quote 0
                      • R
                        Ralf 8 @paul53 last edited by

                        @paul53 sagte in JSON mit unbekannter Anzahl an DP:

                        JSON.parse(val).params['em:0'].total_act_power

                        Herzlichen Dank. Super. Jetzt geht es.
                        Dass zwischen params und ['em:0'] kein Punkt benötigt wird, muss man erstmal herausfinden.

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        747
                        Online

                        31.9k
                        Users

                        80.2k
                        Topics

                        1.3m
                        Posts

                        4
                        17
                        683
                        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