Point your phone at an object, control it in Home Assistant — Docker container + Flask website. Reference photos map to lights, switches, fans, scenes and scripts.
  • Python 67%
  • JavaScript 17.5%
  • CSS 7.3%
  • HTML 6.1%
  • Dockerfile 1.6%
  • Other 0.5%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
2026-11-12 18:10:49 -05:00
app Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:10:20 -05:00
tests Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:10:49 -05:00
.dockerignore Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:07:07 -05:00
.env.example Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:07:10 -05:00
.gitignore Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:08:32 -05:00
build.sh Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:10:25 -05:00
docker-compose.yml Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:10:47 -05:00
Dockerfile Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:08:33 -05:00
README.md Initial commit: Photo Control — point at an object, control it in Home Assistant 2026-11-12 18:09:30 -05:00

Photo Control 📸

Point your phone at a thing, control it.

A Docker container + website for Home Assistant. Save a reference photo of an object — a lamp, a fan, a speaker — linked to a light, switch, fan, scene or script. Later, photograph that object again and its controls open on your phone: on/off, brightness, colour, run scene/script.

No cloud. No account. Matching runs locally in the container.

How it works

  1. Settings — paste your Home Assistant URL + a long-lived access token. HA → your profile → Security → Long-lived access tokens → Create token.
  2. Library — photograph an object, name it, pick what it controls. Up to 5 photos per object (different angles / lighting help a lot).
  3. Scan — photograph the object again. Best match opens with its controls. If the matcher isn't sure, it shows the top 3 and lets you pick — it never guesses wrong silently.

Matching

Local, tiered — best available wins, and it degrades gracefully:

Tier When What it does
CLIP embeddings torch + transformers installed and CLIP turned on in Settings Understands "same lamp, new angle". ~600 MB download on first use. Off by default.
ORB features OpenCV installed (included in the Docker image) Keypoint matching, good for same object, similar angle.
Ensemble (always on) Pillow + numpy only Perceptual hash + colour histogram + downscaled-layout correlation.

A match is accepted at ≥ 0.55 (configurable) and beating the runner-up by ≥ 0.05 — two lamps in one room shouldn't get confused. Above 0.85 it accepts outright.

Run it

docker compose up -d --build
# open http://<your-host>:8099 on your phone

Data (reference photos, fingerprints, settings) lives in ./data and survives restarts / rebuilds.

To set HA without the UI, uncomment HA_URL / HA_TOKEN in docker-compose.yml — or set them in the container env. Settings saved in the website win over env.

Without Docker

pip install -r app/requirements.txt
python app/app.py
# open http://127.0.0.1:8099

Optional, for better matching: pip install opencv-python-headless and/or torch + transformers, then turn CLIP on in Settings.

On your own server (like the user's setup)

The container is a plain Flask + gunicorn app on port 8099 with a /data volume — put it behind whatever you already use (Cloudflare Tunnel, Caddy, Tailscale). It needs to reach your HA instance: if HA is at http://homeassistant.local:8123 on your LAN, the container needs LAN access (network_mode: host or a routable HA URL).

Controls by target

  • Light — on / off / toggle, brightness slider, colour swatches + picker, colour-temperature slider.
  • Switch / fan / cover / media player — on / off / toggle.
  • Scene / script — a big Run button (scene.turn_on / script.turn_on).

After every action the app reads the entity state back from HA, so the UI shows reality, not optimism.

API

Endpoint What
GET / Website
GET /api/health Matcher mode, HA connectivity, ref count
GET/POST /api/settings HA URL, token (never returned), threshold, CLIP flag
GET /api/entities Controllable HA targets (falls back to known devices when HA is offline)
GET/POST/DELETE /api/refs Reference objects
POST /api/refs/<id>/photo Add a photo to a reference
POST /api/scan Multipart photo → ranked matches + live state
POST /api/control {target_type, target_id, action, brightness_pct, rgb_color, color_temp_kelvin, ...}
GET /api/state/<entity_id> Live HA state

Project layout

docker-compose.yml  Dockerfile  README.md
app/
  app.py          Flask app + API
  matcher.py      CLIP / ORB / ensemble matcher
  ha_client.py    Home Assistant REST client
  store.py        Reference + settings storage (/data)
  templates/index.html
  static/app.js  static/style.css
  requirements.txt
tests/            pytest-style unit tests (no HA, no camera needed)
data/             created on first run — photos, refs.json, settings.json

Tests

pip install -r app/requirements.txt
python -m pytest tests/ -q
# or without pytest:
python tests/test_matcher.py && python tests/test_api.py

The matcher tests use synthetic images (coloured shapes on different backgrounds), so they run anywhere — they check that a re-photo of the same object scores well above a different object, and that an exact duplicate scores 1.0.

Limits, honestly

  • Matching is recognition of a specific object you photographed, not general object detection. A white lamp and a different white lamp in the same light will confuse the ensemble — add a second reference angle, raise the threshold, or turn on CLIP.
  • Phone photos vary with lighting. Take the reference in the lighting you usually scan in, and add a second photo in different light if scans miss.
  • CLIP on CPU is slower (a second or two per scan) and needs RAM for the model; the ensemble + ORB path is instant on a Pi.
  • The token is stored in ./data/settings.json inside the container volume — keep that volume private, same as any HA token.