Setup your own openhab-cloud (myopenhab) server/instance

@Flavio_Costa I’m curious if you or anyone else happened to be able to get a private OAuth2 provider to federate the on-prem openhab-cloud with the Alexa Skill. I currently have an ADFS instance setup that I can use, I just don’t know how to craft the claims rule nor do I know how to craft the auth provider for openhab-cloud. Also, I’m curious as to what needs to happen within openhab-cloud’s code to make it accept claims tokens from my claims provider. Does anyone know if there’s a walk-through on how to setup OAuth2 for openhab-cloud. I can only assume this is possible since the public version does it already.

Cheers,

John

Hi John, I have never tried any integration with Alexa, and I’m not really an Alexa user.
I remember some months ago certain discussions about a (then) new action to integrate with Google Home, but I have not followed up on that afterwards so I’m not sure what the status on this is.

On the Eclipse SmartHome framework, there is some new development regarding a OAuth2 client, but I haven’t checked that yet as I am currently working on other topics. I plan to eventually go back to openhab-cloud, but that will probably still take some months.

Thanks,

Flavio

I have my own instance of openhab-cloud running, and integrated with Alexa and IFTTT.

Not sure it is the last updated version from GitHub, as I set it up a couple of months ago, but I do not dare touching it, as I had to tweak it “a bit” to make it work.

I could not find too much documentation on it (at all) so I had to hack and go through the code…

I have no time to document it, but if there is interest I can share what I did. Maybe somebody with more time than I could document a how-to then… :slight_smile:

I created a couple of JS scrips to make me “superuser” in my own openhab-cloud (no, the admin created one is not), and to define the keys and IDs for oauth. I will share these, but will take some time.

For IFTTT I had to create my own service (unpublished) creating manually the API call definitions. Takes some time, and trial and error.

For Alexa, there is a script that creates a bundle, and more or less it can be done, but it took me some time (I had no experience with AWS and lambdas), and you need to create an AWS account.

If you do not have experience on this, without a proper step by step guide it is not for newbies…

Hi All

FIXED, a reboot was all it needed.

Please could you please show us how to config the ifttt thing in cutsom oh-cloud, thank you so much!!

Hi @kevinshane,

You need to create a developer account in IFTTT (without paying I think I remember you could only use 4-5 “test” users)

Are you interested in the oh-cloud setup (setting up the oauth tokens, etc), the IFTTT part, or both? I need to document it and it may take some time. Will give it a try in the coming days in this post, but just to prioritize.

Best Regards,
Pedro

In general, to be able to add Oauth clients (amazon, google, ifttt, etc) to my OH-Cloud custom installation, I use this custom created script.

addoauth.js:

// Author: Pedro Garcia. Please feel free to redistribute and modify at wish keeping this line :)

var config = require('./config.json'),
    mongoose = require('mongoose'),
    system = require('./system'),
    MongoConnect = require('./system/mongoconnect'),
    OAuth2Client = require('./models/oauth2client'),
    OAuth2Scope = require('./models/oauth2scope'),
    mongoConnect;

clientName = process.argv[2];
clientId = process.argv[3];
clientSecret = process.argv[4];

if (!clientName || !clientId || !clientSecret) {
    console.log('openHAB-cloud: Usage: node addoauth.js <clientName> <clientId> <clientSecret>');
    process.exit(0);
}

system.setConfiguration(config);
mongoConnect = new MongoConnect(system);
mongoConnect.connect(mongoose);

client = new OAuth2Client ({
    name: clientName,                           // Client name
    clientId: clientId,                         // Client oauth2 id
    clientSecret: clientSecret,                  // Client oauth2 secret
    // homeUrl: "https://ifttt.com/channels/MyServiceName/authorize",
    // icon: String,
    // active: true,
    // created: Date.now,
    // last_change: Date.now
});

scope = new OAuth2Scope ({
    name: clientId,                             // name of the scope
    description: clientName,                    // description of what this scope permits to do
    // valid: true,
    // created: Date.now
});

