Flow arbeitet nicht richtig

Hallo, ich bin Walter und rel. neu in der Erstellung von Flow.
Bisher habe ich in C (Arduino) und Visual Basic for Applications programmiert.
Ich habe folgendes Problem:
In meinen Flow (Anhang) möchte ich Werte in eine Datei speichern, um diese später auswerten zu können.
Es funktioniert alles, bis auf die Abspeicherung in die Datei.
Den Dateinamen generiere ich aus den Datum. Wenn die Datei noch nicht existiert, wird diese erstellt. Bis dahin ist alles o.k.
Starte ich den Flow erneut, erhalte ich die Fehlermeldung, dass der Dateiname nicht im File Knoten eingetragen ist.
Es ist mir bisher nicht gelungen, die Eigenschaft <msg.filename> an den Fileknoten zu übergeben.
Wo liegt mein Fehler bzw. wie kann ich den Dateinamen an den File Knoten übergeben.
Vielen Dank für die Hilfe.

{English]
Hello, I'm Walter and rel. new to creating flow.
So far I've programmed in C (Arduino) and Visual Basic for Applications.
I have the following problem:
In my flow (attachment) I would like to save values in a file in order to be able to evaluate them later.
Everything works, except for the saving in the file.
I generate the file name from the date. If the file does not exist yet, it will be created. Until then everything is o.k.
If I start the flow again, I get the error message that the file name is not entered in the file node.
So far I have not been able to transfer the property <msg.filename> to the file node.
Where is my mistake or how can I transfer the file name to the file node.
Many thanks for the help.

Hier mein Flow:

