Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. JavaScript
    5. Gelöst: Sein oder nicht sein, öhm Json oder nicht ;-)

    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

    Gelöst: Sein oder nicht sein, öhm Json oder nicht ;-)

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

      Ich möchte einen Datenpunkt für meine Viessmann Heizung setzen. Die Viessmann Api erwartet an der Stelle ein JSON-Object.
      Nennt man das so?

      Im Folgenden mein Testaufbau. die var Temp_Diff ziehe ich mir natürlich produktiv aus einer Rechnung.

      var Temp_Diff = 2
      const Kurve = {"slope":0.4,"shift":Temp_Diff};
      const KKurve = JSON.stringify(Kurve);
      setState("viessmannapi.0.XXXXXX.0.features.heating.circuits.0.heating.curve.commands.setCurve.setValue",KKurve);
      

      Wenn ich "Kurve" in den Setstate schreibe, bekomme ich von der Api zurück, dass ich bitte einen json setzen soll.
      Bei KKurve meckert die API nicht, offensichtlich ist es also ein JSON geworden.

      ABER: Das Logfile vom Iobroker Javascript sagt mir dann:
      You are assigning a string to the state "viessmannapi.0.XXXXXXX.0.features.heating.circuits.0.heating.curve.commands.setCurve.setValue" which expects a object. Please fix your code to use a object or change the state type to string. This warning might become an error in future versions.

      Ist das jetzt nen String oder nicht? Muss ich da für die Zukunft was beachten?

      Danke und Gruß

      Mendikant

      paul53 T 3 Replies Last reply Reply Quote 0
      • paul53
        paul53 @mendikant last edited by paul53

        @mendikant sagte: Please fix your code to use a object

        Lass JSON.stringify() weg. Der Javascript-Adapter wandelt es selbst in ein JSON, wenn der Datenpunkt vom Typ "object" ist.

        1 Reply Last reply Reply Quote 0
        • T
          ticaki Developer @mendikant last edited by ticaki

          @mendikant

          Soweit mir bekannt ist wird ein Json mit JSON.stringify in einen State geschrieben mit common.type = 'string', common.role = 'json'

          https://github.com/ioBroker/ioBroker.docs/blob/master/docs/en/dev/stateroles.md#common

          paul53 1 Reply Last reply Reply Quote 1
          • paul53
            paul53 @ticaki last edited by paul53

            @ticaki sagte: common.type = 'string', common.role = 'json'

            Ja, aber offenbar ist der Datenpunkt vom Typ "object" (vom Adapter so vorgegeben?).

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

              @mendikant sagte: bekomme ich von der Api zurück, dass ich bitte einen json setzen soll.

              Dann ist es ein Fehler des Adapters, denn im Datenpunkt steht ein JSON.

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

                @paul53

                wie geschrieben: Ohne den Stringify meckert die Api:

                viessmannapi.0   2023-09-28 13:23:32.950	  info	Please use a valid JSON: {"slope": x, "shift": y}
                viessmannapi.0  2023-09-28 13:23:32.949	  error	SyntaxError: Unexpected token o in JSON at position 1
                

                Mit Stringify meckert der JS Adapter, aber die API nimmt die Werte an.

                javascript.02023-09-28 13:25:40.970	warn	You are assigning a string to the state "viessmannapi.0.XXXXXX.0.features.heating.circuits.0.heating.curve.commands.setCurve.setValue" which expects a object. Please fix your code to use a object or change the state type to string. This warning might become an error in future versions.
                

                Hier nochmal die Eigenschaften des Datenpunktes.

                {
                  "type": "state",
                  "common": {
                    "name": "Einstellungen sind hier änderbar / You can change the settings here",
                    "role": "value",
                    "type": "object",
                    "write": true,
                    "read": true,
                    "param": [
                      {
                        "param": "slope",
                        "type": "number",
                        "min": 0.2,
                        "max": 3.5
                      },
                      {
                        "param": "shift",
                        "type": "number",
                        "min": -13,
                        "max": 40
                      }
                    ]
                  },
                  "native": {},
                  "from": "system.adapter.viessmannapi.0",
                  "user": "system.user.admin",
                  "ts": XXXXXXXX,
                  "_id": "viessmannapi.0.XXXXXXX.0.features.heating.circuits.0.heating.curve.commands.setCurve.setValue",
                  "acl": {
                    "object": 1636,
                    "state": 1636,
                    "file": 1632,
                    "owner": "system.user.admin",
                    "ownerGroup": "system.group.administrator"
                  }
                }
                

                Also Issue beim JS Adapter aufmachen?

                VG
                Mendikant

                mickym 1 Reply Last reply Reply Quote 0
                • mickym
                  mickym Most Active @mendikant last edited by mickym

                  @mendikant Ändere halt einfach den Datenpunkt auf string oder json und nutze stringify. Ich schreibe Objekte auch immer als string in Datenpunkte.

                  af6492ba-d22e-4992-84b2-1fdc216ccbec-image.png

                  M 1 Reply Last reply Reply Quote 0
                  • M
                    mendikant @mickym last edited by

                    @mickym Danke, so geht es. Auf die Idee hätte ich kommen können....

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

                    Support us

                    ioBroker
                    Community Adapters
                    Donate

                    913
                    Online

                    31.8k
                    Users

                    80.0k
                    Topics

                    1.3m
                    Posts

                    4
                    8
                    310
                    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