Skip to content

Creates an Ambilight effect by syncing Home Assistant lights with your monitor’s colors and brightness.

License

Notifications You must be signed in to change notification settings

SonOfSkywalker/lights_sync_home_assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sync Home Assistant Lights to your monitors

Creates an Ambilight effect by syncing Home Assistant lights with your monitor’s colors and brightness.

Demo

Sync Home Assistant Lights to your monitors

Requirements

  • Python 3.9 or higher
  • mss: for capturing screen content
  • Pillow: for processing images
  • requests: for interacting with the Home Assistant API
  • pyyaml: for reading the YAML configuration file
  • python-dotenv: for loading environment variables securely

Setup

1. Install Python Dependencies

Make sure you have Python 3.x installed, then install the required dependencies using pip:

pip install -r requirements.txt

2. Create a .env File

Create a .env file in the root directory of the project and add the following environment variables:

HASS_URL=http://<YOUR_HOME_ASSISTANT_URL>:<PORT>
HASS_TOKEN=<HOME_ASSISTANT_ACCESS_TOKEN>
CONFIG_PATH=<PATH_TO_YOUR_CONFIG_FILE>

To create a token in Home Assistant, follow the instructions below.

  1. Go to the profile page
  2. Click on the Security tab, then find Long-lived Access Tokens.
  3. Click "Create Token"
  4. Use it ;)

3. Create a Configuration File

Create a YAML file with the configuration for your lights. The configuration file should have the following structure:

monitors:
  main:
    lights:
      - light_id: "light.light_1"
        screen_area: "bottom_right"
      - light_id: "light.light_2"
        screen_area: "whole_screen"

  secondary:
    lights:
      - light_id: "light.light_3"
        screen_area: "bottom_left"

number_of_updates_per_second: 10
brightness_boost: 1.5
  • monitors: A dictionary where each key is the name of a monitor and the value is a list of lights that should be controlled by that monitor.

    • lights: A list of dictionaries where each dictionary contains the light_id of a light in Home Assistant and the screen_area that the light should be based on.
      • light_id: The entity ID of the light in Home Assistant.
      • screen_area: The area of the screen that the light should be based on. Possible values are whole_screen, top_left, top_right, bottom_left, bottom_right
  • number_of_updates_per_second: The number of times per second that the screen should be captured and the lights should be updated. Lower this value if your CPU is dying.

  • brightness_boost: A multiplier to increase the brightness of the lights.

4. Run the Script

Run the script using the following command:

python main.py

How It Works

  1. The script captures the screen content using the mss library.
  2. The average color and brightness of the screen are calculated.
  3. The script sends a request to the Home Assistant API to update the color and brightness of the lights.

Known limitations

Troubleshooting

  • If you encounter any issues, please open an issue on GitHub.

About

Creates an Ambilight effect by syncing Home Assistant lights with your monitor’s colors and brightness.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages