Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Hand Gesture TV Remote for Home Assistant

Control your TV with your hands over a webcam. Twist an invisible knob for volume, push a fist around like a joystick for the D-pad, spread both hands to exit. Everything goes through Home Assistant, so it works with whatever TV your Home Assistant already talks to.

Controlling the TV with hand gestures Controlling the TV with hand gestures

Python License Platform

Single file, no cloud, no account. Nothing leaves your network except calls to your own Home Assistant.

git clone https://github.com/frogcaller/ha-gesture-remote.git
cd ha-gesture-remote
pip install -r requirements.txt
python ha_gesture_remote.py

A setup window walks you through the rest.


What you need

  • A webcam (a laptop cam is fine)
  • Python 3.9 or newer
  • Home Assistant on the same network, with your TV already added to it
  • Your TV working from the Home Assistant dashboard first. If you can't change the volume by clicking in HA, gestures won't help — fix that first.

Step 1 — Install Python and the libraries

Get Python from python.org if you don't have it. On Windows, tick "Add Python to PATH" during install.

Then open a terminal (Command Prompt on Windows) and run:

pip install -r requirements.txt

Takes a couple of minutes. MediaPipe is the hand tracker; the first run downloads a small model, so you need internet that once.

On Debian or Ubuntu, also install tkinter for the setup window:

sudo apt install python3-tk

Step 2 — Add your TV to Home Assistant

Skip this if your TV is already there.

Settings → Devices & Services → Add Integration, then pick the one matching your TV:

TV Integration
Samsung Samsung Smart TV
LG LG webOS Smart TV
Sony, Philips, TCL, most Android TVs Android TV Remote
Roku / Roku TV Roku
Apple TV Apple TV
Chromecast Google Cast

Turn the TV on before adding it, and accept the permission prompt that appears on the screen.


Step 3 — Create an access token

In Home Assistant:

  1. Click your user name at the bottom left
  2. Go to the Security tab
  3. Scroll to Long-lived access tokens → Create token
  4. Give it any name, e.g. gestures
  5. Copy the long eyJ... string immediately — it's shown only once

Step 4 — First run

python ha_gesture_remote.py

A setup window opens the first time. Fill in:

  • Address — your Home Assistant IP, e.g. http://192.168.1.50:8123. Use the IP; homeassistant.local often fails on Windows.
  • Token — paste the eyJ... string from Step 3

Click Connect. It reads your Home Assistant and fills two dropdowns:

  • TV — your media player
  • Remote — the entity that carries up/down/left/right/enter. If this list is empty, your TV's integration doesn't provide arrow keys; volume and play/pause will still work, navigation won't.

Pick your TV brand, click Save and start. Done — you never need to open the setup window again.

Or edit the config file

Setup writes config.ini next to the script — see config.example.ini for the full commented version. You can edit it in any text editor instead of using the window:

[home_assistant]
url = http://192.168.1.50:8123
token = 6eiOiGcUI1NiIzIJhbsJ...

[entities]
media_player = media_player.living_room_tv
remote = remote.living_room_tv

[remote]
preset = samsung

Every setting is commented in the file. Save it and restart the app. Delete the file to get the setup window back, or run python ha_gesture_remote.py --setup to reopen it any time.


Step 5 — Check it works

A video window opens. Press t — that sends a single D-pad RIGHT press with no gesturing involved. If the highlight on your TV moves, everything is wired up.

If it doesn't, the problem is the Home Assistant side, not the camera. Check the terminal for the error.


The gestures

Gesture Does
Pinch thumb + index, twist your hand Volume, like turning a knob
Make a fist, push it up/down/left/right D-pad — holds and repeats like a real remote
Fist, quick tap without moving ENTER / select
Pinch thumb + pinky, release quickly Back
Pinch thumb + pinky, hold 1 second Mute
Pinch thumb + index, tap with your other hand open Play / pause
Pinch thumb + middle / ring, hold Previous / next track
Fist, quick tap with your other hand open Source / input
Two fists, hold 1.2 seconds TV power on/off
Both hands open, fingers spread, hold Exit

The fist D-pad drops an anchor where you close your hand. Push away from that anchor to hold a direction, return to the middle to stop.

Play/pause needs your second hand open on purpose — otherwise every quick volume pinch would pause your movie.

Remapping

Any gesture can do anything else. Press g while the app is running for a remap window — one dropdown per gesture, with a Reset to defaults button. Changes apply immediately and are saved.

