Metadata-Version: 2.4
Name: lumen-hue
Version: 1.1.0
Summary: Desktop control for Philips Hue (Wayland/Hyprland) via the local CLIP v2 API, with screen-sync ambilight
Author: Pierre Sylla
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/PierreSylla/Lumen
Project-URL: Issues, https://github.com/PierreSylla/Lumen/issues
Keywords: philips-hue,hue,ambilight,screen-sync,wayland,hyprland,smart-lights
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: X11 Applications :: GTK
Classifier: Intended Audience :: End Users/Desktop
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Home Automation
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: requests>=2.28
Requires-Dist: pywebview>=5.0
Requires-Dist: pystray>=0.19
Requires-Dist: pillow
Provides-Extra: dev
Requires-Dist: pyinstaller>=6.0; extra == "dev"
Dynamic: license-file

# Lumen

Desktop control for Philips Hue lights, built for Linux/Wayland (Hyprland,
but the UI runs anywhere `pywebview`'s GTK/WebKit backend does). Everything
goes through the bridge's local API (CLIP v2): no cloud, and no
dependency on the mobile app once paired.

![Lumen's Rooms page: room cards with scenes and per-lamp brightness](https://raw.githubusercontent.com/PierreSylla/Lumen/master/docs/screenshots/rooms.png)

Three commands sharing the same configuration:

- **`hue-webui`** - the desktop app: a Vue 3 UI in a native `pywebview`
  window, with a system-tray icon.
- **`hue`** - command-line client, ideal for keyboard shortcuts.
- **`hue-sync`** - screen sync (ambilight) without the GUI.

## Features

- Bridge pairing directly in the app: the bridge is found on the local
  network (mDNS), then one press of its button. Dark/light theme,
  English/French UI.
- Rooms and zones as cards: group control (on/off + brightness), and per
  lamp a colour wheel, brightness, white temperature and the effects the
  lamp supports (candle, fire, prism...). Unplugged lamps show as
  unreachable instead of pretending to be on.
- Scenes grouped by room/zone, with a thumbnail generated from the scene's
  real colours. Gallery scenes with a palette can also play dynamically.
  Create, edit and delete scenes (captures the current light state of every
  lamp in the group - the bridge requires the full set, not a partial
  capture).
- Create, edit and delete rooms and zones, from one editor. A room holds
  devices and mirrors your physical setup (a lamp lives in exactly one
  room); a zone holds individual lights and zones may overlap. "Identify"
  makes a lamp breathe once to tell which is which.
- Screen sync / ambilight - see below: live channel preview, screen picker,
  colour boost, smoothing, frame rate, black-bar detection, and Entertainment
  areas created and edited in the app.
- Real-time updates: the UI reflects changes made elsewhere (phone, wall
  switch, another app) live, via the bridge event stream (SSE).
- System tray: every room and zone with its scenes, all off, settings;
  closing the window minimizes to tray, so a running screen sync keeps
  streaming.
- Optional: a room or zone switched off while the computer sleeps and back
  on at wake-up; a status-bar module (Waybar, Noctalia - see the CLI
  section).
- The bridge's TLS certificate is pinned at pairing, and Lumen follows the
  bridge on its own if the router gives it a new IP.

| | |
|---|---|
| ![Lamp sheet: colour wheel, brightness, whites and effects](https://raw.githubusercontent.com/PierreSylla/Lumen/master/docs/screenshots/lamp.png) | ![Scenes page: scenes grouped by room and zone](https://raw.githubusercontent.com/PierreSylla/Lumen/master/docs/screenshots/scenes.png) |
| ![Screen sync running: live colour of each channel](https://raw.githubusercontent.com/PierreSylla/Lumen/master/docs/screenshots/sync.png) | ![Rooms page in the light theme](https://raw.githubusercontent.com/PierreSylla/Lumen/master/docs/screenshots/rooms-light.png) |

Screenshots use the app's built-in demo data.

## Screen sync (ambilight)

Lumen averages regions of your screen and streams them to the lamps over the
Hue Entertainment API, at up to 50 frames per second.

Create an Entertainment area on the Sync page (+ NEW) or in the official Hue
app, then start the sync (or run `hue-sync`). Each lamp follows the slice of
the screen matching its position in that area, so left lamps follow the left
of the picture. In the area editor, a lamp can also follow only the top or the
bottom of the picture (a lamp above or below the screen), a narrow slice, or
the whole width (an ambient lamp); "Identify" makes a lamp breathe once.

Screen capture drives a system binary rather than a Python binding, and the
first backend that works is used:

| Backend | Needs | Notes |
|---|---|---|
| `wlroots` | `wf-recorder` | Hyprland, Sway. Fastest, never prompts. |
| `portal` | `gst-launch-1.0` (gst-plugin-pipewire), `pw-dump` | Universal: GNOME, KDE, wlroots. Asks which screen on every start. |
| `x11` | `ffmpeg` | Plain X11 sessions. |

Settings hold the screen to capture, a color boost (screen averages are
washed out; lamps need the push) and the frame rate. Screen and color boost
apply to a running sync; changing the frame rate needs a stop and start.

Pairing must have produced a `client_key` - it is the DTLS secret. Configs from
older versions may lack it, in which case re-pair once.

## Installation

**Quick install (Arch/CachyOS):**

```bash
./install.sh
```

Installs the system packages below via `pacman` (asks first), builds the UI,
installs `hue`/`hue-webui`/`hue-sync` with `pipx` (falls back to `pip
install --user`), offers the desktop launcher, and cleans up `hue-gui` if an
older install left it behind. `./install.sh -y` skips every prompt.

**From PyPI** (any distro; no Node needed, the UI ships prebuilt):

```bash
pipx install --system-site-packages lumen-hue
```

The app needs PyGObject, WebKitGTK and an AppIndicator library from your
distro first - PyGObject binds the system GTK, so it can't come from pip, and
`--system-site-packages` is what lets the app see it. On Arch:
`python-gobject webkit2gtk-4.1 libayatana-appindicator`; on Debian/Ubuntu,
e.g. `python3-gi gir1.2-webkit2-4.1 gir1.2-ayatanaappindicator3-0.1`. The
`hue` CLI alone needs none of that.

**Manual install**, or on another distro - requires Python >= 3.10 and
Node.js/npm (build-time only, for the UI):

```bash
# from the project directory
cd webui && npm install && npm run build && cd ..
# recommended (isolated environment; the flag lets it see the system PyGObject)
pipx install --system-site-packages .
# or
pip install --user .
```

This installs `hue`, `hue-webui` and `hue-sync`.

On Arch/CachyOS, install the UI's runtime pieces from the system instead of
via pip:

```bash
sudo pacman -S python-pywebview webkit2gtk-4.1 python-gobject \
               python-pystray python-pillow libayatana-appindicator \
               nodejs npm
# run the app without installing the package
python -m huectl          
```

Screen sync needs `openssl` (already present on most systems) plus one capture
backend from the table above:

```bash
# Hyprland / Sway
sudo pacman -S wf-recorder
# any other compositor, through the desktop portal
sudo pacman -S gstreamer gst-plugin-pipewire pipewire-utils xdg-desktop-portal
```

Bridge detection, and following the bridge when the router gives it a new
IP, use mDNS through `avahi-browse` (already running on most desktops):

```bash
sudo pacman -S avahi && sudo systemctl enable --now avahi-daemon
```

Without it, first detection falls back to the Philips cloud service, and an IP
change has to be entered by hand (Setup > Change IP).

### Launcher / autostart

Copy `packaging/lumen.desktop` into `~/.local/share/applications/`.
To start minimized to the tray at session login (Hyprland), set
`start_minimized` in Setup > Appearance, then:

```
exec-once = hue-webui
```

> The tray icon requires a tray host (Waybar's `tray` module, or your shell's
> systray). Without a host, the window simply stays visible.

## First run

```bash
hue-webui
```

On first run the pairing screen detects the bridge (or enter its IP), you press
the bridge button, then click "Pair". Keys are stored in
`~/.config/huectl/config.json` (chmod 600).

## CLI

```bash
hue discover                 # find the bridge
hue auth                     # press the bridge button
hue lights                   # list lamps
hue rooms                    # rooms and zones
hue scenes                   # scenes
hue status                   # each room/zone: brightness or off
hue status "Living room"     # one room, zone or lamp
hue on "Living room"         # turn a room/zone on ("all" = every light)
hue toggle "Left lamp"       # toggle a lamp
hue bri "Living room" 60     # brightness 0-100
hue bri "Living room" +10    # relative
hue color "Lamp" #ff3300     # color
hue ct "Living room" warm    # warm white (or 3000, neutral, cool)
hue scene "Relax"            # activate a scene
hue raw GET /clip/v2/resource/light   # raw API access
```

Screen sync from the terminal:

```bash
hue-sync --list              # list Entertainment areas
hue-sync                     # ambilight from the screen
hue-sync --output DP-2       # capture one monitor
hue-sync --saturation 2.0    # stronger colors
hue-sync --test              # rainbow pattern, to check the pipeline
```

Example Hyprland shortcuts:

```
bind = $mod, F1, exec, hue toggle "Living room"
bind = $mod, F2, exec, hue scene "Relax"
bind = $mod SHIFT, F1, exec, hue bri "Living room" +15
```

### Status bar

`hue status --json [target]` prints one line in Waybar's custom-module format:
`text` (`60%` or `off`), `alt` and `class` (`on`/`off`, for `format-icons`
and CSS), `percentage`, and a `tooltip` listing every room and zone. Unplugged
lamps count as off, as in the app. Any other bar that runs a command can show
the plain `hue status "Living room"` instead.

Waybar (`~/.config/waybar/config.jsonc`, then add `"custom/hue"` to a modules list):

```jsonc
"custom/hue": {
    "exec": "hue status --json \"Living room\"",
    "return-type": "json",
    "interval": 5,
    "signal": 8,
    "format": "hue {}",
    "on-click": "hue toggle \"Living room\"; pkill -RTMIN+8 waybar",
    "on-scroll-up": "hue bri \"Living room\" +10; pkill -RTMIN+8 waybar",
    "on-scroll-down": "hue bri \"Living room\" -10; pkill -RTMIN+8 waybar"
}
```

The `pkill -RTMIN+8` refreshes the module right after a click instead of at the
next 5 s tick (it matches `"signal": 8`). Dim the module when the lights are
off with `#custom-hue.off { opacity: 0.5; }` in `style.css`.

**Noctalia** (v5): Lumen ships a bar widget plugin in `packaging/noctalia/lumen/`:
a bulb with the brightness, click to toggle, scroll for brightness, the rooms
in the tooltip. `./install.sh` offers to install and enable it; by hand:

```bash
cp -r packaging/noctalia/lumen ~/.local/share/noctalia/plugins/
noctalia msg plugins enable local/lumen
```

Then put it in a bar. Add the widget with Noctalia's bar settings, or in TOML:

```toml
[widget.hue]
type = "local/lumen:hue"
target = "Living room"   # room, zone or lamp; leave out for every light

[bar.default]
end = [ "tray", "hue", "volume" ]   # wherever it should sit
```

Mind which file holds your bar layout: once a bar was edited from Noctalia's
settings window, its lanes live in `~/.local/state/noctalia/settings.toml`
and override `config.toml` - add `"hue"` there, then `noctalia msg config-reload`.
`noctalia msg plugin local/lumen:hue all refresh` forces an update, e.g. from a
keybind that just ran `hue`.

## Project layout

```
huectl/                Python backend + entry points
  config.py            config load/save
  bridge.py            CLIP v2 HTTP client + discovery
  i18n.py              English/French strings, shared with the UI
  cli.py               command-line interface (hue) - has its own color math,
                        no dependency on the UI or on Qt
  webapp.py            pywebview shell, JS<->Python bridge (Api class),
                        SSE/sync background threads, system tray (hue-webui)
  webui_dist/          built Vue app (generated, gitignored - see below)
  huestream.py         HueStream v2 frame protocol
  entertainment.py     Entertainment configurations and channels
  dtls_stream.py       DTLS-PSK transport over the system openssl
  capture.py           screen capture backends, region averaging
  portal.py            xdg-desktop-portal ScreenCast
  sync.py              color sources, channel mapping, hue-sync entry point

webui/                 Vue 3 UI source, built to huectl/webui_dist/ (npm run
                        build) - a sibling dist/ would sit outside the huectl
                        package and never reach an installed wheel
  src/components/      design-system pieces (cards, sheets, sliders, icons)
  src/pages/           Rooms/Zones/Scenes/Sync/Setup
  src/store/           reactive app state + all calls into Api
  src/lib/             CLIP v2 <-> view-model mapping, colour math (a JS port
                        of the same sRGB<->xy conversions the CLI itself uses)
  src/composables/     theme and i18n
```

## Technical notes

- The bridge exposes its API over HTTPS with a self-signed certificate
  (`verify=False`); authentication uses the `hue-application-key` header.
- Colors are converted in sRGB both ways (RGB<->xy) to stay faithful to the
  picked color - ported independently in the CLI (`cli.py`) and the web UI
  (`webui/src/lib/huecolor.js`), verified to agree with each other.
- A scene's actions must cover every light currently in its room/zone - the
  bridge rejects a partial list with "Light action targets not matching
  lights in referenced group" (confirmed against a real bridge). The Scene
  Editor always re-captures the full group, never a subset.
- The Philips mobile app's real product photos are not available through the
  bridge; Lumen draws its own inline-SVG icons instead.
- DTLS-PSK for Entertainment uses the system `openssl` binary, not a Python DTLS
  binding (`python-mbedtls` is unmaintained and does not build against
  Mbed TLS 3.x).
- Screen capture never grabs one frame at a time: a `grim` call costs about
  120 ms whatever the resolution, which caps it near 8 fps. Continuous streams
  are used instead, and only the newest frame is kept so the lamps cannot drift
  behind the screen. Starting sync with no explicit monitor picked on a
  multi-monitor Hyprland setup will fail the fast `wlroots` path and fall
  through to the `portal` backend instead - the UI always resolves
  "Automatic" to a real output name via `hyprctl` first to avoid that path
  entirely.
- The portal backend asks which screen to share on every start; nothing sends
  the portal's `persist_mode` option yet to suppress that (a real follow-up
  now that `portal.py` is plain GDBus.
- The `x11` capture backend is written but has not been exercised on a real X11
  session.
- WebKitGTK's DMABUF renderer can crash on load (Wayland protocol error)
  on hybrid Intel+NVIDIA setups; `hue-webui` sets
  `WEBKIT_DISABLE_DMABUF_RENDERER=1` before import to avoid it.

## Releasing

1. Bump `__version__` in `huectl/__init__.py` - the only place it lives.
2. Commit, then tag and push: `git tag v1.1.0 && git push origin master v1.1.0`.
3. The Release workflow builds the UI and the package, checks the tag matches
   the version, and publishes to PyPI through Trusted Publishing (no token
   stored anywhere). Run it by hand from the Actions tab to check a build
   without publishing.

## License

GNU General Public License v3.0 or later (GPL-3.0-or-later). See `LICENSE`.
