Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Werte aus JSON in Alias-DP zerlegen

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Werte aus JSON in Alias-DP zerlegen

    This topic has been deleted. Only users with topic management privileges can see it.
    • haus-automatisierung
      haus-automatisierung Developer Most Active @wolfi913 last edited by haus-automatisierung

      @wolfi913 sagte in Werte aus JSON in Alias-DP zerlegen:

      muss werde mal abchecken, ob das JSON immer in der gleichen Reihenfolge kommt

      Ansonsten könnte man auch mit .find(...) den entsprechenden Eintrag aus dem Array suchen. z.B.

      parseFloat(JSON.parse(val).find(e => e.name === 'modbus_sunspec_fronius_inverter_12345678_harmonized_power_out').state.split('|').pop())
      

      oder dein ursprünglicher Ansatz auf den link:

      parseFloat(JSON.parse(val).find(e => e.link === 'http://192.168.4.201/rest/items/modbus_sunspec_fronius_inverter_12345678_harmonized_power_out').state.split('|').pop())
      
      W 1 Reply Last reply Reply Quote 0
      • W
        wolfi913 @haus-automatisierung last edited by

        @haus-automatisierung
        Funktioniert 👍
        Die erste Variante find ich besser falls sich aus unerfindlichen Gründen mal die IP ändern sollte. Dann müssten da ja die Alias-DP nicht mehr geändert werden.
        @paul53
        Der Ansatz wäre grundsätzlich nicht schlecht. Leider sind aber teilweise die Werte bei label doppelt vorhanden.

        Vielen Dank für Eure Hilfe

        L 1 Reply Last reply Reply Quote 1
        • L
          Laser @wolfi913 last edited by Laser

          @haus-automatisierung
          Habe einen einfachen Fall: ich möchte erkennen, ob dieser Eintrag (connection lost) vorhanden ist und das auf irgendeine Art im Alias Datenpunkt darstellen.
          So geht es schon mal nicht: JSON.parse(val)."message" oder JSON.parse(val)."connection lost" oder JSON.parse(message).connection lost
          Json:

              "date": "Heute 11:42",
              "severity": "<span class='logError logSeverity'>error</span>",
              "from": "vedirect.0",
              "message": "[2 Einträge] No data received for 10 seconds, connection lost ?",
              "ts": 1714124548068
          
          paul53 1 Reply Last reply Reply Quote 0
          • paul53
            paul53 @Laser last edited by paul53

            @laser
            Typ: "boolean"

            JSON.parse(val).message.includes('connection lost')
            
            L 1 Reply Last reply Reply Quote 2
            • L
              Laser @paul53 last edited by Laser

              @paul53 sagte in Werte aus JSON in Alias-DP zerlegen:

              JSON.parse(val).message.includes('connection lost')

              Als Wert steht immer nur "null" da

              Habe den Alias noch mal komplett gelöscht und neu angelegt. Jetzt sieht der Inhalt so aus (?)
              Da muß ich noch etwas probieren, bis das klappt...

              {
                "type": "state",
                "common": {
                  "name": "JSON",
                  "role": "json",
                  "type": "boolean",
                  "read": true,
                  "write": false,
                  "alias": {
                    "id": "logparser.0.filters.vedirect.json",
                    "read": "JSON.parse(val).message.includes('connection lost')"
                  }
                },
                "_id": "alias.0.Logparser.json",
                "native": {},
                "acl": {
                  "object": 1638,
                  "state": 1638,
                  "owner": "system.user.admin",
                  "ownerGroup": "system.group.administrator"
                },
                "from": "system.adapter.admin.1",
                "user": "system.user.admin",
                "ts": 1714127601731
              
              paul53 2 Replies Last reply Reply Quote 0
              • paul53
                paul53 @Laser last edited by

                @laser
                Ändere besser Zeilen 4 und 5:

                    "name": "Connection lost",
                    "role": "indicator",
                
                1 Reply Last reply Reply Quote 1
                • paul53
                  paul53 @Laser last edited by paul53

                  @laser sagte: Als Wert steht immer nur "null" da
                  Das JSON sieht so aus?

                  {
                      "date": "Heute 11:42",
                      "severity": "<span class='logError logSeverity'>error</span>",
                      "from": "vedirect.0",
                      "message": "[2 Einträge] No data received for 10 seconds, connection lost ?",
                      "ts": 1714124548068
                  }
                  
                  L 1 Reply Last reply Reply Quote 0
                  • L
                    Laser @paul53 last edited by Laser

                    @paul53 Das JSON:

                    [
                      {
                        "date": "Heute 12:42",
                        "severity": "<span class='logError logSeverity'>error</span>",
                        "from": "vedirect.0",
                        "message": "[10 Einträge] No data received for 10 seconds, connection lost ?",
                        "ts": 1714128144018
                      },
                      {
                        "date": "Heute 11:51",
                        "severity": "<span class='logError logSeverity'>error</span>",
                        "from": "sourceanalytix.0",
                        "message": "[calculationHandler] reading incorrect after conversion contact DEV and provide these info | Reading",
                        "ts": 1714125078042
                      }
                    ]
                    
                    paul53 1 Reply Last reply Reply Quote 0
                    • paul53
                      paul53 @Laser last edited by

                      @laser sagte: Das JSON:

                      Das ist ein Array. Lesekonvertierung:

                      JSON.parse(val)[0].message.includes('connection lost')
                      
                      L 1 Reply Last reply Reply Quote 1
                      • L
                        Laser @paul53 last edited by Laser

                        @paul53 Ich hatte gehofft, mit dem Logparser komfortabel bestimme Fehlermeldungen des VE-Adapters im Log detektieren zu können.
                        Das generierte JSON dann auf die Fehlermeldung durchsuchen. Mit Hilfe eines Alias. Das wird aber einfach nichts!

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        1.1k
                        Online

                        31.7k
                        Users

                        79.7k
                        Topics

                        1.3m
                        Posts

                        4
                        14
                        604
                        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