Skip to content

Http Server for controlling Hue Lights, with a Hue Bridge, designed to integrate shelly relays and hue bridge, Tested with Node.js v18.13.0 and 4 lights

License

Notifications You must be signed in to change notification settings

Gorlenah/Http-Server-for-Hue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Http-Server-for-Hue

The project arose from the need to control Philips Hue lights in a local network isolated from the internet, allowing them to be controlled via network protocol via shelly relays (IoT) thus leaving the lights always powered by the AC network, this configuration was tested on a server with Node.js, the server receives GET requests from a client (via HTTP) which sends commands to the hue bridge according to its API, via https (http is not allowed by the bridge, whereas shelly requires http)

This allows unlimited functionality of commands according to the Hue API, hence the project is expandable

In case of further tests I will try to publish them here on GitHub

How to start with HUE API : https://developers.meethue.com/develop/get-started-2/


With the latest update you can find the settings essential for server operation in PARAMETERS :

parameters

You only have to change the data in upper case and highlighted, with your data, depending on your configuration, the api key can be obtained by following the philips guide

Without these parameters the server cannot function!!!

  • HUE-API-KEY: api key for hue bridge access
  • HUE-BRIDGE-IP: hue bridge ip, recommended to have it static
  • SERVER-IP: ip on which you want the server to respond
  • title: server graphic title
  • myTimezone: represents the timezone in which the lights are to be controlled, it will be useful in the event of an update, for now it is not necessary for correct operation
  • lightsArray: contains the identification numbers of the lights to be controlled (each number must be separated by a comma, except the last)

Browser Example:

browser-ex

Console Example:

console-ex


Persistent Server

This Project can be implemented as a persistant server (always running even after server reboot)

I implemented in my Ubuntu Server with CronTab but you can use other methods

What you have to do?

  1. Insert in CronTab new scripts, sudo EDITOR=nano crontab -e will open crontab as root with nano editor
  2. Add CronTab rule for reboot @reboot sleep 60 && /home/<your-username>/startServerHue.sh > /dev/null 2>&1
  • with reboot you tell crontab to execute on every boot
  • with sleep 60, tells to execute the command after 60 seconds from the boot
  • /home/username/startServerHue.sh path to your script (command)
  • /dev/null 2>&1 don't log STD, you can change /dev/null to /home//log.txt to log crontab errors
  1. Write Your Script in the path choosen before, EX:
#!/bin/bash
nodemon /home/fc/Downloads/Http-Server-for-Hue-main/hue.js > /home/fc/Downloads/Http-Server-for-Hue-main/logHue.txt
  • I used nodemon but you can use node
  • > /home/fc/Downloads/Http-Server-for-Hue-main/logHue.txt logs STDOUT to file, so you can see errors and logs

I will put my test files in the persistance folder, look at the repo, with those i runned 2 servers


My Crontab example:

persistance


Integration with shelly relays

You can integrate this project via the I/O URL function, present in shelly relays

shelly example

I recommend to run the relay in detatched mode, so as to keep the hue lights always powered, the button or switch instead will communicate with the server to control the lights via the hue bridge, from field tests, with a server plugged into the local network, the response time is comparable to a direct relay


Potential Problems

On Server, Port occupied by the same process or others, e.g.:

launch with node /YOUR-PATH/hue.js &

Immagine 2023-01-17 184903

To check PID port utilization use : lsof -i :3000 will return a list of PID using that port on linux

kill -9 (PID) to kill that process and free your Server Port

Use cmd+C to close the process, so you don't have to kill it by PID


Depending on the configuration of your server environment, you may have to change the application start-up to make it persistent

About

Http Server for controlling Hue Lights, with a Hue Bridge, designed to integrate shelly relays and hue bridge, Tested with Node.js v18.13.0 and 4 lights

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published