NEWS
Gelöst: Wert in dynamische Struktur im ioBroker ablegen
-
@martybr Eckige Klammern sind ein Array oder in Blockly Chargon eine Liste - Ja Du kannst einfach ein Array mit eckigen Klammern daraus machen - macht aber nur Sinn, wenn Du dann mehrere Objekte im Array hast.
Selbstverstöndlich kannst Du ein Objekt in ein Array stellen. Wenn Du aber mehrere Objekte in ein Array machen mächtest, dann nutze die $append Funktion.
Du solltest Dir angewöhnen - nie KLammern zu bezeichen, sondern was für Objekte Du erstellen möchtest.
-
@mickym
Okay. das ist mein Ziel. Ich möchte Tageswerte in ein Monatsarray speichern. Das mit den Klammern hat funktioniert.
Über Arrays muss ich mich erst kundig machen.Ziel ist, um 00:00 Uhr generierte Werte in ein Monatsarray zu speichern.
Ich bereite mal einen Versuch vor.
-
-
@mickym
das Array wird nach meinem Test nicht aufgefüllt, es bleibt immer nur ein Wert im Array.
Die $append scheint nicht zu wirken.[ { "id": "a0d8740faea1647b", "type": "mqtt in", "z": "5c488c180ba51f18", "name": "ZuluftTemp", "topic": "vitocal/ZuluftTemp", "qos": "0", "datatype": "auto-detect", "broker": "bf311140.13d2b8", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 140, "y": 260, "wires": [ [ "afdcb37ccbacb06f" ] ] }, { "id": "afdcb37ccbacb06f", "type": "change", "z": "5c488c180ba51f18", "name": "Zuluft", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "zuluft", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 290, "y": 320, "wires": [ [ "1643873aeecd8613" ] ] }, { "id": "1643873aeecd8613", "type": "change", "z": "5c488c180ba51f18", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array", "pt": "msg", "to": "[]", "tot": "json" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 490, "y": 280, "wires": [ [ "c9d97aec2949301c", "34c8064e4b5c52fa" ] ] }, { "id": "34c8064e4b5c52fa", "type": "change", "z": "5c488c180ba51f18", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array, payload)", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 610, "y": 340, "wires": [ [ "5b551b24fc1bb26e" ] ] }, { "id": "5b551b24fc1bb26e", "type": "debug", "z": "5c488c180ba51f18", "name": "debug 179", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 750, "y": 280, "wires": [] }, { "id": "c9d97aec2949301c", "type": "debug", "z": "5c488c180ba51f18", "name": "debug 178", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 710, "y": 160, "wires": [] }, { "id": "bf311140.13d2b8", "type": "mqtt-broker", "name": "Mosquito-Server", "broker": "192.168.178.10", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "compatmode": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" } ]
Was mache ich falsch?
Edit:
Als Ziel benötige ich für die 4 Werte jeweils ein Array mit[
Wert1,
Wert2,
Wert3,...
Wert28
]Anzahl der Werte entspricht der Zahl der Tage im laufenden Monat.
-
@martybr Na Du mergst ein leeres Array mit einem skalaren Wert. Dann ist es doch richtig, dass nur ein Wert in dem Array ist. Du musst das Array ja speichern und dann den nächsten Wert anhängen.
So hängst Du doch immer wieder nur EIN Wert an ein leeres Array. Du musst doch das Array irgendwo abspeichern und dann das neu erstellte Array mit einem neuen Wert ergänzen.
Also überleg Dir wohin Du Dein Array Ergebnis des Anhänges abspeichern willst. In einer Variable oder in einem Datenpunkt.
Oder mit anderen Worten: Ein Wert an ein leeres Array angehängt, gibt immer nur ein Array mit einem Wert.
-
@mickym
Okay, das ist ein Ansatzpunkt. Ich mache mir mal Gedanken.
Danke für deine Unterstützung. -
@martybr sagte in Wert in dynamische Struktur im ioBroker ablegen:
@mickym
Okay, das ist ein Ansatzpunkt. Ich mache mir mal Gedanken.
Danke für deine Unterstützung.Ich habs Dir mal mit eine Flowvariable gemacht. Das heißt das Ergebnis wird in eine Variable gespeichert und dann wieder eingelesen und der neue Wert angehängt.
-
@mickym
Der Flow funktioniert.
Ich habe eine Objektveriable in ioBroker.[ { "id": "a0d8740faea1647b", "type": "mqtt in", "z": "7e6af0015415146d", "d": true, "name": "ZuluftTemp", "topic": "vitocal/ZuluftTemp", "qos": "0", "datatype": "auto-detect", "broker": "bf311140.13d2b8", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 260, "y": 6740, "wires": [ [ "afdcb37ccbacb06f" ] ] }, { "id": "afdcb37ccbacb06f", "type": "change", "z": "7e6af0015415146d", "name": "Zuluft", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "zuluft", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 410, "y": 6800, "wires": [ [ "1643873aeecd8613" ] ] }, { "id": "1643873aeecd8613", "type": "change", "z": "7e6af0015415146d", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array", "pt": "msg", "to": "array", "tot": "flow" }, { "t": "set", "p": "array", "pt": "msg", "to": "array ? array : []", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 610, "y": 6760, "wires": [ [ "c9d97aec2949301c", "34c8064e4b5c52fa" ] ] }, { "id": "34c8064e4b5c52fa", "type": "change", "z": "7e6af0015415146d", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array, payload)", "tot": "jsonata" }, { "t": "set", "p": "array", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 850, "y": 6760, "wires": [ [ "5b551b24fc1bb26e" ] ] }, { "id": "5b551b24fc1bb26e", "type": "debug", "z": "7e6af0015415146d", "name": "debug 179", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1070, "y": 6740, "wires": [] }, { "id": "c9d97aec2949301c", "type": "debug", "z": "7e6af0015415146d", "name": "debug 178", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 830, "y": 6640, "wires": [] }, { "id": "7961970716d0df25", "type": "inject", "z": "7e6af0015415146d", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "20.2", "payloadType": "num", "x": 230, "y": 6800, "wires": [ [ "afdcb37ccbacb06f" ] ] }, { "id": "bf311140.13d2b8", "type": "mqtt-broker", "name": "Mosquito-Server", "broker": "192.168.178.10", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "compatmode": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" } ]
Wie kann ich das Array persistent ablegen?
-
Wie kann ich das Array persistent ablegen?
Datenpunkt im iobroker oder im mqtt - wo immer Du willst.
-
@mickym
Ich habe das mal so gemacht:
[ { "id": "99d066d4bbe5dca9", "type": "inject", "z": "5c488c180ba51f18", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "20.2", "payloadType": "num", "x": 350, "y": 700, "wires": [ [ "994a1a0b6d25cef4" ] ] }, { "id": "82d5f1b2aa875c35", "type": "mqtt in", "z": "5c488c180ba51f18", "name": "ZuluftTemp", "topic": "vitocal/ZuluftTemp", "qos": "0", "datatype": "auto-detect", "broker": "bf311140.13d2b8", "nl": false, "rap": true, "rh": 0, "inputs": 0, "x": 420, "y": 620, "wires": [ [ "994a1a0b6d25cef4" ] ] }, { "id": "994a1a0b6d25cef4", "type": "change", "z": "5c488c180ba51f18", "name": "Zuluft", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "zuluft", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 530, "y": 700, "wires": [ [ "4a49f7b7cb1d35d2" ] ] }, { "id": "de7a183e542f367e", "type": "ioBroker get object", "z": "5c488c180ba51f18", "name": "Test.Test-JSON", "topic": "0_userdata.0.Test.Test-JSON", "attrname": "array", "x": 620, "y": 580, "wires": [ [] ] }, { "id": "4a49f7b7cb1d35d2", "type": "change", "z": "5c488c180ba51f18", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array", "pt": "msg", "to": "array", "tot": "flow" }, { "t": "set", "p": "array", "pt": "msg", "to": "array ? array : []", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 730, "y": 660, "wires": [ [ "1bf56806da8b2399", "40df7a89751f5b92" ] ] }, { "id": "40df7a89751f5b92", "type": "change", "z": "5c488c180ba51f18", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array, payload)", "tot": "jsonata" }, { "t": "set", "p": "array", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 830, "y": 740, "wires": [ [ "cb026a3b7a51d987", "8d9b65f4efb22698" ] ] }, { "id": "cb026a3b7a51d987", "type": "debug", "z": "5c488c180ba51f18", "name": "debug 179", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 890, "y": 800, "wires": [] }, { "id": "8d9b65f4efb22698", "type": "ioBroker out", "z": "5c488c180ba51f18", "name": "Test.Test-JSON", "topic": "0_userdata.0.Test.Test-JSON", "ack": "true", "autoCreate": "false", "stateName": "", "role": "", "payloadType": "", "readonly": "", "stateUnit": "", "stateMin": "", "stateMax": "", "x": 1000, "y": 660, "wires": [] }, { "id": "1bf56806da8b2399", "type": "debug", "z": "5c488c180ba51f18", "name": "debug 178", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 950, "y": 540, "wires": [] }, { "id": "bf311140.13d2b8", "type": "mqtt-broker", "name": "Mosquito-Server", "broker": "192.168.178.10", "port": "1883", "clientid": "", "autoConnect": true, "usetls": false, "compatmode": false, "protocolVersion": "4", "keepalive": "60", "cleansession": true, "autoUnsubscribe": true, "birthTopic": "", "birthQos": "0", "birthPayload": "", "birthMsg": {}, "closeTopic": "", "closeQos": "0", "closePayload": "", "closeMsg": {}, "willTopic": "", "willQos": "0", "willPayload": "", "willMsg": {}, "userProps": "", "sessionExpiry": "" } ]
Die Werte kommen auch richtig im Datenpunkt an.
Jetzt noch eine letzte Frage für Heute
Der Flow soll einen Monat laufen. Wenn nun ein Neustart vom ioBroker erfolgt, muss der Flow am letzten Datensatz wieder aufsetzen. Muss der daher nicht den letzten Stand aus dem Speicherdatenpunkt wieder einlesen?
Edit:
Ich habe im Flow eine ioBroker-getObject. Die ist wahrscheinlich falsch. Richtig? -
@martybr sagte in Wert in dynamische Struktur im ioBroker ablegen:
Der Flow soll einen Monat laufen. Wenn nun ein Neustart vom ioBroker erfolgt, muss der Flow am letzten Datensatz wieder aufsetzen. Muss der daher nicht den letzten Stand aus dem Speicherdatenpunkt wieder einlesen?
Nein Du willst kein Objekt, sondern entweder über iobroker- in oder get. Dann brauchst Du aber hinten nicht in eine flow Variable speichern - sondern die Flowvariable direkt über die iobroker-In füllen.
-
@mickym
Ich habe es noch nicht so ganz verstanden. Ich habe es nun so gebaut, wie ich es verstanden habe. Exemplarisch für zwei Flows / Arrays:[ { "id": "5bbdcd58332d0b96", "type": "ioBroker in", "z": "5c488c180ba51f18", "name": "Bezug täglich", "attrname": "payload", "topic": "0_userdata.0.Zaehler.Strombezug.Verbrauch.täglich", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "fireOnStart": "true", "outFormat": "MQTT", "x": 110, "y": 40, "wires": [ [ "53d6131492b2abed" ] ] }, { "id": "4bb406f8dd2161dd", "type": "ioBroker in", "z": "5c488c180ba51f18", "name": "Einspeisung täglich", "attrname": "payload", "topic": "0_userdata.0.Zaehler.Stromeinspeisung.Verbrauch.täglich", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "fireOnStart": "true", "outFormat": "MQTT", "x": 130, "y": 120, "wires": [ [ "c4e24a8d35d070ae" ] ] }, { "id": "c4e24a8d35d070ae", "type": "change", "z": "5c488c180ba51f18", "name": "Einspeisung", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "einspeisung", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 330, "y": 120, "wires": [ [ "278bac26e6737147" ] ] }, { "id": "53d6131492b2abed", "type": "change", "z": "5c488c180ba51f18", "name": "Bezug", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "bezug", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 270, "y": 40, "wires": [ [ "c617a78f8ddaca22" ] ] }, { "id": "c617a78f8ddaca22", "type": "change", "z": "5c488c180ba51f18", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array-bezug", "pt": "msg", "to": "array-bezug", "tot": "flow" }, { "t": "set", "p": "array-bezug", "pt": "msg", "to": "array-bezug ? array-bezug : []", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 450, "y": 40, "wires": [ [ "ff519a511afeb6f1" ] ] }, { "id": "ff519a511afeb6f1", "type": "change", "z": "5c488c180ba51f18", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array-bezug, payload)", "tot": "jsonata" }, { "t": "set", "p": "array-bezug", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 40, "wires": [ [ "3274ac485bf96d56" ] ] }, { "id": "3274ac485bf96d56", "type": "ioBroker out", "z": "5c488c180ba51f18", "name": "Test.Bezug-JSON", "topic": "0_userdata.0.Test.Bezug-JSON", "ack": "true", "autoCreate": "true", "stateName": "", "role": "", "payloadType": "", "readonly": "false", "stateUnit": "", "stateMin": "", "stateMax": "", "x": 890, "y": 40, "wires": [] }, { "id": "278bac26e6737147", "type": "change", "z": "5c488c180ba51f18", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array-einspeisung", "pt": "msg", "to": "array-einspeisung", "tot": "flow" }, { "t": "set", "p": "array-einspeisung", "pt": "msg", "to": "array-einspeisung ? array-einspeisung : []", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 530, "y": 120, "wires": [ [ "27eb027a108b6b2a" ] ] }, { "id": "27eb027a108b6b2a", "type": "change", "z": "5c488c180ba51f18", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array-einspeisung, payload)", "tot": "jsonata" }, { "t": "set", "p": "array-einspeisung", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 750, "y": 120, "wires": [ [ "8c3a9cbe90f64091" ] ] }, { "id": "8c3a9cbe90f64091", "type": "ioBroker out", "z": "5c488c180ba51f18", "name": "Test.Einspeisung-JSON", "topic": "0_userdata.0.Test.Einspeisung-JSON", "ack": "true", "autoCreate": "true", "stateName": "", "role": "", "payloadType": "", "readonly": "false", "stateUnit": "", "stateMin": "", "stateMax": "", "x": 990, "y": 120, "wires": [] } ]
Die Daten aktualisieren sich täglich. Wenn das in Ordnung ist, dann gehe ich an die Zeitsteuerung.
-
@mickym
Ich habe hier noch ein Problem, die Zahl der Tage im Monat in eine globale Variable zu schreiben. Statt der 28 Tage aus der Funktion liefert mir der Change Node nur payload == 5[ { "id": "f6ed836d74798c7f", "type": "inject", "z": "3ebdbbcf49e0ac40", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 100, "y": 400, "wires": [ [ "a3434007e702fcdc" ] ] }, { "id": "7a09df47bef16411", "type": "function", "z": "3ebdbbcf49e0ac40", "name": "function 1", "func": "// Eingabe: msg.payload sollte ein Datum im Format 'YYYY-MM-DD' sein\nlet inputDate = new Date(msg.payload);\n\n// Hole den Monat und das Jahr\nlet month = inputDate.getMonth(); // 0-11\nlet year = inputDate.getFullYear();\n\n// Berechne die Anzahl der Tage im Monat\nlet daysInMonth = new Date(year, month + 1, 0).getDate();\n\n// Setze das Ergebnis in msg.payload\nmsg.payload = daysInMonth;\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 480, "y": 400, "wires": [ [ "599b66169127c12d", "185c42081279a5e0" ] ] }, { "id": "a3434007e702fcdc", "type": "change", "z": "3ebdbbcf49e0ac40", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$moment().locale('de').format('YYYY.MM.DD')", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 290, "y": 400, "wires": [ [ "7a09df47bef16411" ] ] }, { "id": "d8d647f4ae028cb8", "type": "debug", "z": "3ebdbbcf49e0ac40", "name": "debug 182", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 670, "y": 320, "wires": [] }, { "id": "599b66169127c12d", "type": "change", "z": "3ebdbbcf49e0ac40", "name": "Monatstage", "rules": [ { "t": "move", "p": "payload", "pt": "msg", "to": "monatstage", "tot": "global" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 650, "y": 400, "wires": [ [ "d8d647f4ae028cb8" ] ] }, { "id": "185c42081279a5e0", "type": "debug", "z": "3ebdbbcf49e0ac40", "name": "debug 183", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 590, "y": 480, "wires": [] } ]
-
@mickym
Ich glaube, dass ich das Problem gelöst habe:[ { "id": "f6ed836d74798c7f", "type": "inject", "z": "3ebdbbcf49e0ac40", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 100, "y": 400, "wires": [ [ "a3434007e702fcdc" ] ] }, { "id": "7a09df47bef16411", "type": "function", "z": "3ebdbbcf49e0ac40", "name": "function 1", "func": "// Eingabe: msg.payload sollte ein Datum im Format 'YYYY-MM-DD' sein\nlet inputDate = new Date(msg.payload);\n\n// Hole den Monat und das Jahr\nlet month = inputDate.getMonth(); // 0-11\nlet year = inputDate.getFullYear();\n\n// Berechne die Anzahl der Tage im Monat\nlet daysInMonth = new Date(year, month + 1, 0).getDate();\n\n// Setze das Ergebnis in msg.payload\nmsg.payload = daysInMonth;\n\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 480, "y": 400, "wires": [ [ "599b66169127c12d" ] ] }, { "id": "a3434007e702fcdc", "type": "change", "z": "3ebdbbcf49e0ac40", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$moment().locale('de').format('YYYY.MM.DD')", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 290, "y": 400, "wires": [ [ "7a09df47bef16411" ] ] }, { "id": "d8d647f4ae028cb8", "type": "debug", "z": "3ebdbbcf49e0ac40", "name": "debug 182", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 650, "y": 340, "wires": [] }, { "id": "599b66169127c12d", "type": "change", "z": "3ebdbbcf49e0ac40", "name": "Monatstage", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "monatstage", "tot": "global" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 650, "y": 400, "wires": [ [ "d8d647f4ae028cb8" ] ] }, { "id": "185c42081279a5e0", "type": "debug", "z": "3ebdbbcf49e0ac40", "name": "debug 183", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 450, "y": 460, "wires": [] }, { "id": "5f695a4b2b007db0", "type": "change", "z": "3ebdbbcf49e0ac40", "name": "Monatstage", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "monatstage", "tot": "global" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 270, "y": 460, "wires": [ [ "185c42081279a5e0" ] ] }, { "id": "0191af1c60e06008", "type": "inject", "z": "3ebdbbcf49e0ac40", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 100, "y": 460, "wires": [ [ "5f695a4b2b007db0" ] ] } ]
Kannst du bitte mal darüber schauen?
-
@mickym
Ich habe hier noch einen Fehler im Flow. Ich habe nun die dynamische Datumsablage hinzugefügt und den iobroker out entsprechend geändert. Der Datenpunkt wird auch angelegt, aber als "number" und nicht als Array (mit [Wert1, Wert2,...].[ { "id": "ae673cf6cd8433a0", "type": "subflow", "name": "Datum in Topic", "info": "", "category": "", "in": [ { "x": 60, "y": 80, "wires": [ { "id": "2e1ea06b2e94bf1a" } ] } ], "out": [ { "x": 820, "y": 80, "wires": [ { "id": "fc37f5f9d2b0297b", "port": 0 } ] } ], "env": [ { "name": "basePath", "type": "str", "value": "Test1.Test2" } ], "meta": {}, "color": "#DDAA99" }, { "id": "2e1ea06b2e94bf1a", "type": "change", "z": "ae673cf6cd8433a0", "name": "", "rules": [ { "t": "set", "p": "datum", "pt": "msg", "to": "$moment().locale('de').format('YYYY.MMMM')", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 230, "y": 80, "wires": [ [ "0e8de9437c3c420a" ] ] }, { "id": "0e8de9437c3c420a", "type": "change", "z": "ae673cf6cd8433a0", "name": "März zu Maerz", "rules": [ { "t": "change", "p": "datum", "pt": "msg", "from": "März", "fromt": "str", "to": "Maerz", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 440, "y": 80, "wires": [ [ "fc37f5f9d2b0297b" ] ] }, { "id": "fc37f5f9d2b0297b", "type": "change", "z": "ae673cf6cd8433a0", "name": "", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "\"0_userdata.0.\" & $env(\"basePath\") & \".\" & datum & \".\" & topic", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 660, "y": 80, "wires": [ [] ] }, { "id": "1d93ae2f970605e5", "type": "debug", "z": "5c488c180ba51f18", "name": "debug 184", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 1050, "y": 180, "wires": [] }, { "id": "e700e5e9b292c820", "type": "ioBroker out", "z": "5c488c180ba51f18", "name": "", "topic": "", "ack": "true", "autoCreate": "true", "stateName": "", "role": "", "payloadType": "", "readonly": "false", "stateUnit": "", "stateMin": "", "stateMax": "", "x": 1060, "y": 120, "wires": [] }, { "id": "5e8ce599dad4fa74", "type": "subflow:ae673cf6cd8433a0", "z": "5c488c180ba51f18", "name": "", "env": [ { "name": "basePath", "value": "Test1.Test5.MonatsTabellen", "type": "str" } ], "x": 860, "y": 40, "wires": [ [ "e700e5e9b292c820", "1d93ae2f970605e5" ] ] }, { "id": "ff519a511afeb6f1", "type": "change", "z": "5c488c180ba51f18", "name": "", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$append(array-bezug, payload)", "tot": "jsonata" }, { "t": "set", "p": "array-bezug", "pt": "flow", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 670, "y": 40, "wires": [ [ "5e8ce599dad4fa74" ] ] }, { "id": "c617a78f8ddaca22", "type": "change", "z": "5c488c180ba51f18", "name": "Vorhandenes Array", "rules": [ { "t": "set", "p": "array-bezug", "pt": "msg", "to": "array-bezug", "tot": "flow" }, { "t": "set", "p": "array-bezug", "pt": "msg", "to": "array-bezug ? array-bezug : []", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 450, "y": 40, "wires": [ [ "ff519a511afeb6f1" ] ] }, { "id": "53d6131492b2abed", "type": "change", "z": "5c488c180ba51f18", "name": "Bezug", "rules": [ { "t": "set", "p": "topic", "pt": "msg", "to": "Strombezug", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 270, "y": 40, "wires": [ [ "c617a78f8ddaca22" ] ] }, { "id": "5bbdcd58332d0b96", "type": "ioBroker in", "z": "5c488c180ba51f18", "name": "Bezug täglich", "attrname": "payload", "topic": "0_userdata.0.Zaehler.Strombezug.Verbrauch.täglich", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "fireOnStart": "true", "outFormat": "MQTT", "x": 110, "y": 40, "wires": [ [ "53d6131492b2abed" ] ] } ]
-
@martybr Also - ich habe nun gerade Deinen Flow importiert. Wäre übrigens auch gut, wenn Du mir eine Inject Node zur Simulation dran machen würdest, da ich ja in der Regel nicht deine Datenpunkte habe.
Dann machst Du einen gravierenden Fehler, wenn Du in JSONATA meinst, du kannst "array-bezug" schreiben. Dann versucht JSONATA von einer Nachrichteneigenschaft "array" den Betrag der Nachrichteneigenschaft "bezug" zu subtrahieren, was natürlich beides nicht definiert bzw. exisitiert.
Ich habe also in Deinem ganzen Flow - "array-bezug" durch "array_bezug" ersetzt.Dann haben wir doch besprochen, dass der iobroker KEINE Objekte bearbeiten kann. Also müssen wir bevor wir einen Datenpunkt beschreiben, diesen erst in einen String umwandeln.
Also lösche Deinen Datenpunkt nochmals und setze eine JSON Node vor die iobroker-Out Node, so wie besprochen.
Und zuletzt - speicherst Du zwar direkt in die Flow variable - aber Du wolltest doch persistent machen und Du liest ja nirgend Dein Array aus dem iobroker wieder ein?
Also hören wir doch mal auf, das Ergebnis - also das neue Array direkt abzuspeichern:
So nun muss man also wieder was aus dem Datenpunkt einlesen, den man in iobroker geschrieben hat. das ist aber kompliziert, da der Datenpunkt ja dynamisch sich dauernd ändert. Ich überlege mir mal was.
Inzwischen kannst Du Dir ja den modifizierten Flow - als Basis schon mal abspeichern - dann auf der Basis machen wir weiter.
=============================================================
Ich denke, ich muss den ganzen Flow etwas umstellen, damit es auch einigermaßen effizient wird. Also vergiß Deinen/Meinen bisherigen Flow.
-
@mickym
Konntest du dir den Flow zur Monatslänge (von 9:48 Uhr) mal anschauen? Ich habe da eine globale Variable "Monatstage" definiert. -
@martybr Warum das nun wieder - ich habe den Flow nun fertig und wenn der Monat wechselt wird automatisch ein neuer Datenpunkt durch Deinen Subflow angelegt und auch eingelesen.
Nein Sorry - Du hast Recht, wenn sich das Topic ändert, dann muss die Flowvariable noch gelöscht werden. Habe ich vergessen.
-
@mickym
Vielleicht irre ich mich auch. Ich habe von einem lieben Bekannten ein JavaScript, welches über die Werte iteriert. Hier werden die Zahl der Tage im Monat benötigt. Ich versuche hier mit deiner Hilfe Node-Red zu verstehen, da mich Javascript nicht angesprochen hat. Da gibt es mit async etc. genügend Fallstricke.
Daher kommen manche meiner Fragen, die für die bestimmt selbstverständlich sind. Ich fange ja gerade erst mit Node-Red an. Das Buch das ich mir gekauft habe war nicht so toll.
Einges habe ich schon in Node-Red umsetzen können:
Meine Bewegungsmelder mit Zeitsteuerung und Sperre bei manuellem Auslösen und mit deiner Hilfe die Speicherung von Strombezug und Einspeisung.
Ich konnte mit den Flows das ganze und weitere Anwendungen umsetzen, z.B. Wasserverbrauch, Gartenwasser, Solareinspeisung. Dadurch habe ich das Potential von Node-Red erkannt. Nun habe ich Zeit und versuche mich tiefer einzuarbeiten -
@martybr Ja ich schau mir das gleich an -
Aber zu deinem Flow mit den dynamischen Monatsarrays habe ich eine andere Lösung, da brauchst du die Zahl nicht. Sprich wenn sich das topic ändert, dann wird die bisherige flow Variable gelöscht und eine neue erstellt. Schau Dir erst mal den neuen Flow an:
und schau, ob Du den verstehst. Ansonsten schaun ich mir Deinen Flow gerne an - aber ich verstehe immer nicht, warum mit JS in NodeRed arbeitet - ich rate Dir immer, die function Nodes wenn möglich immer zu meiden. Für Deine dynamischen Datenpunkte solltest Du es nicht brauchen. Ich habe übrigens mal einen Flow gemacht, den Du Dir auch mal anschauen solltest.