Harmonize Project connects Philips Hue lights and lightstrips to your TV screen content, creating an amazing ambient lighting effect! This application utilizes a low-latency video and color analysis algorithm developed with Python and OpenCV.
Check out our Reddit thread here and watch the demo below! Electromaker explains how our application works at a high level in his podcast here!
Harmonize Project (formerly known as Harmonize Hue) has no affiliation with Signify or Philips Hue. Hue and Philips Hue are trademarks of Signify.
Thank you to all those who have contributed to this project. Please keep your pull requests coming!
Lights:
Minimum Hardware:
Example Hardware configuration (tested successfully unless otherwise noted below):
Software Setup:
Ubuntu Desktop 24.04 LTS 64-bit with Python v3.12 (most recent version tested)
Install the Raspberry Pi Imager software (see https://www.raspberrypi.org/software/) on a separate computer with an available SD card slot/adapter. Insert an SD card with at least 32GB capacity with decent read/write speeds.
Launch the imager and select the Raspberry Pi device type, Ubuntu Desktop 64-bit OS, and the storage location for the SD card. Click Next.
After the OS has been installed, insert the SD card into the RPi and boot.
Install all dependencies via the following commands. Be sure to watch for errors!
Install pip (will also install gcc and g++ C-compilers as dependencies):
sudo apt-get install python3-pip
Install Snap:
sudo apt install snapd
Install Avahi (multicast DNS daemon):
sudo snap install avahi
Install Screen (SSH multiple window manager):
sudo apt install screen
Install pipx Github reference:
sudo apt install pipx
pipx ensurepath
Install virtualenv:
pipx install virtualenv
Create virtual environment and activate:
virtualenv --python=python3.12 ~/harmonize_env
source ~/harmonize_env/bin/activate
Install NumPy, zerconf, requests, and termcolor Python dependencies via pip:
pip install numpy=1.26.4 zeroconf requests termcolor
Compile and install OpenCV 4.10.0 from source - Follow this guide... Compiling may take a couple of hours depending on the capabilities of your system. Note that if you upgrade Ubuntu to a new release you may need to completely uninstall, recompile, and reinstall OpenCV. Note: As of June 16, 2024, numpy 2.0.0 is available, but this project will plan to use 1.26.4 until a minor upgrade release of numpy 2.1 is available.
sudo apt install cmake
sudo apt install python3-dev python3-numpy libpython3-all-dev
sudo apt install libavcodec-dev libavformat-dev libswscale-dev
sudo apt install libgstreamer-plugins-base1.0-dev libgstreamer1.0-dev # to be used for GStreamer support
sudo apt install libgtk-3-dev
sudo apt install wget git
wget -O opencv.zip https://github.com/opencv/opencv/archive/4.10.0.zip
unzip opencv.zip
mv opencv-4.10.0 opencv
mkdir -p build && cd build
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_opencv_java=OFF -D BUILD_opencv_python2=OFF -D BUILD_opencv_python3=ON -D PYTHON_DEFAULT_EXECUTABLE=$(which python3) -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=OFF -D BUILD_EXAMPLES=OFF -D WITH_CUDA=OFF -D WITH_GSTREAMER=ON -D BUILD_TESTS=OFF -D BUILD_PERF_TESTS=OFF ../opencv
make -j4
sudo make install
cd ..
sudo ln -s /usr/local/lib/python3.12/site-packages/cv2 /home/bdworak/harmonize_env/lib/python3.12/site-packages/cv2
git clone https://github.com/MCPCapital/HarmonizeProject.git
Legacy Software Setup (currently unsupported and not maintained):
Download the latest scripts and install all dependencies via the following commands. Be sure to watch for errors! You will need about 1GB of free space. The script can run for up to an hour.
git clone https://github.com/MCPCapital/HarmonizeProject.git
cd HarmonizeProject
sudo ./setup.sh
Hardware Setup Example A:
Hardware Setup Example B (for A/V receivers with 2 or more HDMI outputs):
Entertainment Area Configuration:
First-Time Run Instructions:
To start the program:
screen
cd HarmonizeProject
source ~/harmonize_env/bin/activate
./harmonize.py
(ex. maximum brightness and auto-restart after 8 seconds of missed frames) ./harmonize.py -l 0 -a 8
screen -r
Command line arguments:
-v
Display verbose output-g #
Use specific Entertainment area group number (#)-b <id>
Use specified bridge ID-i <ip>
Use specified bridge IP address-s
Enable latency optimization for single light source centered behind display-w #
Sets the video device wait time to the specified value, in seconds. Defaults to 0.75.-f <file/url>
Use the specified file or URL video stream instead of a video device.-l [0-255]
Decrease brightness from 0 to 255 (0 is maximum brightness, default is 30).Configurable values within the script: (Advanced users only)
breadth
- determines the % from the edges of the screen to use in calculations. Default is 15%. Lower values can result in less lag time, but less color accuracy.time.sleep(0.015)
- Determines how frequently messages are sent to the bridge. Keep in mind the rest of the function takes some time to run in addition to this sleep command. Bridge requests are capped by Philips at a rate of 60/s (1 per ~16.6ms) and the excess are dropped.nice
command to give Harmonize higher priority over other CPU tasks.python3 ./videotest.py
to see if your device (via OpenCV) can properly read the video input.-w
argument *This is a known bug (race condition).ls -ltrh /dev/video*
should provide a list of results that includes /dev/video0 when the OS properly detects the video capture card.Pull requests are encouraged and accepted! Whether you have some code changes or enhancements to the readme, feel free to open a pull request. Harmonize Project is licensed under The Creative Commons Attribution-NonCommercial 4.0 International Public License.
Development credits to Matthew C. Pilsbury (MCP Capital LLC), Ares N. Vlahos, and Brad Dworak.