Setup
This tutorial will show you how to setup the Quantum Hue Gateway
What you will need:
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:
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:
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.