console.log('Creating oauth2 scope');
scope.save(function(error) {
    if (error) console.log('Error: ' + error);
    else console.log('Scope created');
    console.log('Creating oauth2 client');

    client.save(function(error) {
        if (error) console.log('Error: ' + error);
        else console.log('Client created');
        process.exit(0);
    });
});

Create it in the base openhab-cloud directory and execute it with:

#> node addoauth.js
openHAB-cloud: Usage: node addoauth.js <clientName> <clientId> <clientSecret>

For sure there is a better way. If so, please let me know :slight_smile:

2 Likes

Hi Guys

Does this allow, once setup, your Android phone to setup a HTTPS connection to your OH2 instance? by setting up the URL of your machine under the ‘REMOTE’ part of the App?

I cant connect but can open a web browser session to https://serverurl from the internet which takes me to the openhab cloud login page.

cheers

Yes. You will need a fix IP or some other means (i.e. dynamic DNS) to resolve the name of your server. I would also strongly recommend you to use a real certificate (if you are security-aware).

You do not need anything from my previous post for this to work, anyway: it is related to integrating the custom instance with third party services through OAUTH.

But if you just want to connect remotely, and do not have a reason to run your own instance, I would also recommend you to use the openhab-cloud instance from openhab.org

Best Regards,
Pedro

HI Pedro

Ive got an ip and dns name, if i use it with port 443 as the remote server in the OH2 app, it doesn’t connect.
By using this instance, in my Android client do I configure https://url

And then in nginx, i forward to 3000? Its not very clear and this is driving me insane

Thanks!

Can anyone confirm what needs to go into here?

Hi @dastrix80,

If the cloud instance is running on the same computer or network as the openhab instance, you can address it by the local address as in the image you sent.

If the cloud instance is on Internet, you need to point to the public address (i.e. https://myhomedomain/)

Answering your previous question: yes, you need to secure your cloud server behind a proxy. I use a highly customized Apache, so I cannot help you on nginx, but there are some how-to’s and tutorials already around.

Just make sure you enable proxying of websockets requests, to avoid having your openhab instance constantly polling your cloud instance

Best regards,
Pedro

Hi Pedro

Not sure what you mean, OpenHab Cloud & OpenHab2 run locally on the same machine.

In any case, I cant remotely access the UI’s using the Local instance of OpenHab Cloud nor can I use the Android Apps to access OpenHab by configuring ‘REMOTE’ and pointing it to my https://domain, which in NGINX points towards Port 3000 of my Local OpenHab Cloud

:./

I’m at a loss and this is incredibly frustrating because theres no logs at all!

Hi @dastrix80

Then you can use the local address in the OpenHab configuration, as in the screen snapshot you have sent.

First of all, have you tried connecting from the local network directly to the oh-cloud instance from your web browser? (i.e. http://192.168.0.3:3000)

If this does not work, then the cloud instance is not running / responding (or you have a firewall)

Best Regards,
Pedro

Hi Pedro, yes it works and I can login. I also get cloud notifications however when I click the link ‘CLICK HERE TO ACCESS YOUR DASHBOARD’ it does nothing.Thanks

Hi @dastrix80,

What does “does nothing” mean? Also, could you please try these to see if we can find some clues on what the issue is?

  • To what URL is the link “Click here to…” pointing to? Can you access the same URL directly on the OH instance?
  • Is the rest api responding through the OH-cloud instance? (i.e. ask for ‘/rest/sitemaps’ or ‘/rest/this-is-an-error’)
  • What is the contents of your “system” section in the “config.json” file? Host, port and protocol should match the URL you plan to reach your oh-cloud instance with.

Best Regards,
Pedro

Hi Pedro

I made changes to config.json, the dashboard link now works. However I still cannot connect using the Android App. It pops up the list of sitemaps, but it wont display their contents

It works fine on a PC

Cheers

Hi All

Does anyone use Habpanel with openhab cloud? If so, does your constantly keep asking for the username/password to login?

Thanks!

THis is driving me mental and I dont know how to resolve it. Nginx doesnt appear to be the issue. Any thoughts?

This should read:
sudo apt-get install nginx