The two "hold" gestures (pinch-and-move, fist-and-move) choose between volume, D-pad joystick, or nothing — so if you'd rather steer menus with a pinch and turn volume with a fist, just swap them.

Every other gesture picks a single action: play/pause, select, back, home, source, exit, an individual arrow, mute, volume up/down, next/previous, or power.

Source and exit aren't on every brand's remote. If your TV has no such key the gesture simply does nothing — Samsung has both, LG has exit only, Apple TV has neither.

You can also edit the [gestures] section of config.ini directly:

[gestures]
pinch_index_hold = volume
fist_move = dpad
pinch_pinky_tap = back
pinch_pinky_hold = mute
fist_tap = select
two_fists_hold = power

Keys

Key Does
g Remap gestures
t Send a test D-pad press
i Flip the volume direction if the knob feels backwards
n Next device, if you set up more than one
r Refresh state from Home Assistant
c / f Next camera / mirror the view
q Quit

Tuning

All of this is in the [tuning] section of config.ini. Restart after saving.

Problem Setting
Volume knob feels backwards twist_invert = yes (or press i while running)
Want up/down movement instead of twisting volume_mode = drag
Volume gets too loud volume_limit = 0.6
D-pad arrows fire too easily dpad_deadzone = 1.0
One push scrolls past what you wanted dpad_repeat = 0.6
Says TOO FAR where you normally sit min_hand_size = 0.04
Pausing by accident leave play_pause_needs_open_hand = yes

A few finer settings live at the top of the .py file, with comments — smoothing strength, repeat delays, gesture debounce.


Multiple cameras

Two webcams pointed from different angles track noticeably better than one, since a finger hidden from one lens is usually visible to the other. The clearest view drives the gestures automatically.

python ha_gesture_remote.py --list        # see what's detected
python ha_gesture_remote.py --camera 0 2  # use both

Troubleshooting

"No Home Assistant token" — the setup window was closed before saving. Run it again, or put your token in config.ini.

No setup window appears — on Linux, install tkinter: sudo apt install python3-tk. Without it, setup falls back to questions in the terminal.

"Entity not found" — the entity ID is wrong. Run python ha_gesture_remote.py --list-entities to see the real ones, or rerun --setup and pick from the dropdown.

"HA OFFLINE" — wrong IP, wrong port, or an expired token. Check you can open the URL in a browser.

D-pad connects but the TV ignores it — wrong command set for your brand. Change preset under [remote] in config.ini to samsung, webos, roku or appletv.

TV won't turn on, but turns off fine — normal. Most TVs ignore network commands when fully off. Wake-on-LAN in Home Assistant is the usual fix.

Presses keep going after you stop — raise dpad_repeat to 0.6. Your TV accepts commands more slowly than most.

No camera found — close anything else using the webcam (Zoom, Teams, browser tabs).


How it works

MediaPipe Hands gives 21 landmarks per hand per frame. A few things follow from that which are worth knowing if you want to modify it:

  • Pinches are measured relative to hand size, not in pixels, so they work at any distance from the camera. Landmark jitter doesn't scale that way though, which is why gesture changes are debounced by a frame count that rises as your hand gets smaller in frame.
  • The volume knob uses the wrist-to-knuckle angle, unwrapped before smoothing. Filtering the raw atan2 output would fling the volume every time the angle crossed the back of the circle.
  • Gestures don't know what they mean. Each fires a named slot; the slot points at an action. That's what makes remapping pure config.
  • Nothing blocks the video loop. Commands are queued and sent on a background thread, and D-pad presses are never queued behind one still in flight — otherwise a slow TV builds a backlog that keeps scrolling after you stop.

Everything tunable is at the top of the file with comments, or in config.ini.

Contributing

Issues and pull requests welcome, especially:

  • Command sets for more TVs. Add a preset to REMOTE_PRESETS near the top.
  • New gestures. Add a slot to GESTURE_SLOTS and fire it from the main loop; the remap window picks it up automatically.
  • Reports of misfires, with your camera distance and lighting. That's the hardest part to test alone.

Keep it a single file with no new required dependencies.

Notes

Your token is stored in config.ini next to the script, readable only by your user account. Don't share that file — anyone with the token has full control of your Home Assistant. Delete the token in Home Assistant under Security if it leaks.

Uses MediaPipe Hands for tracking and the Home Assistant REST API for everything else.

MIT licensed. See LICENSE.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages