Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. ioBroker Allgemein
    4. mqtt keep alive im iobroker, oder in Node red

    NEWS

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

    • ioBroker goes Matter ... Matter Adapter in Stable

    • Monatsrückblick - April 2025

    mqtt keep alive im iobroker, oder in Node red

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

      Hallo zusammen,

      ich habe den mqtt dienst im iobroker am laufen, und kann da die datenpunkte
      aus meinen GX Gerät auslesen.

      leider kommen die Daten nicht sofort, ich muss immer erst die VRM online aufrufen, so das
      der mqtt dienst im GX gespächiger wird.

      oder ich sende im mqtt Explorer folgenden befehl: R/f83331xxxxx/keepalive
      dann wacht der GX auf und sendet alle Daten.

      mir gelingt es allerdings nicht diesen Befehl im mqtt dienst im iobroker,
      noch in node red zu senden.

      wie habt ihr das gelöst?

      grüsse aus bayern

      mickym S 2 Replies Last reply Reply Quote 0
      • mickym
        mickym Most Active @PEberhardt last edited by mickym

        @peberhardt Nun wo ist dein Broker und wenn Du es im mqtt Explorer schaffst - dann sollte es auch gehen. Eventuell hast Du den broker vermurkst. Es macht auch Sinn nicht im Broker direkt zu publishen .Wo ist das Problem, wenn Du mit der mqtt-Node publishst?

        Ich kann alles Publishen. Wenn das keepalive was braucht - das liegt an dem Gerät, da kann ich nicht helfen, dann muss man halt zu dem topic was publishen.

        1 Reply Last reply Reply Quote 0
        • S
          steffen_dec @PEberhardt last edited by

          @peberhardt
          Hallo,
          bist du da schon weiter gekommen?
          Ich habe dasselbe Problem, wenn ich über MQTT-Explorer ein publish auf "R/48e7daxxxxxx/system/0/Serial" mache, dann kommen die Werte für die nächste 1-2 Minuten.

          Mit einem Skript/Blockly habe ich auch versucht dieses Objekt zu beschreiben, leider funktioniert es nicht.

          Danke
          Gruß
          Steffen

          K 1 Reply Last reply Reply Quote 0
          • K
            klassisch Most Active @steffen_dec last edited by

            @steffen_dec
            Weiß nicht, ob das im konkreten Fall hilft. Aber so sieht mein Skript mit Quellensammlung zum Victron MQTT keep-alive aus

            Neben MQTT gibt es auch noch Modbus. Und auch darüber kann man Daten lesen und steuern.

            /*****************************************
             *      VICTRON MQTT 
             * 
             *    MQTT keep alive V2 requires Venus OS version >= V2.8
             *
             *   (mandatory for Victron MQTT interface)
             *    Victron Venus (GX) has to be polled in cyclic manner <1 min
             *    to assure a continuous MQTT service
             * 
             * 
             * 
             * Thanks to  https://forum.iobroker.net/user/mickym
             * refer thread https://forum.iobroker.net/topic/49258/frage-zu-mqtt-sonoff-adapter-und-mqqt-%C3%BCber-shell 
             * 
             * If this program does not work, please refer to 
             * https://github.com/victronenergy/dbus-mqtt/blob/master/README.md 
             * There is a legacy method for older devices and your configuration may differ
             * resulting in a different address of the serial number
             *
             * That document also describes the SELECTIVE subscriptions of a subset of topics, 
             * which is recommended for bigger installations with lots of data objects
             * ATTENTION !!! Using the selective keepalive method requests to advice the 
             * MQTT client (ioBroker adapter) to send every message even if the message is unchanged
             * (UNCHECK "publish chnages only" in the MQTT setup tab)  
             * 
             * A general overview about communication with victron products can be found in
             * https://www.victronenergy.com/upload/documents/Technical-Information-Data-communication-with-Victron-Energy-products_EN.pdf
             * https://www.victronenergy.de/upload/documents/Technical-Information-Data-communication-with-Victron-Energy-products_DE.pdf
             * 
             * 
             *
             * 
             *  
             *****************************************/
            /**********input parameters************** */
            const debugLogOn = true; // enables console logs 
            
            const vrmAccount = 'bGeheimNimmDein eigenes2';
            const mqqtClientInstanceId ='mqtt.1';
            
            const victronMqttKeepAliveInterval = 30*1000; // 30* 1000 ms
            
            /******** Alternative 1: use this empty list to suscribe to all available topics 
             * An empty message subscribes all */
            
            // const victronMqttSubscritionString =  '';
            
            /******** End Alternative 1: use this empty list to suscribe to all available topics */
            
            
            /*******Alternative 2 Selective subscription ********************************
             * for production in bigger installations you can use a list of dedicated 
             * subscription such as
             */  
             
             const victronMqttSubscritionList = ["vebus/#","system/#","battery/#","solarcharger/#" /*,"solarcharger/+/Dc/0/Voltage"*/];
             const victronMqttSubscritionString = JSON.stringify(victronMqttSubscritionList);
            // victron requests a string and no JSON objects here
            
            // if(debugLogOn)console.log('victronMqttSubscritionList: ' + victronMqttSubscritionList);
            // if(debugLogOn)console.log('victronMqttSubscritionString: ' + victronMqttSubscritionString);
            
             /* ******* End Alternative 2 ************************** */
            
            /********** End input parameters************** */
            
            /************ Program Code *************************** */
            
             
            const victronMqttKeepAliveName = 'R.' + vrmAccount + '.keepalive' ;
            var victronMqttKeepAliveId = mqqtClientInstanceId + '.' + victronMqttKeepAliveName ;
            
            var ignoreMqttPayload = 0;
            
            if (debugLogOn){
                console.log('keepAliveName: '+ victronMqttKeepAliveName);
                console.log('keepaliveId: ' + victronMqttKeepAliveId);
            }
            
            console.log('Please check if the data point with the Id ' + victronMqttKeepAliveId + 'exists' );
            console.log('If not, please create it manually in expert mode. Type is string' );
            
            
            // first poll
            let pollingCounter = 1;
                  setState(victronMqttKeepAliveId, String(pollingCounter)); 
                  setState(victronMqttKeepAliveId, victronMqttSubscritionString);
                  ++ pollingCounter
            // value sent has to be changed for every transmission. 
            //   Othewise the MQTT adapter would supress the transmission in the default configuartion
            //   = "transmit changes only"
              
            // cyclic polls
            var keepalivePollCounterShowTimer = null;
            setInterval(function() { 
                  setState(victronMqttKeepAliveId, victronMqttSubscritionString);
                  ++ pollingCounter
                  if(keepalivePollCounterShowTimer) clearTimeout(keepalivePollCounterShowTimer); // stop running timer
                  keepalivePollCounterShowTimer = setTimeout(function() { // restart Timer
                       // this provides a changing value for the MQTT adapter
                       setState(victronMqttKeepAliveId, String(pollingCounter)); 
                   }, victronMqttKeepAliveInterval/2); 
            }, victronMqttKeepAliveInterval);
                
            
            
            /************* Bonus ************************
            
                examples to convert values (provided by @ https://forum.iobroker.net/user/mickym)
                in posts https://forum.iobroker.net/post/710843 and https://forum.iobroker.net/post/710856 
            
                Reading values provided by the MQTT client:
            
                   str='{"value": 233.8300018310547}';
                   obj = JSON.parse(str);
                   wert = obj.value;
            
            
                Writing values to the MQTT object range
                  objAcPowerSetpoint = { "value" : -200};
            
                  // object wieder in JSON String
                  strMqtt = JSON.stringify(objAcPowerSetpoint);
                  setState ('mqtt.0.W.e0fffff1389.vebus.257.Hub4.L1.AcPowerSetpoint', strMqtt, false);
            
             ********************** End Bonus ***********************************************/
            
            
            
            
            // Test: reading and converting a value
            
            /****************check might be defect 
            
            const testId = 'mqtt.1.N.b827eb4b48d2.vebus.288.Ac.Out.L1.P';
            
            on({id: testId, change: "ne"}, function(dp) { 
               let Pobj = JSON.parse(dp.state.val);
               let Pval = Pobj.value; 
               if (debugLogOn){
                   console.log('dp: ' + JSON.stringify(dp));
                   console.log('TestObjekt: ' , JSON.stringify(Pobj));
                   console.log('TestValue: ' + Pval);
                }; 
            });
            
            
            /******************** Monitoring *********************************** */
            
            //SoC of Battery
            
            const socWarning1Threshold = 99;
            const socWarning2Threshold = 25;
            
            
            const socPath = '.system.0.Dc.Battery.Soc';
            const socId = mqqtClientInstanceId + '.N.' + vrmAccount + socPath;
            if (debugLogOn) console.log('SoC-Id: ' + socId);
            
            on({id: socId, change: "ne"}, function(dp) { 
               let socObj = JSON.parse(dp.state.val);
               let socVal = socObj.value; 
               if(debugLogOn)console.log('SoC change: ' + socVal)
            
               if(socVal <= socWarning2Threshold){
                   if(debugLogOn)console.log('!! Battery Alert 2. SoC = ' + socVal);
               }
               else {
                   if(socVal < socWarning1Threshold){
                       if(debugLogOn)console.log('!! Battery Warning 1. SoC = ' + socVal);
                   };
               };
            });
            
            /*****************  SystemState / Switch ************/
            const statePath = '.system.0.SystemState.State';
            const stateId = mqqtClientInstanceId + '.N.' + vrmAccount + statePath;
            
            if (debugLogOn) console.log('state-Id: ' + stateId);
            
            
            // State: 0=Off;1=Low Power;2=Fault;3=Bulk;4=Absorption;5=Float;6=Storage;7=Equalize;8=Passthru;9=Inverting;10=Power assist;11=Power supply;252=Bulk protection
            const invertingState = 9;
            
            on({id: stateId, change: "ne"}, function(dp) { 
               let stateObj = JSON.parse(dp.state.val);
               let stateVal = stateObj.value; 
               if(debugLogOn)console.log('state change: ' + stateVal)
               if(stateVal == invertingState){
                   if(debugLogOn)console.log('!! Enterig inverter  state. Check for grid failure');
               };
            });
            
            
            
            
            
            //end
            
            
            
            1 Reply Last reply Reply Quote 0
            • A
              Alkazar last edited by Alkazar

              @steffen_dec
              Moin Steffen,

              ich bin heute Abend über das gleiche Problem gestolpert. Nach mehreren erfolglosen Versuchen habe ich jetzt eine Lösung mit einem Blockly-Skript gefunden.
              Wichtig hier der Datenpunkt muss gesteuert und nicht aktualisiert werden, so klappt es zumindest bei mir:
              Screenshot 2023-07-24 004326.jpg

              tugsi 1 Reply Last reply Reply Quote 0
              • tugsi
                tugsi @Alkazar last edited by

                @alkazar sagte in mqtt keep alive im iobroker, oder in Node red:

                Wichtig hier der Datenpunkt muss gesteuert und nicht aktualisiert werden, so klappt es zumindest bei mir:

                Ist schon lustig, habe dies auch mit steuern gemacht, brachte bei mir aber kein Ergebnis, dann bin ich hingegangen und habe es umgestellt auf aktualisieren und siehe da, jetzt klappt es.
                Muss man nicht verstehen 😉

                Humidor 1 Reply Last reply Reply Quote 0
                • Humidor
                  Humidor @tugsi last edited by Humidor

                  @tugsi Hallo!
                  stehe vor dem selben Problem
                  das hier wäre mein Blockly, ich habe nur N und den keepalive im Mqtt.1. Client drin
                  Bildschirmfoto 2024-02-02 um 09.50.31.png

                  hab da jetzt viel probiert, ich bekomme einfach keine Daten, bitte um HILFE!
                  es fehlt mir auch der R Reiter, kA warum, VRM ist aktiv, Cerbo GX ist aktiv und Mqtt eingeschaltet...??
                  er kann mir den Datenpunkt auch nicht erzeugen
                  Bildschirmfoto 2024-02-02 um 10.29.33.png
                  Bildschirmfoto 2024-02-02 um 10.28.17.png

                  tugsi 1 Reply Last reply Reply Quote 0
                  • adcrafter27
                    adcrafter27 last edited by adcrafter27

                    Es muss der Bereich "R" sein, viele haben diesen nicht da sie meist nicht mit den Mqtt Explorer gearbeitet haben, sondern direkt mit dem IoBroker.
                    Mann muss einmal den keepalive Befehl mit den Mqtt Explorer gesendet haben,.
                    oder man verwendet einfach Node Red. Habe eine kleine Anleitung gemacht
                    https://forum.iobroker.net/topic/72404/mqtt-zum-victron-cerbo-gx/9?_=1706865695864

                    1 Reply Last reply Reply Quote 0
                    • tugsi
                      tugsi @Humidor last edited by

                      @humidor
                      Wie @adcrafter27 schon schreibt, Du musst R/ benutzen, den auf steuern und dann sollte es funktionieren.

                      Humidor 1 Reply Last reply Reply Quote 0
                      • Humidor
                        Humidor @tugsi last edited by

                        @tugsi R alive läuft mit mittels Node (@adcrafter27 ), aber es kommt noch immer nichts daher, gibt es Zugriffsrechte, Einschränkungen, Passwörter?

                        Humidor tugsi 2 Replies Last reply Reply Quote 0
                        • Humidor
                          Humidor @Humidor last edited by

                          @humidor es läuft, der andere Thread ist oben verlinkt.

                          1 Reply Last reply Reply Quote 0
                          • tugsi
                            tugsi @Humidor last edited by

                            @humidor
                            Bin jetzt erst zuhause, meine Antwort war auch nicht korrekt, denn ich musste auf aktualisieren stellen, weil steuern nicht klappte ...
                            Aber Du hast es mittlerweile ja auch schon hinbekommen.
                            Ich hab jetzt bei mir mal geschaut und gesehen, dass ich den Blockly inaktiv habe und MQTT auch nicht mehr da benutze, um ehrlich zu sein, habe ich ne zeitlang vieles probiert und muss mir gerade selber zugestehen, weiß gar nicht mehr, was ich seinerzeit wollte und wie und wo ich es jetzt gelöst habe *lach.
                            Ich habe auf der Venus auch NodeRed laufen und schicke da bestimmte Werte von weg bzw frage die ab, gerade im Zusammenhang mit meiner Wallbox.

                            Aber wie bei allem, es gibt verschiedene Wege, die nach Rom führen 😉

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

                            Support us

                            ioBroker
                            Community Adapters
                            Donate
                            FAQ Cloud / IOT
                            HowTo: Node.js-Update
                            HowTo: Backup/Restore
                            Downloads
                            BLOG

                            463
                            Online

                            31.7k
                            Users

                            79.8k
                            Topics

                            1.3m
                            Posts

                            8
                            12
                            1460
                            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