"Philips Ambilight for desktops". A tool to generate color palettes from your desktop wallpaper and send them to Home Assistant.

Overview

Desktop Dye

DesktopDye is an open source project written in Rust that allows users to have their lights paired with Home Assistant adjust to the most dominant color on their computer screen, similar to how Philips Ambilight works with their TVs. This README file provides instructions on how to install and use DesktopDye.

Usage

Install DesktopDye

  1. Install Rust if you haven't already. You can download it from the official Rust website: https://www.rust-lang.org/tools/install.
  2. Clone the repository from GitHub using git clone https://github.com/jeroen-meijer/desktop_dye.
  3. Navigate to the cli folder using cd desktop_dye/cli, and then install the DesktopDye CLI by running cargo install --path ..
  4. Run the cli once using desktop_dye_cli. This will create a config file in <USER_DIR>/.desktop_dye/config.yaml. For Windows users, the user directory is usually C:\Users\<USERNAME>\.desktop_dye\. For macOS/Linux users, this will most likely be ~/.desktop_dye/.

Set up Home Assistant

Four things need to be done to set up Home Assistant to support DesktopDye.

Create an access token.

  1. Go to your Home Assistant dashboard and log in.
  2. Then, go to your profile, scroll down and create a new Home Assistant access token. Copy the token and save it somewhere for use later.

Create a light group (optional, but recommended).

This light group will contain the lights that will change based on the screen's color.

  1. In your Home Assistant dashboard, go to Settings -> Devices & Services -> Helpers, and create a new helper of type Group -> Light group. Give it any name you want, then add the lights that you want to control with DesktopDye. We recommend keeping "Hide members" turned OFF.
  2. Make a note of the entity ID of your newly created light group and save it somewhere for later.

Create a text input helper.

This will be the text field that DesktopDye will send new color values to, which an automation (made in the next step) will use to control the light group made in the previous step.

In the same Helpers menu as before, create a Helper of type Text. Give it an easily recognizable name and take note of the entity ID for later.

Create an automation.

This is the automation that will be triggered when the Text helper's value is changed by DesktopDye, and should change the state of the light group from before to the values in the text field.

  1. In your Home Assistant dashboard, navigate to Settings -> Automations & Scenes, and create a new automation. Name it something easy to remember.
  2. Click the menu in the top right, select "Edit in YAML" and paste the following template into the YAML editor. Edit the input_text.YOUR_TEXT_INPUT_ENTITY and light.YOUR_LIGHT_GROUP parts to match the entity IDs of your text input helper and light group, respectively.
alias: 'Desktop Dye Client'
description: ''
trigger:
  - platform: state
    entity_id:
      - input_text.YOUR_TEXT_INPUT_ENTITY
