Automatischer Reconnect zum Cloud-Connector

  • Da es den Einen oder anderen gibt, der nach der Abschaltung der Livisi Cloud-Dienste weiterhin alles von unterwegs mit OpenHab steuern will benötigt den OpenHab Cloud-Connector.
    Wie man diesen Einrichtet, habe ich schon einmal in einer Anleitung erwähnt. Nichts ist aber ärgerlicher, als dass der Cloud-Connector seinen Dienst verweigert und die Verbindung in die Cloud abbricht. Dann ist es auch nicht mehr möglich, von unterwegs auf das Smarthome zuzugreifen.


    Es gibt aber eine Möglichkeit zu prüfen, ob der Dienst noch mit myOpenHab verbunden ist und diesen ggf. automatisch neu startet

    Dazu habe ich in Openhab-Community folgende Anleitung gefunden der für mich auch gut funktioniert:
    https://community.openhab.org/…cted-disconnection/143199


    Hier der Original-Post aus obigem Link:
    1. Install bindings and transformations

    Start by installing these add-ons, if you don’t already have them:

    2. Turn on Implicit User Role

    Check that the Implicit User Role is ON in your API Security settings (it most likely is).

    [Blocked Image: https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/a/6/a6d4b80762e830a34f57db75d2398c5f292906cd.png]image733×180 6.78 KB

    3. Make an unbound item to store the testing message

    Create a string item that has no channel attached to it. Mine is called myopenHAB_Connection.

    When the connnection test starts, the string will be updated to Testing. We’ll then send a command through myopenHAB to change the string to Online. If the command succeeds, it’s not necessary to restart the cloud connector.

    If you want, you can add this item to a page or sitemap as an indicator of the cloud status.

    4. Make a thing and item to send a POST command to myopenHAB

    1. In MainUI, manually add a thing using the Exec Binding. You can edit the ID and label to be whatever you want them to be (mine is called Post_Test_Command).[Blocked Image: https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/optimized/3X/c/7/c778612c9533e25aff9f7c3becf8835d36083bd4_2_517x175.png]image722×245 6.01 KB
    2. Enter the following statement in the Command field, substituting in your myopenHAB username and password:

      curl -u username:password -H "Content-Type: text/plain" -X POST -d "Online" https://myopenhab.org/rest/items/myopenHAB_Connection

      This curl command changes the string in the myopenHAB_Connection item to be Online.

    3. Click the “Create thing” button to save your work.
    4. Create a switch item that’s connected to the Running channel of your exec thing (I’ve called my item Post_Test_Command). When this item is turned ON, it will execute the shell command and then reset itself to OFF.[Blocked Image: https://community-openhab-org.s3.dualstack.eu-central-1.amazonaws.com/original/3X/e/8/e8e19b7586511eb46a0a23036b631f4df53d81a8.png]image728×136 6.09 KB

    5. Make a thing and item to restart the cloud connector

    1. In MainUI, add another thing using the Exec Binding. You can edit the ID and label to be whatever you want them to be.
    2. Enter the following statement in the Command field:
      Code
      openhab-cli console -p habopen bundle:restart org.openhab.io.openhabcloud

      This shell command will log into the console 2 and restart the openhabcloud bundle.

      NOTE: habopen is the default password for the console (which is different from the password you use to log into your server via SSH. Most users leave it as `habopen’, but if you’ve changed it then you’ll need to change it here as well.

    3. Click the “Create thing” button to save your work.
    4. Create a switch item that’s connected to the Running channel of your exec thing (I’ve called my item Restart_Cloud_Connector).

    6. Add the exec commands to the exec.whitelist

    Before you can execute a shell command, it has to be added to the exec.whitelist file, which you’ll find in the openhab-conf/misc folder on your OH server.

    1. Open exec.whitelist in a text editor and insert the commands we used in our exec things:

      curl -u username:password -H "Content-Type: text/plain" -X POST -d "Online" https://myopenhab.org/rest/items/myopenHAB_Connection

      openhab-cli console -p habopen bundle:restart org.openhab.io.openhabcloud

      Don’t forget to update your username, password, and item name (if you changed it from myopenHAB_Connection). The commands in your exec things must be identical to the whitelist.

    2. Save and close exec.whitelist.

    7. Test your exec items

    At this point, your items should work. You can add them to a page or sitemap and toggle them on to see the results in your log.

    8. Make a thing to monitor the log

    1. In MainUI, manually add a thing using the Log Reader Binding. For the ID and label, I’ve used:
      • ID: openhabcloud
      • Label: LogReader: openHAB Cloud
    2. In the Custom Patterns field, enter the following string:
      Code
      Connected to the openHAB Cloud service

      The thing will monitor the log and update whenever it sees this exact string of text.

      NOTE: We installed the REGEX Transformation earlier so that it can be used by this item (using the default settings). You don’t need to do anything else with REGEX.

    3. Click the “Create thing” button to save your work.

      The log reader thing has an an advanced channel called New Custom Event. It can be used to trigger a rule without needing an item (though you can also make a switch if you prefer).

      So, let’s make that rule.

    9. Restart the binding whenever a disconnect is detected

    Apologies for the fact that I’m still using Rules DSL. In a nutshell, this rule does the following:

    1. Triggers whenever openHAB reconnects to myopenHAB.
    2. Updates the myopenHAB_Connection string item to Testing
    3. Sends a command through the cloud to change myopenHAB_Connection string item to Online
    4. Checks if myopenHAB_Connection changed to Online
    5. Restarts the binding if the Online command was not received

    And that’s all. The hard part is really getting the things/items set up, but only if you’ve never used the exec or log reader bindings before.

    Some things to note:

    • The rule will trigger every time it sees the “Connected to…” message in the log. So, it will loop continuously until it successfully reconnects. For this reason, I’ve set a five-minute waiting period in case there are multiple disconnects/reconnects in a brief span of time.
    • The rule will not run unless it sees the “Connected to…” message. So, if there’s an actual myopenHAB outage, we won’t keep pinging it with this rule and potentially making things worse.




    Ich habe allerdings den Neustart der Cloud-Connection nicht über ein zweites Exec-Thing realisiert sondern mit einer DSL-Rule und dem entsprechenden Status des Schalters.

  • Hallo,


    Dein Vorschlag mit dem LogReader ist grundsätzlich gut.

    Allerdings setzt das korrekte Funktionieren Deines Szenarios voraus, dass Deine lokale OpenHAB-Instanz merken muss, dass die Verbindung zur Cloud weg ist. Denn ohne das, kann kein Log-Eintrag erzeugt werden und ohne Log-Eintrag kann das vom Log-Reader-Binding auch nicht entsprechend ausgewertet werden.


    In der Praxis ist es jedoch häufig so, dass Dein lokales OpenHAB gar nicht "merkt", dass es ein Problem gibt.

    Deshalb hat sich eine andere Vorgehensweise als besser herausgestellt.


    Diese habe ich in folgendem Thread beschrieben:


    OpenHab: System reboot, Neustart OH, Neustart einzelner Bindings von der Benutzeroberfläche aus - Seite 2 - OpenHab - LIVISI Community


    Für diese Methode ist auch kein Binding oder sonst etwas erforderlich.


    Gruß Ralph

  • So, nun habe ich einen Grund, warum man obiges Vorgehen nicht nutzen sollte sondern besser auf das von Ralph gepostete setzen sollte. Habe das Script jetzt übernommen und unter kleinen Anpassungen in eine DSL Rule übernommen.

    Sobald der Service oder der Pi neu gestartet wird, wird die Exec.Whitelist nicht mehr korrekt erkannt und es erscheint hinter den Befehlen im Log immer "but it is not contained in whitelist."

    Sobald der openHab Service oder der Pi neu gestartet wird, selbst wenn alles noch in der Whitelist vorhanden ist.

    Helfen. tut nur das manuelle öffnen und speichern der Whitelist.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!