@garagehacker (garagehacker) posted a new topic, subject "openHAB Cloud Setup Guide for Azure and IFTTT". It read:

   # Objective
    
    Integrate IFTTT Platform services with openHAB by hosting a private instance of openHAB Cloud Connector on Azure.
    
    # Prerequisites
    
      * Familiarity with Linux command line interface
      * Azure subscription
      * IFTTT account (and optional Maker service setup for webhook example)
      * Existing openHAB instance and UUID and secrets
    
    
    
    # High-Level Steps
    
      1. Create and Configure VM
      2. Install openHAB Cloud Connector
      3. Install openHAB Cloud Connector Add-on
      4. Install LetsEncrypt SSL certificates
      5. Install and configure NGINX
      6. IFTTT Platform service integration
      7. Create IFTTT Applet
      8. Final VM configurations
    
    
    
    # Create and Configure VM
    
      1. Login to your Azure Portal and create a new Ubuntu 18.04 VM according to your needs
      2. Configure NSG to allow inbound TCP/80 and TCP/443 to your VM private IP address
      3. Create a FQDN DNS Name and note this for later
      4. SSH into your VM
      5. Update the OS and install additional packages
    
    
    [code] 
        $ sudo apt update;sudo apt upgrade -y
        $ sudo apt install build-essential redis-server mongodb nginx python git certbot python-certbot-nginx -y
        
    [/code]
    
      6. With this version of Ubuntu we need to install a specific version of Node:
    
    
    [code] 
        $ wget https://nodejs.org/download/release/v7.10.1/node-v7.10.1-linux-x64.tar.gz -O /var/tmp/node-v7.10.1-linux-x64.tar.gz
        $ sudo mkdir /usr/local/lib/nodejs
        $ sudo tar -xvf /var/tmp/node-v7.10.1-linux-x64.tar.gz -C /usr/local/lib/nodejs
        $ sudo ln -s /usr/local/lib/nodejs/node-v7.10.1-linux-x64/bin/node /usr/bin/node
        $ sudo ln -s /usr/local/lib/nodejs/node-v7.10.1-linux-x64/bin/npm /usr/bin/npm
        
    [/code]
    
      7. Verify that version 7.10.1 is running
    
    
    [code] 
        $ node --version
        
    [/code]
    
      8. Create user openhabcloud and group openhabcloud
    
    
    [code] 
        $ sudo useradd -M -r -s /bin/false -c "openHAB Cloud Connector" openhabcloud
        
    [/code]
    
    # Install openHAB Cloud Connector
    
      1. Download the latest version of cloud connector:
    
    
    [code] 
        $ sudo git clone https://github.com/openhab/openhab-cloud.git /opt/openhabcloud
        $ cd /opt/openhabcloud
        $ sudo npm install
        
    [/code]
    
      2. Change ownership of the directory
    
    
    [code] 
        $ sudo chown -R openhabcloud:openhabcloud /opt/openhabcloud
        
    [/code]
    
      3. Create the initial configuration file
    
    
    [code] 
        $ cd /opt/openhabcloud/
        $ sudo cp config-development.json config.json
        
    [/code]
    
      4. Edit /opt/openhabcloud/config.json, and replace the placeholder with your FQDN created above
      5. MongoDB username and password fields should be deleted, if there is no authentication configured
      6. Check if redis is running with ping command / expect PONG reply if everything is fine
    
    
    [code] 
        $ redis-cli ping
        
    [/code]
    
      7. Start the service to test if it's working
    
    
    [code] 
        $ sudo node app.js
        
    [/code]
    
      8. Note: the application is now running in the foreground. Press CTRL-C to end.
      9. Check the log output file at /opt/openhabcloud/logs/openhab-cloud-CCYY-MM-DD-process-nnnn.log for errors
      10. Optional: From your host computer (not the VM) configure SSH tunnel to test login of the web UI. Remember this service is running on TCP/3000 and that is not exposed to the public Internet. Otherwise, run netstat -an | grep LISTEN | grep “:3000” to see if the service is listening for incoming connections. Another alternative might be to use ngrok.
    
    
    
    # Install openHAB Cloud Connector Add-on
    
      1. From your openHAB Paper UI navigate to Add-ons > Misc
      2. Find misc-openhabcloud - 2.4.0 in the list of available add-ons and install
      3. Edit file services/openhabcloud.cfg adding your FQDN and expose at least one item to openHAB Cloud Connector. This item will be available once IFTTT integration is completed.
    
    
    [code] 
        baseURL=https://[FQDN]
        mode=remote
        expose=demoSwitch
        
    [/code]
    
    # Install LetsEncrypt SSL Certificates
    
      1. Optional: It's free and easy so why not? This requires port TCP/80 open inbound which is why the Azure NSG contains this entry. Can be removed from NSG once certs are installed with this process.
    
      2. Setup front-end NGINX web server by copying site configuration file that came with openhab cloud connector
    
      3. Note: LetsEncrypt certificates expire after 2 months.
    
    
    
    [code] 
        $ sudo cp /opt/openhabcloud/etc/nginx_openhabcloud.conf /etc/nginx/sites-available/default
        $ sudo sed -i '/listen \*:80/d' /etc/nginx/sites-enabled/default
        $ sudo service nginx restart
        $ sudo certbot --nginx -d [FQDN]
        
    [/code]
    
    # Install and Configure NGINX
    
      1. Edit /etc/nginx/sites-enabled/default to reflect the location of the SSL certificates and update the server_name directive as shown below.
    
    
    [code] 
        server {
        listen *:443;
        ssl on;
        ssl_certificate /etc/letsencrypt/live/[FQDN]/fullchain.pem;
        ssl_certificate_key /etc/letsencrypt/live/[FQDN]/privkey.pem;
        server_name [FQDN];
        if ( $scheme = "http" ) {
        rewrite ^/(.*)$ https://$host/$1 permanent;
        }
        
        charset utf-8;
        access_log /var/log/nginx/openhab-cloud.org-access.log;
        error_log /var/log/nginx/openhab-cloud.org-error.log;
        client_max_body_size 300m;
        location /css {
        alias /opt/openhabcloud/public/css;
        }
        
        location /js {
        alias /opt/openhabcloud/public/js;
        }
        
        location /img {
        alias /opt/openhabcloud/public/img;
        }
        
        location /bootstrap {
        alias /opt/openhabcloud/public/bootstrap;`
        }
        
        location /font-icons {
        alias /opt/openhabcloud/public/font-icons;
        }
        
        location /fonts {
        alias /opt/openhabcloud/public/fonts;
        }
        
        location /js-plugin {
        alias /opt/openhabcloud/public/js-plugin;
        }
        
        location /downloads {
        alias /opt/openhabcloud/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;
        }
        
        #error_page 404 /404.html;
        # redirect server error pages to the static page /50x.html
        #
        error_page 500 502 503 504 /50x.html;
        location = /50x.html {
        root html;
        }
        }
        
    [/code]
    
      2. Start the NGINX web service
    
    
    [code] 
        $ sudo service nginx restart
        $ sudo node app.js
        
    [/code]
    
      3. Visit your openHAB Cloud Connector at [https://FQDN]
      4. Register your openHAB instance by creating an account and supplying the UUID and Secret
    
    
    
    **
    
    w1_BJkTiwM0K5rPO5CbcYziAs6_d4wC_c4lP2TTNlZFNUJZk9in2UbAMcbLj-6sryYdUn-f2q5tjtQ4-fbEm6lSn21zDgQN3x-zU_yKZi_JNu3a4OnahE6c4Jj3Kg0XmLgbpQ2fW839×528
    
    **
    
    # IFTTT Service Integration
    
    **This section is based on the excellent guide:How To: Integrate Custom openHAB Cloud with IFTTT**
    
      1. Generate Client ID and the second Client Secrets by running the following command twice. Save the output for step 7.
    
    
    [code] 
        $ python3 -c "import secrets; print(secrets.token_hex(32))"
        
    [/code]
    
      2. Create a demo account your instance of openHAB Cloud Connector. UUID and secret values won't be used so anything will work. IFTTT Platform requires a demo account in step 10.
      3. Visit https://platform.ifttt.com/ and create a new Organization and Service.
      4. Fill out any required items under Service > General
      5. Navigate to “API” and fill in the IFTTT API URL with your FQDN
      6. Note the Service Key which will be used later
      7. Navigate to “Authentication” and select “My API has users with non-expiring OAuth2 access tokens” and enter Client ID and Client Secret here
      8. Set the “Authorization URL” to “https://[FQDN]/oauth2/authorize”
      9. Set the “Token URL” to “https://[FQDN]]/oauth2/token”
      10. Enter the demo account credentials that you created in Step 1 and Save all settings
      11. SSH into your openHAB Cloud Connector VM and configure the following oauth settings in mongodb
    
    
    [code] 
        $ mongo
        >>> use openhab
        >>> db.oauth2clients.insert({ clientId: "[Client ID]", clientSecret: "[Client Secret]"})
        >>> db.oauth2scopes.insert( { name : "ifttt", description: "Access to openHAB Cloud specific API for IFTTT", } )
        >>> exit
        
    [/code]
    
      12. Add your IFTTT Service Key to config.json
    
    
    [code] 
            "ifttt" : {
            "iftttChannelKey" : "[IFTTT Service Key]",
            "iftttTestToken" : ""
            },
        
    [/code]
    
      13. Restart openHAB cloud connector service
      14. Login to your openHAB cloud instance with your demo account
      15. From the API tab navigate to “Authentication Test” and click “Begin Test”
      16. After a short wait, you will be redirected to your openHAB Cloud Connector's OAuth2 authorization prompt. Click Allow.
    
    
    
    PL-lmuIi4pjmeboJZP5-M3XDizTxTsJOubt79x_c3cInTrgK8YZ90l444w6stMgXsH_MVP5TnNu7NRVe772vbog_1AhEinVzr2eR0OuWYM8RQZAyE3L777aMn2bCGpHuNOURjUbR964×391
    
      17. The results should look like this:
    
    
    
    IxdUrpECuxXYsaWszMGokoYrD4-cOvHF8aMvRjWTNlYhyoP6jQwcbbVNn0M3oUIJ5Gqplk0zsXMtLy1kvD46Syhdja6LIEpGXlOw5UJrE4Hn8NB_7V7VmkF2zq26MnS6rnkygTw41308×722
    
      18. Expand “Request access token” section and find the BODY entry under Response. Copy the access_token value and enter it into the iftttTestToken value in your config.json file.
    
    
    
    BfbFYj6uttT6uKbd1QnJ53MncHKc5KH4-5xnNYxqLxHwdKQmNvoTJY5d5syCBOnHg3rMK4mB-TdqE0XAgArfCc0_s2oLKAf2AXHd0V7TDoRAXI9w_M0ULr7FBVlZgKH9fZ867ywn891×448
    
      19. Optional: Execute the Endpoint tests. Expect these to fail but responses should contain HTTP status code “200” to indicate successful response from your endpoint.
    
    
    
    MgJHo486j7wTih-WIyn1uoRkwS1YUpZC7h_LxF61v6WvMhPKKXeYowCRYEyEb3HFqGhFQaJ_BuGauH_mb6ogDOLuixqiI2HgiBnpIBIQKXHsjUfWAiJCacAjqIb1puvQ6Fklq1c_934×463
    
      20. To send a command to openHAB from IFTTT applets you will need to configure an Action. Example form:
    
    
    
    Jyl7ysJYjN1WNOcMJer6GPY5v2XSIu1VsVjQz88HLg38fgN2lm9aB3zRk61elurvOnhsC0Z1GwtxBTf46HtHvFqzrMYKICiTjcwbz-eNOeSainIobkJBmnIbE39w65eBAHTj_HrG1352×920
    
      21. Click Save and create two Action fields
      22. Field 1: This is a dynamically retrieved list of exposed items from your openHAB instance.
    
    
      * Label: Which Item?
      * Key name: item
      * Required: This action field is required…
      * Action field type: Dropdown list
      * Retrieve list items from my service: https://[FQDN]//ifttt/v1/actions/command/fields/item/options
    
    
      23. Field 2: This is the command or value to set the OH item to. In an applet this might be state of ON or OFF.
    
    
      * Label: Command to send
      * Key name: command
      * Required: This action field is required…
      * Action field type: Text input
      * Messages: Short text
    
    
      24. Once completed the Action “Send a command” should have these two action fields:
    
    
    
    0LwN1FB7oA8-PsNhxBag7duagJ7xuN_dFEwclYVc1PDcREwkKevjHl1Cgm01Lk1fwjLxXdvx_eChAr3GqOpWQ8uiwDsiV0VLo_schIQv0ECYi4JpG0V_Sl2-zv2KrMpJU7XDnTo5838×378
    
      25. Important: Disable registration feature so that your instance of openHAB Cloud remains private. Edit the config.json file and append/edit the registration_enabled value to false
      26. Restart the service for the change to take affect
    
    
    [code] 
            ...
            "legal": {
            "terms" : "",
            "policy": ""
            },
            "registration_enabled": false
            }
        
    [/code]
    
    # Create Sample IFTTT Applet
    
      1. Ensure that your item(s) appear on your openHAB Cloud instance. If none appear use Karaf remote console to set a value to an exposed item. This will force the item to appear in the openHAB Cloud item list.
    
    
    [code] 
        openhab> smarthome:send demoSwitch ON
        
    [/code]
    
    nMjrch_Xrl6dBO5k-mwSTUNxj2980oQinVk_13fSZe7slfDDe8JkE7d4Px_pWSB5OClpATILzWJV5mhIwdVQzoVx_7p-m8kuof_rN0Zsj0Dc19vbP4iCLlFe9qqFHfn80Y1C0DVP802×336
    
      2. Visit https://ifttt.com/create
      3. Choose trigger: Webhooks (Note: Maker service setup required before using Webhooks)
      4. In the “Event Name” field enter demoSwitchON this will be passed as part of the URL in the Webhook call
      5. Next click +That and in the search box type in the name of your IFTTT Platform service
      6. If this is the first time using your service you will be redirected to your OAUTH2 sign in page. Important: Login with your openHAB Cloud Connector account (not the demo account) and click Allow. This has authorized IFTTT to read your OH exposed items and send them commands.
      7. Choose action: Send a command
      8. Which item?: [Select your exposed item]
      9. Command to send: ON
      10. Create Action, Review and finish!
      11. Repeat steps 2-10 again to create an OFF action.
      12. Issue a request to the webhook URL via browser or command line
    
    
    [code] 
        $ curl -X POST https://maker.ifttt.com/trigger/demoSwitchON/with/key/[redacted]
        
    [/code]
    
    Congratulations! You've fired the demoSwitchON event
    [code] 
        $ curl -X POST https://maker.ifttt.com/trigger/demoSwitchOFF/with/key/[redacted]
        
    [/code]
    
    Congratulations! You've fired the demoSwitchOFF event
    
      13. Visit your openHAB Cloud Connector > Event log page and verify that the events were received
    
    
    
    AXLqTJqWts7EiI7Bvby2bAMqG0hwLIQf3fTnR2GWWzLejEfZKyaG8247w8NQ1c4huMK4IcZOckm3dTH1_jmDiTqpADvl2PXMTYtCsMLJC_DwLeq2646WhM4F5g52HmlaeEjOKr9Y972×393
    
    # Final VM configurations
    
      1. Configure the service to start on boot by copying example systemd service file to /etc/systemd/service
    
    
    [code] 
        $ sudo cp /opt/openhabcloud/etc/openhabcloud.service /etc/systemd/system
        $ sudo vim /etc/systemd/system/openhabcloud.service
        
    [/code]
    
      2. Edit the file so it looks like the one below.
    
    
    [code] 
        [Unit]
        Description=node.js openhab cloud server
        After=nginx.service redis-server.service mongodb.service
        
        [Service]
        User=openhabcloud
        Group=openhabcloud
        Environment=NODE_ENV=production
        Restart=always
        RestartSec=10
        StandardOutput=syslog
        StandardError=syslog
        SyslogIdentifier=openhabcloud
        WorkingDirectory=/opt/openhabcloud
        ExecStart=/usr/local/lib/nodejs/node-v7.10.1-linux-x64/bin/node /opt/openhabcloud/app.js
        
        [Install]
        WantedBy=multi-user.target
        
    [/code]
    
      3. Enable the service to start on boot
    
    
    [code] 
        $ sudo systemctl enable openhabcloud.service
        $ sudo systemctl start openhabcloud.service
        $ systemctl status openhabcloud.service
        
    [/code]

@Andrew_Rowe (Andrew Rowe) replied

    just want to say @garagehacker thanks for such a well documented tutorial. I don't use IFTTT but two years since last visit and such a great contribution to the community! This shows that there is a huge ‘silent majority' of OpenHAB users that don't necessarily participate on a daily or weekly basis but are committed to this project.  
    Bravo

After which, @JornHermans (Jorn Hermans) added

    Saw this after i did a setup of the openhab-cloud, could you explain wy step 19 does this, this makes it not possible to publish the ifttt service…
    
    I also did open a topic for it ?

@CurtisFeatures (Jamie Curtis) replied

    Iv only recently got back into openhab after being away from home automation for a while. I was gutted when I found out IFTTT no longer worked as it made life so much easier for the family to use. And then I stumbled upon this and all I have to say is THANK YOU!.
    
    I had some issues setting up the SSL as it would not let me restart the NGINX service but I think this might have been down to me already running a reverse proxy in my DataCenter. Other than that though I managed to get it working on http as a proof on concept and will revisit the SSL and try run it through my own proxy rather than the one on the linux host.

To which @Mike-Mayer (Mike Mayer) replied

    Great Tutorial, also for setting up an openHAB-Cloud with a Google VM.  
    Tip: if you start with a small VM, setup will work better, after insatllation downgrade to micro 
    
    Cheers  
    Mike

@CurtisFeatures (Jamie Curtis) replied

    So this was working for me until I rebooted the server today. Now when I check the status using
    
    systemctl status openhabcloud.service
    
    I am getting this error… HELP?
    
    Last login: Mon Jan 27 13:59:39 2020 from 418-220-6139  
    jamie@cur-linux-01:~$ systemctl status openhabcloud.service  
    ● openhabcloud.service - node.js openhab cloud server  
    Loaded: loaded (/etc/systemd/system/openhabcloud.service; enabled; vendor pre  
    Active: activating (auto-restart) (Result: exit-code) since Mon 2020-01-27 14  
    Process: 1740 ExecStart=/usr/local/lib/nodejs/node-v7.10.1-linux-x64/bin/node  
    Main PID: 1740 (code=exited, status=1/FAILURE)  
    lines 1-5/5 (END)…skipping…  
    ● openhabcloud.service - node.js openhab cloud server  
    Loaded: loaded (/etc/systemd/system/openhabcloud.service; enabled; vendor preset: enabled)  
    Active: activating (auto-restart) (Result: exit-code) since Mon 2020-01-27 14:07:54 UTC; 5s ago  
    Process: 1740 ExecStart=/usr/local/lib/nodejs/node-v7.10.1-linux-x64/bin/node /opt/openhabcloud/ap  
    Main PID: 1740 (code=exited, status=1/FAILURE)

So @CurtisFeatures (Jamie Curtis) replied

    I recall doing a part where I could start the service manually by running:
    
    sudo node app.js
    
    When I did this I got an error saying there was an invalid syntax.
    
    I ran sudo cp config-development.json config.json to reconfigure and now everything works fine.
    
    How strange…

@Brody (Anders Broberg) replied

    This is a great guide. I would never have been able to set up openhab-cloud on Azure on my own without it. Only snag I hit was with the SSL certificates.
    
    Took me a while to figure out, and I'm not sure it was the only thing needed to get it to work, but at least the following lines need to be commented out in /etc/nginx/sites-available/default before restarting nginx in the step “Install LetsEncrypt SSL Certificates”. Otherwise nginx throws an error that it can't find the certificates and can't start SSL.
    
    garagehacker:
    
    > 
    [code]
    >     listen *:443; 
    >     ssl on; 
    >     ssl_certificate /etc/letsencrypt/live/[FQDN]/fullchain.pem; 
    >     ssl_certificate_key /etc/letsencrypt/live/[FQDN]/privkey.pem;
    >     
    [/code]
    
    Br,  
    Anders

So @digicos (Digicos) replied

    My Environment :  
    Digital Ocean, Ubuntu 18.04.4 LTS  
    nodejs : 7.10.1 & 12.18.0
    
    has anyone been able to make openhab cloud work on nodejs >=12.18.0  
    I am struggling to make it work.
    
    Also, I am having problem running on 7.10.1. I configured nodejs as described by @garagehacker in his post. The application starts and exits immediately with no errors printed on console. Can anyone help me here.  
    Thanks.


{'source': 'discourse', 'url': 'https://community.openhab.org/t/openhab-cloud-setup-guide-for-azure-and-ifttt/83208', 'title': 'openHAB Cloud Setup Guide for Azure and IFTTT', 'views': 2290, 'has_accepted_answer': False, 'word_count': 2632, 'like_count': 11, 'reply_count': 1, 'participant_count': 7, 'posts': 9, 'tags': 'openhabcloud openhab-cloud azure', 'author': '@garagehacker (garagehacker)', 'participants': '@garagehacker (garagehacker), @Andrew_Rowe (Andrew Rowe), @JornHermans (Jorn Hermans), @CurtisFeatures (Jamie Curtis), @Mike-Mayer (Mike Mayer), @Brody (Anders Broberg), @digicos (Digicos)', 'image_url': [None], 'created_at': '2019-10-07T20:24:46.401Z', 'last_posted_at': '2020-07-18T05:11:37.663Z'}