GithubHelp home page GithubHelp logo

rtyle / connect-things Goto Github PK

View Code? Open in Web Editor NEW
4.0 3.0 1.0 200 KB

Connect your (Legrand Adorne) things for external (e.g. SmartThings) control

License: GNU Lesser General Public License v3.0

JavaScript 100.00%
upnp legrand adorne artik-cloud lc7001 smartthings upnp-connect rflc smartthings-hub smartthings-schema-connector st-schema

connect-things's Introduction

connect-things

Connect your things.

This supports a general architecture for providing connections to things. The only things realized now are Switch and Dimmer devices reachable through a local Legrand Adorne LC7001 hub.

The Legrand Adorne Wi-Fi Ready Switch, Dimmer Switch and Outlet devices will be discovered as device URNs

  • schemas-upnp-org:device:BinaryLight:1
  • schemas-upnp-org:device:DimmableLight:1

Which correspond to

The only connections realized now are a UPnP connection through a SmartThings hub and a SmartThings Cloud Connector Schema App.

This project may be used to replace SmartThings to Legrand Adorne LC7001 hub integration through Samsung’s ARTIK Cloud. Samsung has abandoned the ARTIK Cloud and Legrand has no plans to provide an alternative. This is an alternative.

Installation

connect-things is a JavaScript application that expects to be run in a nodejs environment. It was developed using, at the time, the Latest LTS Version: 12.18.3 of nodejs. connect-things can be installed by git and the Node Package Manager npm. You can use these, as a normal user, to install connect-things with all of its dependencies:

git clone https://github.com/rtyle/connect-things
(cd connect-things; npm install)

To inspect the connect-things command line options and run it:

node . --help
node .

UPnP Connect Through a SmartThings Hub

This can be disabled with the --disable upnp command line option.

A companion project is upnp-connect which connects these things through a local SmartThings hub to SmartThings device types with Switch and SwitchLevel capabilities.

Since only the SmartThings hub will need access, it is recommended to exclude all others ...

node . --upnp-host smartthings.home

... where smartthings.home resolves to the SmartThings hub (use IP address otherwise).

SmartThings Cloud Connector Schema App

This can be disabled with the --disable c2c command line option.

Assuming that SmartThings will not be able to reach the connect-things service directly, an ngrok (or equivalent) tunnel to it will be required. We assume that ngrok is used here. One side of the tunnel should target the port (default, 8081) of the connect-things host/service and the other side of the tunnel should be identified reliably with your custom subdomain. For example, on the host running connect-things,

ngrok http -subdomain=yoursubdomainhere 8081

Replace yoursubdomainhere (above and below) with your chosen, unique, reliable custom subdomain. Every/any time that this changes you will need to update old/invalid references (For example, Target URL and Token URI, below). That is why it is best if you can ensure that such will never change. Likewise, if you move away the ngrok service (or ngrok otherwise breaks old/invalid references), such will have to be updated.

The SmartThings Developer Workspace must be used to create a project. The new project should be created for this Device Integration with a SmartThings Cloud Connector of type SmartThings Schema Connector. After naming your project, the next step will be to Register App of the Cloud Connector. It will be a Webhook Endpoint with a Target URL of

https://yoursubdomainhere.ngrok.io/c2c/resource

Set up the credentials required to access the cloud which hosts the devices. Follow the instructions in etc/c2cClientLocal.js to generate (and remember) your own unique id and secret for the connect-things (local) client and use these to fill in the Client ID and Client Secret fields.

The Authorization URI need only be reachable from the device running the SmartThings app used to onboard connect-things. It is most secure (and advised) if this device is reachable on the same LAN as the connect-things host. For example ...

https://connect-things.home:8082/c2c/oauth2/authorize
  • where connect-things.home resolves to the host running connect-things (use IP address otherwise),
  • connect-things is running an http service on port 8081 (default)
  • and an https service on the next port (8082), dedicated to phone.home, which will only be so if run with the
--c2c-auth phone.home

option where phone.home resolves to the host running the SmartThings app (use IP address otherwise) used to onboard connect-things.

The Token URI must be reachable from SmartThings.

https://yoursubdomainhere.ngrok.io/c2c/oauth2/token

The optional OAuth Scope(s) should be left empty.

Next, fill in the App Display Name with, say connect-things and choose a logo, say connect-c2c-things.png

Copy the your own unique SmartThings (remote) Client ID and Client Secret and paste (remember) them into etc/c2cClientRemote.js.

You can then Deploy to Test.

Run connect-things for first-time onboarding.

cat README.certificates # and follow directions
rm -f etc/c2cCallbackAuthentication.json
rm -f etc/c2cCallbackUrls.json
node . --c2c-oauth phone.home

The certificate created is used for the connect-things https service and its private key is also used to sign JWT tokens. Any etc/c2cCallback*.json files are removed first because they will be overwritten as part of establishing a new relationship with SmartThings. Old content will probably not work.

From the SmartThings app (run on phone.home), enable Developer Mode then add (+) a Device by device type. Scroll to the bottom and click My Testing Devices. Under My setup apps, click connect-things. Select the Location and Room that devices will be added to and click Next.

The local SmartThings app will not automatically trust the self-signed certificate created above so you must tell it to. The local SmartThings app should automatically be authenticated and tokens should be exchaged between connect-things and SmartThings.

Connection between SmartThings and connect-things is successful
Close this page to finish setup.

Close the page.

Successfully connected to connect-things.

Click Done.

As there is no longer a need for authentication (access tokens have been exchanged and can be refreshed), connect-things should be restarted without the --c2c-oauth phone.home option.

node .

SmartThings will be told as new devices are discovered by connect-things and will immediately support them.

To remove this integration, click on any of its devices to ...Edit it, go to Linked Services and ...Delete it (-).

Automatic Run

From the connect-things host, change directory to where it is installed.

One should be able to make this run automatically in most environments. It has been tested to run on Linux.

Run as a Linux systemd service

As root,

cp etc/connect-things/connect-things.service /etc/systemd/system/

Read this file for further instructions.

Google will offer help running ngrok automatically with systemd.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.