Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Datenpunkt berechnen

    NEWS

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    Datenpunkt berechnen

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

      weiterverarbeiten kann aber vieles sein…

      zB machst du einfach einen function node dran und mit "msg.payload[2]" holst du dir den 3 Wert im Array = 7.47

      Bin ziemlich sicher das es mit allen anderen Lösungen (bash, js, usw) wesentlich aufwendiger ist.

      Wenn es eine einfachere Lösung gibt - also unter 18 Zeichen - würde ich die jedenfalls gerne sehen 🙂

      1 Reply Last reply Reply Quote 0
      • Homoran
        Homoran Global Moderator Administrators last edited by

        @moebius:

        zB machst du einfach einen function node dran und mit "msg.payload[2]" holst du dir den 3 Wert im Array = 7.47 `
        so etwas hatte ich nach split auch versucht, hatte aber nicht geklappt, wahrscheinlich weil ich einen Multi-Output node nutzen wollte. Jedenfalls kam immer eine Fehlermeldung, dass keine msg_ID (????) dem Wert zugefügt werden könnte, die ich früher mit einem "msg.payload = " wegbekommen hatte.

        Werde jetzt nochmal mit kleinen Schritten arbeiten, bis ich es verstanden habe.

        Danke

        Rainer

        1 Reply Last reply Reply Quote 0
        • M
          moebius last edited by

          Wenn du mir sagst, was du weiter machen willst, kann ich das Beispiel gerne noch adaptieren…geht ja in 0," "

          Bin schon auf die anderen Lösungen gespannt 🙂

          1 Reply Last reply Reply Quote 0
          • Homoran
            Homoran Global Moderator Administrators last edited by

            ersten Schritte klappen, ich muss halt 14 nodes statt eines Multi-output node machen:

            je einmal ein function node:

            (Gesamtleistung)

            msg.payload = parseFloat(msg.payload[1]);
            return msg;
            

            davor war [2] Tagesertrag

            19.2.2017, 19:59:17node: 236e2f50.c7f5d
            msg : Object
            { _msgid: "4f9edac4.889c34", topic: "", payload: 7.47 }
            19.2.2017, 19:59:17node: 8ec4df5a.05194
            msg : Object
            { _msgid: "4f9edac4.889c34", topic: "", payload: 23117 }
            

            aber ich fürchte ich muss noch irgendwo die Credentialös einbauen, wenn sie nicht mehr im Cache sind.

            EDIT:

            du hattest den Quelltext der Seite ja im Inject node!

            Ich habe noch einen http request node hinzugefügt in dem ich auch die Credentials eingeben kann.

            Jetzt kommt:

            19.2.2017, 20:02:45node: 236e2f50.c7f5d
            msg : Object
            object
            _msgid: "f5b984b6.644ca8"
            topic: ""
            payload: 7.47
            statusCode: 200
            headers: object
            responseUrl: "http://pvserver:pvwr@192.168.138.54/"
            19.2.2017, 20:02:45node: 8ec4df5a.05194
            
            msg : Object
            object
            _msgid: "f5b984b6.644ca8"
            topic: ""
            payload: 23117
            statusCode: 200
            headers: object
            responseUrl: "http://pvserver:pvwr@192.168.138.54/"
            

            Gruß

            Rainer

            1 Reply Last reply Reply Quote 0
            • M
              moebius last edited by

              Glaube nicht das du 14 nodes brauchst…

              Wenn du Werte nach ioBroker spielen willst, brauchst du nur die Werte den jeweiligen DP im function node zuzuordnen.

              Es sollte dann ein array mit messages rauskommen, wo das topic der Names des DP's ists. Das kannst du dann über ein split gleich in

              den ioBroker output füttern.

              Werde das Beispiel adaptieren, damit du siehst was ich meine

              1 Reply Last reply Reply Quote 0
              • M
                moebius last edited by

                @Homoran:

                Jetzt kommt:

                19.2.2017, 20:02:45node: 236e2f50.c7f5d
                msg : Object
                object
                _msgid: "f5b984b6.644ca8"
                topic: ""
                payload: 7.47
                statusCode: 200
                headers: object
                responseUrl: "http://pvserver:pvwr@192.168.138.54/"
                19.2.2017, 20:02:45node: 8ec4df5a.05194
                
                msg : Object
                object
                _msgid: "f5b984b6.644ca8"
                topic: ""
                payload: 23117
                statusCode: 200
                headers: object
                responseUrl: "http://pvserver:pvwr@192.168.138.54/"
                ```` `  
                

                sieht doch gut aus! Werte sind da und statusCode ist 200

                1 Reply Last reply Reply Quote 0
                • Homoran
                  Homoran Global Moderator Administrators last edited by

                  @moebius:

                  sieht doch gut aus! Werte sind da und statusCode ist 200 `
                  Ja! bin auch schon ganz stolz 😉

                  jetzt geht es weiter - ich muss die "x x x" abfangen,

                  Hier ist mein erster nativer js-Teil:

                  var Spannung = parseFloat(msg.payload[3]);
                  var Strom = parseFloat(msg.payload[5]);
                  
                  If ( parseFloat(msg.payload[5] ) >0 ); {
                  msg.payload = ( Spannung * Strom );
                  else 
                  msg.payload = 0;
                  }
                  
                  return msg;
                  

                  da gibt's ein Mecker in der Zeile mit dem Else

                  Gruß

                  Rainer

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

                    @Homoran:

                    da gibt's ein Mecker in der Zeile mit dem Else `

                    if (parseFloat(msg.payload[5]) > 0) msg.payload = Spannung * Strom;
                    else msg.payload = 0;
                    

                    oder

                    if (parseFloat(msg.payload[5]) > 0) {
                       msg.payload = Spannung * Strom;
                    } else {
                       msg.payload = 0;
                    }
                    
                    1 Reply Last reply Reply Quote 0
                    • Homoran
                      Homoran Global Moderator Administrators last edited by

                      Danke Paul,

                      ich hatte zwar auch mit den geschweiften Klammern gespielt, aber diese Kombination dann wohl nicht gehabt 😞

                      Gruß

                      Rainer

                      1 Reply Last reply Reply Quote 0
                      • M
                        moebius last edited by

                        Hab das Beispiel erweitert. So könnte man die Werte zu iobroker übertragen.

                        ! [
                        ! {
                        ! "id": "1f5df07c.81145",
                        ! "type": "tab",
                        ! "label": "Flow 5"
                        ! },
                        ! {
                        ! "id": "12035f81.de82c",
                        ! "type": "html",
                        ! "z": "1f5df07c.81145",
                        ! "name": "",
                        ! "tag": "[bgcolor="#FFFFFF"]",
                        ! "ret": "text",
                        ! "as": "single",
                        ! "x": 372,
                        ! "y": 157,
                        ! "wires": [
                        ! [
                        ! "9a52a9cc.079668"
                        ! ]
                        ! ]
                        ! },
                        ! {
                        ! "id": "d487fa3f.daea58",
                        ! "type": "inject",
                        ! "z": "1f5df07c.81145",
                        ! "name": "",
                        ! "topic": "",
                        ! "payload": " <title>PV Webserver</title>
                        ! <form method="&quot;post&quot;" action="&quot;&quot;">
                        ! | |
                        | | PIKO 5.5
                        Helios (255) | |
                        ! | |
                        ! * * *

                        !
                        !
                        AC-Leistung Energie
                        aktuell x x x W Gesamtenergie 23117 kWh
                        Tagesenergie 7.47 kWh
                        Status Aus
                        !

                        ! * * *

                        !
                        !
                        PV-Generator Ausgangsleistung
                        <u>String 1</u> <u>L1</u>
                        Spannung x x x V Spannung x x x V
                        Strom x x x A Leistung x x x W
                        <u>String 2</u> <u>L2</u>
                        Spannung x x x V Spannung x x x V
                        Strom x x x A Leistung x x x W
                        <u>String 3</u> <u>L3</u>
                        Spannung x x x V Spannung x x x V
                        Strom x x x A Leistung x x x W
                        !

                        ! * * *
                        ! |
                        | |
                        ! |
                        ! | | RS485 Kommunikation |
                        | |
                        | | Wechselrichter |
                        | |
                        ! * * *
                        ! | |
                        | | Historie       Infoseite | Einstellungen | |
                        ! </form>
                        ! ",
                        ! "payloadType": "str",
                        ! "repeat": "",
                        ! "crontab": "",
                        ! "once": false,
                        ! "x": 220,
                        ! "y": 100,
                        ! "wires": [
                        ! [
                        ! "12035f81.de82c"
                        ! ]
                        ! ]
                        ! },
                        ! {
                        ! "id": "9a52a9cc.079668",
                        ! "type": "function",
                        ! "z": "1f5df07c.81145",
                        ! "name": "assign dps",
                        ! "func": "var msgs = []\n\nvar newmsg = { "topic": "admin.0.ws333.Temp3", "payload": msg.payload[2].trim()}\nmsgs.push(newmsg)\nvar newmsg = { "topic": "admin.0.ws333.Temp4", "payload": msg.payload[3].trim()}\nmsgs.push(newmsg)\n\nreturn [msgs];",
                        ! "outputs": 1,
                        ! "noerr": 0,
                        ! "x": 556,
                        ! "y": 213,
                        ! "wires": [
                        ! [
                        ! "6450ec54.d97594"
                        ! ]
                        ! ]
                        ! },
                        ! {
                        ! "id": "6450ec54.d97594",
                        ! "type": "ioBroker out",
                        ! "z": "1f5df07c.81145",
                        ! "name": "",
                        ! "topic": "",
                        ! "ack": "true",
                        ! "autoCreate": "false",
                        ! "x": 719,
                        ! "y": 255,
                        ! "wires": []
                        ! }
                        ! ]
                        Mit den Klammern und Strichpunkten musst du noch üben 🙂

                        if ( parseFloat(msg.payload[5] ) >0 ) {
                        msg.payload = (Spannung * Stom)
                        }
                        else {
                        msg.payload = 0
                        }
                        ````Du kommst bei node-red am leichtesten weiter, wenn du dich auf das Konzept einläßt. Am besten die ganze
                        
                        prozedurale Programmierung vergessen - der function node ist "böse" :evil: . Den darf man nur nehmen, wenns gar nicht anders geht.
                        
                        Edit sagt: function node auf multi message umgestellt - 2 nodes eingespart
                        [1803_clipboard06.jpg](/assets/uploads/files/1803_clipboard06.jpg)
                        1 Reply Last reply Reply Quote 0
                        • paul53
                          paul53 last edited by

                          @moebius:

                          Mit den Klammern und Strichpunkten musst du noch üben `
                          Du aber auch mit dem Semikolon. Was bei Homoran zu viele, sind bei Dir zu wenig.

                          1 Reply Last reply Reply Quote 0
                          • M
                            moebius last edited by

                            @paul53: du bist aber streng! In js sind ja keine ; vorgeschrieben und der code funktioniert auch.

                            Man kann natürlich welche machen - aber an den richtigen Stellen 😛

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

                              @moebius:

                              …und der code funktioniert auch. `
                              Ja, ist aber schlechter Stil und damit kein gutes Beispiel für einen absoluten Neuling.

                              1 Reply Last reply Reply Quote 0
                              • Y
                                ykuendig last edited by

                                Also, wenn ihr jetzt so Gas gebt, erwarte ich bei Sonnenaufgang die ersten Resultate. Vom Wechselrichter versteht sich.

                                1 Reply Last reply Reply Quote 0
                                • Homoran
                                  Homoran Global Moderator Administrators last edited by

                                  @moebius:

                                  Am besten die ganze

                                  prozedurale Programmierung vergessen - der function node ist "böse" `

                                  ok :shock:

                                  Ich wollte damit anfangen kleine Brocken javascript einzusetzen um langsam mit js warm zu werden 😞

                                  Daher sieht es bei mir auch so aus:
                                  144_solar_node-red.jpg

                                  nur im letzten kommt nichts raus:

                                  habe aber auch noch nicht lange gesucht.

                                  var DC = parseFloat(((msg.payload[5])*parseFloat(msg.payload[3])+(msg.payload[9])*parseFloat(msg.payload[7])));
                                  var AC = parseFloat(msg.payload[0]);
                                  
                                  var Wirkung = (AC/DC*100);
                                  
                                  if (parseFloat(msg.payload[5]) > 0) {
                                     msg.payload = Wirkung;
                                  } else {
                                     msg.payload = 0;
                                  }
                                  
                                  return msg;
                                  

                                  kein Gemecker, aber einfach kein Ergebnis auch kein null??

                                  @paul53:

                                  Du aber auch mit dem Semikolon. Was bei Homoran zu viele, sind bei Dir zu wenig. `
                                  Node-red meckert dann "unneccessary semikolon" - das hat es aber nicht :oops: :oops:

                                  Danke erstmal

                                  Rainer

                                  1 Reply Last reply Reply Quote 0
                                  • Y
                                    ykuendig last edited by

                                    Ich seh jetzt nicht in Deine Funktion-Nodes. Aber trimmst Du auch die Daten wie @moebius das vorgeschlagen hat? Oder rechnest Du das mit den ganzen Leerzeichen zusammen?

                                    1 Reply Last reply Reply Quote 0
                                    • M
                                      moebius last edited by

                                      @homoran: wahrscheinlich ist DC = 0 -> schlimm! 🙂

                                      Kann dir nur raten es nicht so zu machen - am Schluss endest du dann auch bei normalem javascript, tippst dir die finger wund und jagst die halbe Zeit bugs…

                                      1 Reply Last reply Reply Quote 0
                                      • Y
                                        ykuendig last edited by

                                        @moebius, aber Dein flow sieht ja eigentlich schon fast fertig aus. könntest Du da nicht die payloads noch gleich in Nummern wandeln. Dann müsste man blos noch die Datenpunkte richtig anschreiben. :lol:

                                        1 Reply Last reply Reply Quote 0
                                        • Homoran
                                          Homoran Global Moderator Administrators last edited by

                                          @ykuendig:

                                          Aber trimmst Du auch die Daten wie @moebius das vorgeschlagen hat? `
                                          An dem node hänge ich gerade und verstehe ihn noch nicht ganz.

                                          • Nein, ich arbeite noch mit allem, aber node-red scheint schlau zu sein und entfernt beim parseFloat() die Leerzeichen.

                                          @moebius:

                                          wahrscheinlich ist DC = 0 -> schlimm! `
                                          klar, daher ist es im Moment "x x x", was immer das bei parseFloat() ergibt??

                                          und hier in Köln heißt es: "Null x Null x Null is Null"

                                          bei der Division wird es dann natürlich lustig - überzeugt, dann muss ich das auch noch abfangen.

                                          @moebius:

                                          am Schluss endest du dann auch bei normalem javascript `
                                          Da will ich aber hin 😄

                                          Einen Adapter in node-red wäre wahrscheinlich höchst ambitioniert 😉

                                          Gruß

                                          Rainer

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

                                            Vor (msg.payload[9]) fehlt parseFloat.

                                            var DC = parseFloat(msg.payload[5]) * parseFloat(msg.payload[3]) + parseFloat(msg.payload[9]) * parseFloat(msg.payload[7]);
                                            var AC = parseFloat(msg.payload[0]);
                                            
                                            if(DC) {
                                               msg.payload = 100 * AC / DC;
                                            } else {
                                               msg.payload = 0;
                                            }
                                            
                                            return msg;
                                            
                                            1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post

                                            Support us

                                            ioBroker
                                            Community Adapters
                                            Donate

                                            834
                                            Online

                                            31.7k
                                            Users

                                            79.8k
                                            Topics

                                            1.3m
                                            Posts

                                            7
                                            70
                                            12458
                                            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