Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Brauche bitte Hilfe zu Json String

    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

    Brauche bitte Hilfe zu Json String

    This topic has been deleted. Only users with topic management privileges can see it.
    • Y
      Yoshi last edited by

      Hallo Leute,

      ich habe hier ein BMS, was ich per Matt angebunden habe. Das spuckt mir hier keine einzelnen Datenpunkte aus sondern alles in einem.
      Wie kann ich nun aus dem String einzelne Datenpunkte erstellen. Ich stehe da gerade total auf dem Schlauch.

      {
      "EspError": "",
      "BMSAddress": 0,
      "SOC": 38.4,
      "RemainCapacity": 112.03,
      "BatteryVoltage": 52.82,
      "ChargeDischargeCurrent": -4.86,
      "CellMinV": 3.301,
      "CellMinIdx": 0,
      "CellMaxV": 3.303,
      "CellMaxIdx": 9,
      "CellDiffMv": 1,
      "CellCount": 16,
      "CellVoltages": {
      "Cell1": 3.301,
      "Cell2": 3.301,
      "Cell3": 3.302,
      "Cell4": 3.302,
      "Cell5": 3.301,
      "Cell6": 3.301,
      "Cell7": 3.301,
      "Cell8": 3.302,
      "Cell9": 3.302,
      "Cell10": 3.303,
      "Cell11": 3.301,
      "Cell12": 3.301,
      "Cell13": 3.302,
      "Cell14": 3.303,
      "Cell15": 3.302,
      "Cell16": 3.303
      },
      "TempCount": 6,
      "Temperatures": {
      "CellTemp1": 17.5,
      "CellTemp2": 17.6,
      "CellTemp3": 17.9,
      "CellTemp4": 17.6,
      "AmbientTemp": 18.2,
      "PowerTemp": 17
      },
      "BatteryCycles": 5,
      "SOH": 100,
      "BatteryCapacity": 291.35,
      "RatedCapacity": 150,
      "BusVoltage": 52.86
      }

      paul53 M 2 Replies Last reply Reply Quote 0
      • paul53
        paul53 @Yoshi last edited by paul53

        @yoshi
        Beispiel:

        on(idJson, function(dp) {
           const obj = JSON.parse(dp.state.val);
           setState(idCellTemp2, obj.Temperatures.CellTemp2, true);
        });
        
        Y 1 Reply Last reply Reply Quote 0
        • Y
          Yoshi @paul53 last edited by

          @paul53
          ok, das habe ich schon beim suchen irgendwo gelesen.
          Aber bei mir scheitert es gerade dabei, wo ich genau das eintragen muss ?

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

            @yoshi sagte: wo ich genau das eintragen muss ?

            Das ist ein Javascript. Der Datenpunkt mit dem JSON ist der Trigger und die neuen Datenpunkte vom Typ "Zahl" erstellt man vorher unter "0_userdata.0".

            1 Reply Last reply Reply Quote 0
            • M
              MCU @Yoshi last edited by MCU

              @yoshi So?
              e0b86331-3b93-4b03-b4e7-2d29f2341745-image.png

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

                @mcu sagte: So?
                Oder so (nur einige Datenpunkte):

                Bild_2022-06-01_161019032.png

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

                  @paul53

                  Hab nun diese Skript laufen.

                  on(idJson, function(mqtt.0.Seplos.SEPLOS_dfc47.AllJsonData) {
                  const obj = JSON.parse(dp.state.val);
                  setState(idCellTemp2, obj.Temperatures.CellTemp2, true);
                  });

                  Bildschirmfoto 2022-06-01 um 16.55.35.png

                  Und diesen Datenpunkt erstellt.

                  Aber er kommt mit der Fehlermeldung: und schreibt nichts rein.
                  javascript.0 (8856) script.js.Übergreifendes.Batterie compile failed:
                  at script.js.Übergreifendes.Batterie:1

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

                    @yoshi sagte: Hab nun diese Skript laufen.

                    Korrektur:

                    const idJson = 'mqtt.0.Seplos.SEPLOS_dfc47.AllJsonData';
                    const path = '0_userdata.0.Batterie.'
                    
                    on(idJson, function(dp) {
                        const obj = JSON.parse(dp.state.val);
                        setState(path + 'Temperatures.CellTemp1', obj.Temperatures.CellTemp1, true);
                        setState(path + 'Temperatures.CellTemp2', obj.Temperatures.CellTemp2, true);
                        // usw.
                    });
                    
                    Y 1 Reply Last reply Reply Quote 0
                    • Y
                      Yoshi @paul53 last edited by

                      @paul53

                      Genial, funktioniert.
                      Muss ich für jeden Wert ein eigenes Skript bauen, oder kann ich das irgendwie fortlaufend machen ?

                      Vielen Dank für die schnelle Hilfe

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

                        @yoshi sagte: kann ich das irgendwie fortlaufend machen ?

                        Fortlaufend ein setState() unter dem anderen (habe oben um "CellTemp1" ergänzt).

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

                          @paul53
                          VIELEN DANK!!

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

                            @yoshi
                            Für die 16 Zellenspannungen kann man eine Schleife verwenden:

                                for(let i = 1; i <= 16; i++) {
                                    setState(path + 'CellVoltages.Cell' + i, obj.CellVoltages['Cell' + i], true);
                                }
                            
                            1 Reply Last reply Reply Quote 0
                            • First post
                              Last post

                            Support us

                            ioBroker
                            Community Adapters
                            Donate

                            528
                            Online

                            31.8k
                            Users

                            80.0k
                            Topics

                            1.3m
                            Posts

                            3
                            12
                            490
                            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