Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Visualisierung
    4. Button Bild durch JSON setzen ?

    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

    Button Bild durch JSON setzen ?

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

      Moin !
      Ich würde gerne das Bild eine "Jquery - ctrl - Icon State" Buttons durch einen bestimmten JSON Wert setzen lassen. Mein JSON sieht so aus:

      [{
              "Device": "Comp-L-Acer-L",
              "Profile ID": "filtprof1",
              "Profile Name": "Standard",
              "Usage": "Unbeschränkt",
              "Time": "00:00 von 24:00 Stunden"
          }, {
              "Device": "Comp-L-Acer-W",
              "Profile ID": "filtprof1",
              "Profile Name": "Standard",
              "Usage": "Unbeschränkt",
              "Time": "00:00 von 24:00 Stunden"
          }
      ]
      

      Das Icon soll nach dem Wert von Profile ID gesetzt werden aber für ein bestimmtes Device.

      Konkret der Wert Profile ID bei "Device": "Comp-L-Acer-L" auf filtprof1 steht dann möchte ich BILD1, steht er auf einem anderen Wert, dann eben BILD2.

      Ich weiß das man Bilder über Datenpunkte mittels Bindings direkt setzen kann. Bsp:

      {v:Global.0.Alexa.Selected;v == 'alexa2.0.Echo-Devices.G090XG08945606VC' ? '/icons-mfd-png/control_clear.png' : '/icons-mfd-png/status_light_off.png'}
      

      Nur geht das eben auch mittels JSON Wert ?

      Grüße Dominik

      O OliverIO 2 Replies Last reply Reply Quote 0
      • O
        oliver2017 @moelski last edited by

        @moelski Hast du es hinbekommen? Meine Work around lösung ist ein Script laufen zulassen und entsprechende Datenpunkte zu benutzen, diese dann per Binding verknüpfen!

        Gruß Olli

        1 Reply Last reply Reply Quote 0
        • OliverIO
          OliverIO @moelski last edited by

          Ist zwar schon leicht veraltet, aber das Prinzip wäre so

          {v:Global.0.DatepunktMitJSON;JSON.parse(v)[1]["Profile ID"]}
          

          Durch die erste Anweisung befindet sich der JSON-Text in v
          Durch JSON.parse wird er in ein Objekt umgewandelt.
          Mit den nachfolgenden Anweisungen [1]["Profile ID"]
          wird das 2.Element (Comp-L-Acer-W) aus dem Array mit Objekten selektiert und davon das
          Attribut "Profile ID".
          Theoretisch würde bei Profile ID auch die Punktnotation ([1].ProfileID) gehen, da aber ein Leerzeichen enthalten ist, muss der Zugriff so erfolgen.

          O 1 Reply Last reply Reply Quote 0
          • O
            oliver2017 @OliverIO last edited by

            @oliverio so dachte ich dass auch , aber ich bekomme immer nur eine "0" als Rückgabe!

            An was liegt es?

            OliverIO 1 Reply Last reply Reply Quote 0
            • OliverIO
              OliverIO @oliver2017 last edited by

              @oliver2017
              Dann zeige deine binding Anweisung

              Wie Soll ich das sonst prüfen?

              O 1 Reply Last reply Reply Quote 0
              • O
                oliver2017 @OliverIO last edited by oliver2017

                @oliverio
                verschiedenes Probiert, aber immer nur "0" als Rückgabe wert.

                {v:0_userdata.0.Fritzbox.I-Net-Filter.DeviceFilterListJson;JSON.parse(v)[2]["Device"]}
                {v:0_userdata.0.Fritzbox.I-Net-Filter.DeviceFilterListJson;JSON.parse(v)v["2.Device"]}
                {v:0_userdata.0.Fritzbox.I-Net-Filter.DeviceFilterListJson;vv:JSON.parse(v);vv["2.Device"]}
                

                Datenpunkt: (als Zeichenkette ) auch als JSON probiert

                [
                  {
                    "Device": "3D-Drucker-octopi-1",
                    "Profile ID": "filtprof1",
                    "Profile Name": "Standard",
                    "Usage": "Unbeschränkt",
                    "Time": "Unbegrenzt"
                  },
                  {
                    "Device": "3D-Drucker-octopi-2",
                    "Profile ID": "filtprof1",
                    "Profile Name": "Standard",
                    "Usage": "Unbeschränkt",
                    "Time": "Unbegrenzt"
                  },
                  {
                    "Device": "amazon-22222",
                    "Profile ID": "filtprof1",
                    "Profile Name": "Standard",
                    "Usage": "Unbeschränkt",
                    "Time": "Unbegrenzt"
                  }
                ]
                
                OliverIO 1 Reply Last reply Reply Quote 0
                • OliverIO
                  OliverIO @oliver2017 last edited by

                  @oliver2017

                  hab mal debuged.
                  da ist halt immer noch ein fehler in vis drin.
                  ich hatte mal vor einiger zeit ein Verbesserungsvorschlag gemacht,
                  allerdings ist dieser wieder verhunzt ins vis reingelaufen.
                  so wie es jetzt drin ist kann es leider nicht funktionieren.
                  mich wundert es halt, das nicht noch mehr das problem haben. wohl werten alle das json erst in einem skript aus

                  ich kann dich nur auf mein widget JSON template im adapter rssfeed verweisen
                  https://forum.iobroker.net/topic/31521/test-widget-json-template?_=1651682400120

                  O 1 Reply Last reply Reply Quote 0
                  • O
                    oliver2017 @OliverIO last edited by

                    @oliverio
                    meinst du das?

                    https://github.com/ioBroker/ioBroker.vis/commit/93d4affd0c959b20b1dd384bf239fe7a1c432fb7#r42103805

                    denke auch das da ein fehler ist, denn selbst console.log() funktioniert nicht

                    2 gsicilia82 committed to ioBroker/ioBroker.vis
                    parse JSON for VIS bindings
                    
                    For JSON-bindings in VIS. Contribution from user "oweitman" in ioBroker#263 (comment)
                    
                    `if (typeof value) { ... }` was not usable, I don't know the reason. With typeof-check, also Arrays would be recocnized as Objects and not declared as String.
                    Pull request to accelerate enhancement...
                    OliverIO 1 Reply Last reply Reply Quote 0
                    • OliverIO
                      OliverIO @oliver2017 last edited by OliverIO

                      @oliver2017

                      nicht ganz, aber fast
                      es ist dieser commit
                      https://github.com/ioBroker/ioBroker.vis/commit/fdb636630a452772a6bf798aab7b41e3b80c2d6c

                      hier wird der json-string value als text eingefügt. blöderweise aber von doppelten anführungzeichen eingeschlossen.
                      wenn dann später das generierte javascript ausgeführt wird, kommt es zum fehler.

                      so sieht dein intern generiertes javascript dann aus.

                      var v = JSON.parse("[{" Device ":" 3D - Drucker - octopi - 1 "," Profile ID ":" filtprof1 "," Profile Name ":" Standard "," Usage ":" Unbeschränkt "," Time ":" Unbegrenzt "},{" Device ":" 3D - Drucker - octopi - 2 "," Profile ID ":" filtprof1 "," Profile Name ":" Standard "," Usage ":" Unbeschränkt "," Time ":" Unbegrenzt "},{" Device ":" amazon - 22222 "," Profile ID ":" filtprof1 "," Profile Name ":" Standard "," Usage ":" Unbeschränkt "," Time ":" Unbegrenzt "}]");
                      return v[2]["Device"];
                      

                      evtl entedckst du auch den fehler. da hilft das hinten angehängte replace leider auch nicht mehr. eigentlich konnte das seit diesem commit noch nie funktionieren (ausser bei primitive types)

                      1 GermanBluefox committed to ioBroker/ioBroker.vis
                      * (fceller) parse JSON for VIS bindings
                      OliverIO 1 Reply Last reply Reply Quote 0
                      • OliverIO
                        OliverIO @OliverIO last edited by

                        @oliverio
                        hab das mal nochmal in einen ordentlichen github kommentar verfasst
                        https://github.com/ioBroker/ioBroker.vis/pull/281#issuecomment-1118353907

                        gsicilia82 created this issue in ioBroker/ioBroker.vis

                        closed parse JSON for VIS bindings #281

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

                        Support us

                        ioBroker
                        Community Adapters
                        Donate

                        812
                        Online

                        31.8k
                        Users

                        80.0k
                        Topics

                        1.3m
                        Posts

                        3
                        10
                        505
                        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