Hosting your own OpenHab Cloud instance

Hi All,

I am writing this quick guide for anyone who is interested in hosting it’s own openhab cloud instance.

I have taken the guidance from the following posts:

Setup your own openhab-cloud (myopenhab) server/instance
This post was written a while back but still having greatest information of all. However, it needs some updates that I have tried to cover in this post.

Few points are taken from the following repository URL:
OpenHab Cloud Repository

Server Configuration:

Server: VPS from IONOS

RAM: 512 MB

HDD: 10GB SSD

OS: Ubuntu 20.04

Follow the steps below to quickly set-up the OpenHab Cloud:

  • Get a new cheap VPS or Cloud Server. I used IONOS VPS for as cheap as $2 per month for above configuration.

  • Get a domain name or use a sub domain. You can use any cheap domain provider. I used GoDaddy.

  • Change your domain “A Record” to point to your new VPS or Cloud server.

  • Login to your VPS server using SSH:

    • Open command or terminal and type ssh root@[your server IP address]
    • Type your password when asked and press enter.
  • Next run the following command in sequence:

    • sudo apt-get update && sudo apt-get upgrade
    • sudo hostname [your domain name]
  • Install NGINX:

    • sudo apt-get install nginx
  • Remove the default configuration:

    • rm /etc/nginx/sites-enabled/default
  • Create a new configuration for your domain:

    • nano /etc/nginx/sites-enabled/[your domain name]
  • Copy the following code below in the editor:

server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name [your domain name];

    root /var/www/[your domain name];
    index index.html index.htm;
    location ~ /.well-known {
    	allow all;
    }
}
  • Press “ctrl/command + x” to close the file. Press Y is asked for overwriting the file.

  • Execute the following command to create and then navigate to a new directory for your cloud repository:

    • mkdir /var/www/[your domain name]
    • cd /var/www/[your domain name]
  • Execute the following command to create an index.html file and test if our server is running:

    • nano index.html
  • Write the following text in the editor:

 <html>
        <head>
                <title>
                        My OpenHab Cloud
                </title>
        </head>
        <body>
                My OpenHab Cloud Test Page
        </body>
</html>
  • Press “ctrl/command + x” to close the file. Press Y is asked for overwriting the file.

  • Execute the following command to restart the nginx server

    • sudo systemctl restart nginx
  • Execute the following command to check if your new page is working or not:

    • curl [your domain name]
    • You will see the html you just created as the output of the previous command.
  • Install SSL certificate for your OpenHab Cloud instance:

    • sudo apt-get install letsencrypt
    • sudo letsencrypt certonly -a webroot --webroot-path=/var/www/[your domain name] -d [your domain name]
    • Provide your email address when asked and agree to the terms and conditions.
  • Setup the SSL for your OpenHab Cloud Instance:

    • nano /etc/nginx/sites-enabled/[your domain name]
    • Write the following code in the editor. Replace the old code in the file:
 server {
    listen 80 default_server;
    listen [::]:80 default_server;
    server_name [your domain name];
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl default_server;
    listen [::]:443 ssl default_server;
    server_name [your domain name] ;

    ssl_certificate /etc/letsencrypt/live/[your domain name]/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/[your domain name]/privkey.pem;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
    ssl_prefer_server_ciphers on;
    ssl_ciphers "EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH";
    ssl_ecdh_curve secp384r1;
    ssl_session_cache shared:SSL:10m;
    ssl_session_tickets off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 8.8.8.8 8.8.4.4 valid=300s;
    resolver_timeout 5s;

    add_header Strict-Transport-Security "max-age=63072000; includeSubdomains";
    add_header X-Frame-Options DENY;
    add_header X-Content-Type-Options nosniff;

    root /var/www/[your domain name];
    index index.html index.htm;
    location ~ /.well-known {
    	allow all;
    }
	
	location /css {
        alias  /var/www/[your domain name]/openhab-cloud/public/css;
    }
    location /js {
        alias /var/www/[your domain name]/openhab-cloud/public/js;
    }
    location /img {
        alias /var/www/[your domain name]/openhab-cloud/public/img;
    }
    location /bootstrap {
        alias /var/www/[your domain name]/openhab-cloud/public/bootstrap;
    }
    location /font-icons {
        alias /var/www/[your domain name]/openhab-cloud/public/font-icons;
    }
    location /fonts {
        alias /var/www/[your domain name]/openhab-cloud/public/fonts;
    }
    location /js-plugin {
        alias /var/www/[your domain name]/openhab-cloud/public/js-plugin;
    }
    location /downloads {
        alias /var/www/[your domain name]/openhab-cloud/public/downloads;
    }

    location / {
        proxy_pass http://localhost:3000;
        proxy_redirect off;
        proxy_http_version 1.1;
        proxy_set_header Host $host;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header X-Real-IP $remote_addr ;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for ;
        proxy_set_header X-Forwarded-Proto https;
    }
}
  • Run the following commands:
    • sudo apt-get install build-essential redis-server mongodb python git
    • cd /var/www/[your domain name]/
    • git clone --depth 1 --branch 1.0.10 https://github.com/openhab/openhab-cloud.git
    • sudo apt-get install software-properties-common
    • curl -sL https://deb.nodesource.com/setup_7.x | sudo -E bash -
    • sudo apt-get install nodejs
    • sudo apt install npm
    • sudo npm cache clean -f
    • sudo npm install -g n
    • sudo n 7.10.1 Its important to install this version of node.
    • cd /var/www/[your domain name]/openhab-cloud
    • npm install
    • npm install bcryptjs@^2.4.3 qunitjs@^2.0.0
    • npm install node-time
    • cp config-production.json config.json
  • Change the config.json file as follows:
    • nano config.json
    • Change your domain name as the first line in the file.
    • Remove the User Name and Password lines from the mongodb section. It must look like below:
"mongodb": {
        "hosts": ["127.0.0.1"],
        "db": "openhab"
    },
  • Reboot your system and navigate to your openhab cloud directory:

    • cd /var/www/[your domain name]/openhab-cloud/
  • Run the following command to start your openhab cloud:

    • node app.js

Node application will start and show status messages.
Once started, open your browser and navigate to [your domain name].
Check that your browser will automatically redirect the site to https.

Running the application as service:
Follow the steps below to start the application as service each time when your server reboots.

  • Create a new file by running the following command:
    • nano /lib/systemd/system/openhabcloud.service
  • Change the contents of the file with below:
[Unit]
Description=My OpenHab Cloud Service

[Service]
Type=simple
User=**[Replace this with a Valid Account Name]**
ExecStart=node /var/www/[your domain name]/openhab-cloud/app.js
Restart=on-failure

[Install]
WantedBy=multi-user.target
  • Test your service by using the following commands:

    • sudo systemctl daemon-reload
    • sudo systemctl start openhabcloud
    • sudo systemctl status openhabcloud
  • If your service is shown as active and running then try opening [your domain name] in browser. It must show you the secured version of OpenHab cloud instance.

  • Run the following commands to make it autostart at system boot:

    • sudo systemctl enable openhabcloud.service
  • Reboot your server with the following command and check [your domain name] in browser:

    • sudo reboot -h now

Make sure you have the following ports open in your firewall:

Port 80 for HTTP.
Port HTTPS for 443.
Port 22 for SSH. This you can remove after the configuration.

4 Likes

will Google Intergration still work? I’m in the US and ive noticed some latency when asking google to do things that involve talking to myopenhab cloud and was thinking its cuz the server is all the way in middle of EU

You’d have to set up and maintain the Google Assistant Action on your cloud server, and connect it to Google.

I believe the myopenHAB servers are in the US, but don’t quote me on that.

I’m in Canada and usually don’t see any more latency with Assistant than I do from the Android app or a sitemap, so I’m not sure that running your own server will benefit you much, relative to the time/effort/expense you’ll put into it.

I am in India, I do not see any latancy both for Google Assistance and for Alexa.
May I know the configuration and all the bindings you are using, may be I will try to mimic your exact environment and see what is causing the delay.

Thank you for the great write-up! I got it working also on AWS EC2 following your instructions!

I worked out you need to issue “npm rebuild” after installing bcryptjs and qunitjs, or it wont start however :slight_smile:

1 Like

Thank you for the tutorial.

I had no problems with the installation but we have a problem much more headaches.

After installing and adding the uuid/secret from the local app I got the message:

Your openHAB is online. Click here to access your openHAB's dashboard

This is an endless loop involving something called proxyURL.

An example to illustrate is that the main application runs at https://www.myopenhab.org then after logging in you are redirected to https://home.myopenhab.org

This means we need to run 2 instances of the application on ports 3000 and 3001.

I don’t really understand their intentions.

Setup your own openhab-cloud (myopenhab) server/instance - Tutorials & Examples - openHAB Community

1 Like

Just installed on Ionos Ubuntu 22 (latest), mongodb v6, node 14, and pulled last version of the openenhab-cloud. Working perfect with alexa skills too.

1 Like