NEWS
Gelöst: Sein oder nicht sein, öhm Json oder nicht ;-)
-
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
-
@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.
-
Soweit mir bekannt ist wird ein Json mit
JSON.stringify
in einen State geschrieben mitcommon.type = 'string', common.role = 'json'
https://github.com/ioBroker/ioBroker.docs/blob/master/docs/en/dev/stateroles.md#common
-
@ticaki sagte: common.type = 'string', common.role = 'json'
Ja, aber offenbar ist der Datenpunkt vom Typ "object" (vom Adapter so vorgegeben?).
-
@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.
-
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 -
@mendikant Ändere halt einfach den Datenpunkt auf string oder json und nutze stringify. Ich schreibe Objekte auch immer als string in Datenpunkte.
-
@mickym Danke, so geht es. Auf die Idee hätte ich kommen können....