[{"id":"bb0b1c9f.00da8","type":"tab","label":"Waschmaschine Strom sichern","disabled":false,"info":""},{"id":"700153c4.84c8ac","type":"mqtt in","z":"bb0b1c9f.00da8","name":"MQTT Broker lesen","topic":"stat/eg/waschmaschine/strom","qos":"0","datatype":"json","broker":"51dc6a63.563814","nl":false,"rap":false,"x":110,"y":80,"wires":[["f9553e6b.7cd5d","ae9d3e97.d7141","59b15b6c.959004"]]},{"id":"ae9d3e97.d7141","type":"function","z":"bb0b1c9f.00da8","name":"Wert - Strom","func":"wert= msg.payload.wert;\nmsg.payload= wert + ';' + 'mA';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":80,"wires":[["d53586ef.e26758"]]},{"id":"f9553e6b.7cd5d","type":"function","z":"bb0b1c9f.00da8","name":"Erstellung Datei","func":"msg.payload=\"\";\nfunction formatDate(date) {\n    var d = new Date(date),\n        month = '' + (d.getMonth() + 1),\n        day = '' + d.getDate(),\n        year = d.getFullYear();\n\n    if (month.length < 2) month = '0' + month;\n    if (day.length < 2) day = '0' + day;\n\n    return [day, month, year].join('-');\n}\n\nvar tempString =formatDate(Date().toString());\n\nvar tempString1 = \"/media/pi/9A6D-72BD/Waschmaschine/\";\nvar tempString2 = tempString1.concat(tempString);\nvar finalPath = tempString2.concat(\".txt\");\nmsg.filename = finalPath;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":360,"y":20,"wires":[["ad21bcd8.972b9"]]},{"id":"59b15b6c.959004","type":"function","z":"bb0b1c9f.00da8","name":"Zeit","func":"zeit= msg.payload.Zeit;\nmsg.payload= zeit;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":140,"wires":[["34ffbc57.225af4"]]},{"id":"34ffbc57.225af4","type":"function","z":"bb0b1c9f.00da8","name":"timestamp in HH:mm:ss","func":"var dt = new Date(msg.payload);\n\nvar Monat = dt.getMonth() + 1;\nvar Tag = dt.getDate();\nvar Jahr = dt.getFullYear();\nvar Stunde = dt.getHours();\nvar Minute = dt.getMinutes();\nvar Sekunde = dt.getSeconds();\n\nif(Monat.toString().length == 1) {\n  var Monat = '0'+Monat;\n  }\n  \nif(Tag.toString().length == 1) {\n  var Tag = '0'+Tag;\n  }\n  \n if(Stunde.toString().length == 1) {\n   var Stunde = '0'+Stunde;\n   }\n   \n if(Minute.toString().length == 1) {\n    var Minute = '0'+Minute;\n   }\n\n if(Sekunde.toString().length == 1) {\n   var Sekunde = '0'+Sekunde;\n   }\n \nmsg.payload = Stunde + ':' + Minute;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":140,"wires":[["d53586ef.e26758"]]},{"id":"d53586ef.e26758","type":"join","z":"bb0b1c9f.00da8","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":";","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":80,"wires":[["ad21bcd8.972b9"]],"inputLabels":["2"],"outputLabels":["1"]},{"id":"ad21bcd8.972b9","type":"file","z":"bb0b1c9f.00da8","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":630,"y":20,"wires":[[]]},{"id":"f5dfc7e1.4838a8","type":"file function","z":"bb0b1c9f.00da8","name":"","filename":"","reloadfile":true,"outputs":1,"x":300,"y":540,"wires":[[]]},{"id":"51dc6a63.563814","type":"mqtt-broker","name":"","broker":"192.168.2.115","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"stat/eg/waschmaschine/strom","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

Hello @WaRo52 Walter, welcome to the forum! I've edited your post to provide a translation in English (via translate.google.com) and fixed your flow so it can be imported

  1. What version of Node-RED and node.js are you running (this can be found in the startup log)
  2. Please attach a debug node to the output of the mqtt-in node so we can see what kind of data you are sending to the rest of the flow. Please copy and paste the results (see below on how to do that)
  3. you should also remove the var's in the if statements
    ================

Hallo @WaRo52 Walter, willkommen im Forum! Ich habe Ihren Beitrag bearbeitet, um eine Übersetzung auf Englisch bereitzustellen (über Translate.google.com) und Ihren Ablauf so korrigiert, dass er importiert werden kann

  1. Welche Version von Node-RED und node.js verwenden Sie (diese finden Sie im Startprotokoll)
  2. Bitte fügen Sie einen „Debug“-Knoten an die Ausgabe des „mqtt-in“-Knotens an, damit wir sehen können, welche Art von Daten Sie an den Rest des Flusses senden. Bitte kopieren Sie die Ergebnisse und fügen Sie sie ein (siehe unten, wie das geht)
  3. Sie sollten auch die Variablen in den if-Anweisungen entfernen
    ================

In den Dokumenten gibt es eine tolle Seite (Arbeiten mit Nachrichten: Node-RED), die erklärt, wie man das Debug-Panel verwendet, um den richtigen Pfad zu jedem Datenelement zu finden.

Achten Sie besonders auf den Teil über die Schaltflächen, die unter Ihrem Mauszeiger angezeigt werden, wenn Sie mit der Maus über eine Debug-Meldungseigenschaft in der Seitenleiste fahren.

BX00Cy7yHi

Um den Code lesbar und nutzbar zu machen, ist es notwendig, Ihren Code mit drei Backticks zu umgeben (auch als linkes Anführungszeichen oder Backquote „ „“ bekannt).

```
    Code kommt hierher
```

Sie können Ihren Beitrag bearbeiten und korrigieren, indem Sie auf das Stiftsymbol :pencil2: klicken.

Weitere Informationen finden Sie in diesem Beitrag - How to share code or flow json

I suggest,
You can store your data in context storage rather than a file. You can set context to persistant to survive restarts.

would also store it in the OG object as it it easier to parse back. You can also add other properties to the object prior to storing if you wished. You could also store object direct to a file if yo so desired,.
It is better to format data for display, not to store it. i.e. store the value and the units separately, then use value and unit to format for display.

example flow storing payload to context and retrieving

[{"id":"700153c4.84c8ac","type":"mqtt in","z":"bb0b1c9f.00da8","name":"MQTT Broker lesen","topic":"stat/eg/waschmaschine/strom","qos":"0","datatype":"json","broker":"51dc6a63.563814","nl":false,"rap":false,"inputs":0,"x":130,"y":80,"wires":[["0d969792ddc83cc0"]]},{"id":"0d969792ddc83cc0","type":"change","z":"bb0b1c9f.00da8","name":"","rules":[{"t":"set","p":"waschmaschine_strom","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":390,"y":80,"wires":[["bd217c4a1745ad5e"]]},{"id":"bd217c4a1745ad5e","type":"debug","z":"bb0b1c9f.00da8","name":"do other stuff","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":620,"y":80,"wires":[]},{"id":"9fc2d07bce73251c","type":"inject","z":"bb0b1c9f.00da8","name":"retrieve stored json","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"waschmaschine_strom","payloadType":"flow","x":210,"y":220,"wires":[["183955aa7a9ca7e1"]]},{"id":"183955aa7a9ca7e1","type":"debug","z":"bb0b1c9f.00da8","name":"debug 325","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":470,"y":220,"wires":[]},{"id":"51dc6a63.563814","type":"mqtt-broker","name":"","broker":"192.168.2.115","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"stat/eg/waschmaschine/strom","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

[edit] As to issue, your creation of the filename would need to be in the same message not on a different wire.
e.g.

[{"id":"179b74ebc696b374","type":"inject","z":"bb0b1c9f.00da8","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"stat/eg/waschmaschine/strom","payload":"{\"wert\":10,\"Zeit\":20}","payloadType":"json","x":150,"y":140,"wires":[["59b15b6c.959004","ae9d3e97.d7141"]]},{"id":"59b15b6c.959004","type":"function","z":"bb0b1c9f.00da8","name":"Zeit","func":"zeit= msg.payload.Zeit;\nmsg.payload= zeit;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":330,"y":140,"wires":[["34ffbc57.225af4"]]},{"id":"ae9d3e97.d7141","type":"function","z":"bb0b1c9f.00da8","name":"Wert - Strom","func":"let wert= msg.payload.wert;\nmsg.payload= wert + ';' + 'mA';\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":350,"y":80,"wires":[["d53586ef.e26758"]]},{"id":"34ffbc57.225af4","type":"function","z":"bb0b1c9f.00da8","name":"timestamp in HH:mm:ss","func":"var dt = new Date(msg.payload);\n\nvar Monat = dt.getMonth() + 1;\nvar Tag = dt.getDate();\nvar Jahr = dt.getFullYear();\nvar Stunde = dt.getHours();\nvar Minute = dt.getMinutes();\nvar Sekunde = dt.getSeconds();\n\nif(Monat.toString().length == 1) {\n   Monat = '0'+Monat;\n  }\n  \nif(Tag.toString().length == 1) {\n  Tag = '0'+Tag;\n  }\n  \n if(Stunde.toString().length == 1) {\n   Stunde = '0'+Stunde;\n   }\n   \n if(Minute.toString().length == 1) {\n     Minute = '0'+Minute;\n   }\n\n if(Sekunde.toString().length == 1) {\n    Sekunde = '0'+Sekunde;\n   }\n \nmsg.payload = Stunde + ':' + Minute;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":530,"y":140,"wires":[["d53586ef.e26758"]]},{"id":"d53586ef.e26758","type":"join","z":"bb0b1c9f.00da8","name":"","mode":"custom","build":"string","property":"payload","propertyType":"msg","key":"topic","joiner":";","joinerType":"str","accumulate":false,"timeout":"","count":"2","reduceRight":false,"reduceExp":"","reduceInit":"","reduceInitType":"","reduceFixup":"","x":510,"y":80,"wires":[["f9553e6b.7cd5d"]],"inputLabels":["2"],"outputLabels":["1"]},{"id":"f9553e6b.7cd5d","type":"function","z":"bb0b1c9f.00da8","name":"Erstellung Datei","func":"function formatDate(date) {\n    var d = new Date(date),\n        month = '' + (d.getMonth() + 1),\n        day = '' + d.getDate(),\n        year = d.getFullYear();\n\n    if (month.length < 2) month = '0' + month;\n    if (day.length < 2) day = '0' + day;\n\n    return [day, month, year].join('-');\n}\n\nvar tempString =formatDate(Date().toString());\n\nvar tempString1 = \"/media/pi/9A6D-72BD/Waschmaschine/\";\nvar tempString2 = tempString1.concat(tempString);\nvar finalPath = tempString2.concat(\".txt\");\nmsg.filename = finalPath;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":100,"wires":[["5590329da9332af6","ad21bcd8.972b9"]]},{"id":"5590329da9332af6","type":"debug","z":"bb0b1c9f.00da8","name":"debug 325","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":690,"y":60,"wires":[]},{"id":"ad21bcd8.972b9","type":"file","z":"bb0b1c9f.00da8","name":"","filename":"","appendNewline":false,"createDir":false,"overwriteFile":"false","encoding":"none","x":630,"y":20,"wires":[[]]}]

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.