Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • Philips Hue Bride available in network

  • Node.js installed

  • Node.js node-hue-api package installed

How to install node-hue-api

In order to install the node-hue-api execute the following command in your shell or cmd:

Code Block
npm install -g node-hue-api

Creating a local user

In order for the Q-Server Central Core to communicate with the hue bridge we will need to create a local user. Please note, that the username should be treated as a password since it provides complete control over the devices, which are connected to the hub.

Create a new file with the name registerUser.js in a directory of your choice.
Paste the following code into this file:

Code Block
languagejs
const v3 = require('node-hue-api').v3
  , discovery = v3.discovery
  , hueApi = v3.api 
;

const appName = 'quantum-hue';
const deviceName = 'qserver';

async function discoverBridge() {
  const discoveryResults = await discovery.nupnpSearch();

  if (discoveryResults.length === 0) {
    console.error('Failed to resolve any Hue Bridges');
    return null;
  } else {
    // Ignoring that you could have more than one Hue Bridge on a network as this is unlikely in 99.9% of users situations
    return discoveryResults[0].ipaddress;
  }
}

async function discoverAndCreateUser() {
  const ipAddress = await discoverBridge();

  // Create an unauthenticated instance of the Hue API so that we can create a new user
  const unauthenticatedApi = await hueApi.createLocal(ipAddress).connect();
  
  let createdUser;
  try {
    createdUser = await unauthenticatedApi.users.createUser(appName, deviceName);
    console.log('*******************************************************************************\n');
    console.log('User has been created on the Hue Bridge. The following username can be used to\n' +
                'authenticate with the Bridge and provide full local access to the Hue Bridge.\n' +
                'YOU SHOULD TREAT THIS LIKE A PASSWORD\n');
    console.log(`Hue Bridge User: ${createdUser.username}`);
    console.log(`Hue Bridge User Client Key: ${createdUser.clientkey}`);
    console.log('*******************************************************************************\n');

    // Create a new API instance that is authenticated with the new user we created
    const authenticatedApi = await hueApi.createLocal(ipAddress).connect(createdUser.username);

    // Do something with the authenticated user/api
    const bridgeConfig = await authenticatedApi.configuration.getConfiguration();
    console.log(`Connected to Hue Bridge: ${bridgeConfig.name} :: ${bridgeConfig.ipaddress}`);

  } catch(err) {
    if (err.getHueErrorType() === 101) {
      console.error('The Link button on the bridge was not pressed. Please press the Link button and try again.');
    } else {
      console.error(`Unexpected Error: ${err.message}`);
    }
  }
}

// Invoke the discovery and create user code
discoverAndCreateUser();

Press the Link Button on the Hue Bridge.
Execute the script by opening a terminal or cmd in the directory you placed the script into and execute:

  • Windows

    • node .\registerUser.js

  • Mac/Linux:

    • node ./registerUser.js

The output should look like this:

...

Make sure to note these credentials temporarily in order to use them in the Gateway setup. You can dispose of them afterwards.

Activating Hue Gateway

Navigate to the marketplace on your Q-Server Central Core and activate the Hue Gateway.
You should be greeted with a setup dialog:

...

Fill in the information that the script gave to you earlier.

...

When everything went successful you should see your lights come up as devices in your Clients overview.

...

  • Quantum Q-Server Central Core setup on the same network as your Hue Bridge

Activating the Hue Gateway

Navigate to the Library on your Q-Server Central via the toolbar on the left hand side of your screen.

...

Next, click on the Gateways Tab.

...

Hit the Download button beneath the Philips hue gateway.

...

You should receive a notification that the Hue Gateway has downloaded successfully.

...

Again, using the toolbar on the left hand side of the screen navigate to the Gateways page.

...

Now, select the Start function from the Actions drop down menu.

...

The gateway will automatically find the IP of your Hue Bridge. Once it does, hit the link button on your Hue and then click next.

...

Your username should be automatically filled in by the gateway.

...

Again, click the next button and finish by clicking the Activate button on the following page.

...

Now you can navigate to your Clients page to see a list of all of the Hue devices that are connected to your system.

...