condition: []
action:
  - service: light.turn_on
    target:
      entity_id: light.YOUR_LIGHT_GROUP
    data:
      transition: 2
      rgb_color:
        - >-
          {{ states.input_text.YOUR_TEXT_INPUT_ENTITY.state.split("
          ")[0].split(",")[0] }}
        - >-
          {{ states.input_text.YOUR_TEXT_INPUT_ENTITY.state.split("
          ")[0].split(",")[1] }}
        - >-
          {{ states.input_text.YOUR_TEXT_INPUT_ENTITY.state.split("
          ")[0].split(",")[2] }}
      brightness_pct: >-
        {{ states.input_text.YOUR_TEXT_INPUT_ENTITY.state.split("
        ")[0].split(",")[3] }}
mode: single

Edit the config file

  1. Open the config file located in <USER_DIR>/.desktop_dye/config.yaml. Again, for Windows users, this will most likely be C:\Users\<USERNAME>\.desktop_dye\. For macOS/Linux users, this will most likely be ~/.desktop_dye/.
  2. Update the following settings in the config file:
  • ha_target_entity_id: Enter the entity ID of the light group helper you created earlier
  • ha_token: Enter the Home Assistant access token you created earlier
  • ha_endpoint: Verify that this is the correct endpoint for your Home Assistant setup. By default, this should be http://homeassistant.local:8123.
  1. Save and close the config file.

Done! ๐ŸŽ‰

Congratulations, you have successfully set up DesktopDye! You can now run the CLI by running desktop_dye_cli in your terminal. If you want to run it in the background, you can use a tool like tmux.

The Config File

The DesktopDye config file contains various settings used to control the behavior of the CLI. The config file is located in <USER_DIR>/.desktop_dye/config.yaml. Again, for Windows users, this will most likely be C:\Users\<USERNAME>\.desktop_dye\. For macOS/Linux users, this will most likely be ~/.desktop_dye/.

The default config file contains fields for all available settings, and looks like this:

# The ID of the screen to capture colors from.
# Is optional. If not specified, the screen primary screen is used.
# Run the application to see a list of screens and their IDs.
screen_id:

# The endpoint of the Home Assistant instance to send the colors to.
# This can usually be set to http://homeassistant.local:8123
# Is required. If not specified, the application will not start.
ha_endpoint: http://homeassistant.local:8123

# The API token to use to authenticate with Home Assistant.
# Is required. If not specified, the application will not start.
ha_token:

# The Home Assistant entity ID to send the colors to.
# This should be a text helper entity, and will usually start with 'input_text.'
# Is required. If not specified, the application will not start.
ha_target_entity_id:

# The amount of colors to sample and send to Home Assistant.
#
# Note that, depending on the algorithm used, the amount of colors sent may be less than
# this value.
#
# Is optional. If not specified, the application will sample 3 colors per capture.
# Must be between 1 and 10 (inclusive).
sample_size: 3

# The algorithm to use to select the colors to send to Home Assistant.
#
# There are two algorithms:
# - 'color_thief': A fast algorithm that selects the most dominant colors.
#   This is the default algorithm, and is relatively accurate for most use cases.
# - 'pigmnts': A slower algorithm based on the kmeans-algorithm that selects the
#    most dominant colors. Though generally slightly more accurate, it is also
#    significantly slower and not recommended for most use cases.
#
# Is optional. If not specified, the default 'color_thief' algorithm is used.
algorithm: color_thief

# The amount of seconds to wait between color captures.
#
# In other words, every this many seconds, the application will capture the colors on the
# screen, and send them to Home Assistant (if it is not already sending colors, and if the
# colors have changed).
#
# Is optional. If not specified, the application will capture colors every 3 seconds.
capture_interval: 3.0

# Selects the mode of color selection.
#
# This determines what colors are sent to Home Assistant, and in what order.
#
# There are three modes:
# - 'default': Orders the colors by occurrence, with the most dominant color first.
# - 'brightest': Orders the colors by brightness, with the brightest color first.
# - 'hue_shift': A special mode where a set of hues around the most dominant color are sent,
#    creating a gradient. In this mode, the primary color is not sent first, and may not
#    be sent at if the amount of colors in the gradient is an even number.
#
# Is optional. If not specified, the default mode is used.
mode: default

# Determines the amount of degrees of shift to use when selecting hues.
#
# This is only used when the mode is set to 'hues'.
#
# This value is used to shift the primary color to the left and right, creating a gradient.
# For example, if this is set to 45.0, the primary color will be shifted 45 degrees to the
# left and right, creating a gradient with a width of 90 degrees (with the primary color
# in the middle).
#
# Is optional. If not specified, the default value of 45.0 degrees is used.
hue_shift: 45.0

# Determines the format in which the colors are sent to Home Assistant.
#
# There are two formats:
# - 'rgb': The colors are sent as a comma-separated list of RGB values.
#   RGB values consist of three components; red, green, and blue,
#   and are integers in the range of 0-255 (inclusive).
#   Example: "255,255,0 255,0,0 0,255,0"
# - `rgbb`: The colors are sent as a comma-separated list of RGB values, with a brightness
#   component at the end. This is the default format.
#   The RGB values are integers in the range of 0-255 (inclusive), while
#   the brightness value is a float in the range of 0.0-100.0 (inclusive).
#   This is useful since Home Assistant devices generally don't support setting the brightness
#   through the RGB values, and instead require a separate brightness value.
#   Example: "255,255,0,100.0 255,0,0,100.0 0,255,0,100.0"
# - `hsb`: The colors are sent as a comma-separated list of HSB (hue, saturation, brightness)
#   values. While this format is more accurate, it is also more difficult to work with in
#   Home Assistant, and can lead to unexpected results in color accuracy. However, this is
#   the only format that supports setting a specific brightness for Home Assistant lights,
#   which the RGB format does not support.
#   HSB values are in the range of floats 0.0-360.0 for hue and floats 0.0-100.0 for the
#   saturation and brightness.
#   Example: "60.0,100.0,100.0 0.0,100.0,100.0 120.0,100.0,100.0"
#
# Is optional. If not specified, the default format (`rgbb`) is used.
color_format: rgbb

# Determines the factor by which to increase the brightness of every color.
#
# If provided, the brightness of every color is multiplied by this value. This
# is useful if the colors are too dark, or if the brightness of the colors is
# not sufficient for your lighting setup.
#
# Note that brightness values are clamped to the range of 0.0-100.0 (inclusive).
# Setting this value lower than 1.0 will decrease the brightness of the colors,
# while setting it to 0.0 will result in all colors being black.
#
# Example:
# - brightness_factor = 0.5, base brightness = 50.0, result = 25.0
# - brightness_factor = 2.0, base brightness = 50.0, result = 100.0
# - brightness_factor = 2.0, base brightness = 75.0, result = 100.0 (clamped)
#
# Is optional. If not specified, it is set to 1.0, which means no brightness
# adjustment is performed.
brightness_factor: 1.0

Uninstalling

To uninstall DesktopDye, follow these steps:

  1. Stop any running instances of desktop_dye_cli.
  2. Run cargo uninstall desktop_dye_cli in your terminal to uninstall the CLI.
  3. Delete the DesktopDye folder in the directory where you cloned the repository.
  4. Delete the config file in <USER_DIR>/.desktop_dye/config.yaml.

Troubleshooting

Colors aren't changing

If the colors of the lights in your light group aren't changing, make sure that:

  1. The Home Assistant automation you created is enabled and correctly set up.
  2. The entity ID of your light group and your text input helper are correctly set in the config.yaml file.
  3. The Home Assistant access token in the config.yaml file is correct.

desktop_dye_cli won't start on macOS

If you are on macOS and desktop_dye_cli won't start, it is likely because it needs permission to capture screenshots. You can grant it permission by going to System Preferences -> Security & Privacy -> Privacy -> Screen Recording, and then adding desktop_dye_cli to the list of apps allowed to capture screenshots.

desktop_dye_cli won't start on Linux

If you are on Linux and desktop_dye_cli won't start, it is likely because it needs permission to read the screen. You can grant it permission by running the following command:

$ which desktop_dye_cli
## Take note of the path to the desktop_dye_cli binary, then run the following command.

sudo setcap cap_sys_admin+ep path/to/desktop_dye_cli
## Replace path/to/desktop_dye_cli with the actual path to the binary from the first command.

Contributing

If you find a bug or have a feature request, please file an issue on the GitHub repository.

If you want to contribute to the code, please submit a pull request. Contributions are welcome and appreciated.

License

DesktopDye is licensed under the MIT license. See LICENSE for more information.

You might also like...
The easiest way to search for images on your desktop ๐Ÿ”Ž
The easiest way to search for images on your desktop ๐Ÿ”Ž

What is ByteDetective? ByteDetective is a desktop app (currently available for MacOS) that acts as a semantic search engine for your photos. The aim i

Rust crate for creating filters with DirectX shaders. Includes Scale, Color conversion using DirectX api.

DxFilter Scale and ColorConversion done with DirectX filters. You can also create your own filters with the provided api. Crate contains various tools

Generate commit messages using GPT3 based on your changes and commit history.
Generate commit messages using GPT3 based on your changes and commit history.

Commit Generate commit messages using GPT-3 based on your changes and commit history. Install You need Rust and Cargo installed on your machine. See t

๐Ÿ“ Generate your README.md from Rust doc comments

cargo-onedoc ๐Ÿ“ Generate README.md from doc comments. Only write your documentation once! This crate provides a Cargo subcommand that can generate Mar

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.
Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Fusion is a cross-platform App Dev ToolKit build on Rust . Fusion lets you create Beautiful and Fast apps for mobile and desktop platform.

Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient.

Bolt โšก Bolt is a desktop application that is designed to make the process of developing and testing APIs easier and more efficient. Quick start ๐Ÿ‘ฉโ€๐Ÿ’ป

๐Ÿ’ซ Small microservice to handle state changes of Kubernetes pods and post them to Instatus or Statuspages

๐Ÿ’ซ Kanata Small microservice to handle state changes of Kubernetes pods and post to Instatus ๐Ÿค” Why? I don't really want to implement and repeat code

๐Ÿ”ฎ ChatGPT Desktop Application (Mac, Windows and Linux)
๐Ÿ”ฎ ChatGPT Desktop Application (Mac, Windows and Linux)

ChatGPT ChatGPT Desktop Application ๐Ÿ“ฆ Install ๐Ÿ“ Update Log ๐Ÿ•’ History versions... Windows From our github releases: ChatGPT_0.7.4_x64_en-US.msi Or i

NewBin Desktop Application (Mac, Windows and Linux)
NewBin Desktop Application (Mac, Windows and Linux)

NewBing NewBing Desktop Application (Windows Mac Linux) Install Windows NewBing_0.0.1_x64_en-US.msi Mac NewBing_0.0.1_x64.dmg Usage Recommended Rust (

Owner
Jeroen Meijer (Jay)
Call me Jay. Software Developer, passionate about TypeScript and Flutter, like to help out other people. Admin and maintainer for @fluttercommunity
Jeroen Meijer (Jay)
Create virtual serial ports, connect them to physical serial ports, and create routes between them all.

Virtual Serial Port Router (vsp-router) Create virtual serial ports, connect them to physical serial ports, and create routes between them all. vsp-ro

Rob Donnelly 3 Nov 24, 2022
League Of Legends Assistant.

Lola Lola is League Of Legends Assistant. Features Auto get runes and spells lane of champion selecting. You can faster apply it with click button. Al

Jinker 13 Nov 3, 2022
Generate enum from a trait, with converters between them

Derive macro for Rust that turns traits into enums, providing tools for calling funtions over channels

Vitaly Shukela 16 Nov 3, 2022
A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems

A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)

houseme 5 Oct 6, 2022
An ActivityPub home server written in Rust, implementing the Mastodon API.

Tafarn An ActivityPub home server written in Rust, implementing the Mastodon API. At present no web UI is provided, the API is the only way to interac

โœจ Q (it/its) โœจ 12 Jan 22, 2023
A tool to subscribe to Twitch channels and store them efficiently on disk

twitch-messages A tool to subscribe to Twitch channels and store them efficiently on disk Build the Tools You can start by building the binaries that

Clรฉment Renault 1 Oct 31, 2021
An opinionated, practical color management library for games and graphics.

colstodian An opinionated color management library built on top of kolor. Introduction colstodian is a practical color management library for games an

Gray Olson 27 Dec 7, 2022
A lean, minimal, and stable set of types for color interoperation between crates in Rust.

This library provides a lean, minimal, and stable set of types for color interoperation between crates in Rust. Its goal is to serve the same function that mint provides for (linear algebra) math types.

Gray Olson 16 Sep 21, 2022
๐Ÿฆธโ€โ™‚๏ธ Recast migrates your old extensions to AndroidX, making them compatible with the latest version of Kodular.

Recast Recast helps make your old extensions compatible with Kodular Creator version 1.5.0 or above. Prerequisites To use Recast, you need to have Jav

Shreyash Saitwal 13 Dec 28, 2022
Ditch your status bar for some snazzy desktop notifications.

citron Ditch your panel for some snazzy desktop notifications. citron is: a non-intrusive alternative to status bars. on-demand, i.e. does not run in

Aziz Ben Ali 1 Jan 11, 2022