Local-first command-line control for compatible Tuya Wi-Fi lights. Localight uses TinyTuya to send commands directly over the LAN; Tuya Cloud is not needed for normal runtime control once the device credentials are configured.
The project is still early-stage and has been developed with a limited set of Tuya-compatible lights, including a protocol 3.3 light. Compatibility with every Tuya device is not guaranteed.
Requirements: Python 3.11 or newer and a Tuya-compatible device reachable on your local network.
git clone https://github.com/an0mal1a/localight
cd localightpython -m pip install -e .
localight device add bedroom
localight default bedroom
localight statusdevice add asks for Device ID, IP address, Local Key and protocol version. The
Local Key is entered with a hidden prompt and is never printed by Localight.
localight status [device]
localight on [device]
localight off [device]
localight toggle [device]
localight brightness [device] VALUE
localight temperature [device] VALUE
localight health [device]
localight devices
localight device add NAME
localight device show NAME
localight device remove NAME
localight device import-env [NAME]
localight default [NAME]
localight discoverThe device name is optional when a default has been configured. Brightness also supports the compact default-device form:
localight brightness 500
localight brightness +50
localight brightness -50
localight brightness bedroom +50
localight temperature 400
localight temperature bedroom -50Temperature is the light profile's normalized Tuya DPS 23 value from 0 to
1000; it is not a Kelvin value. Setting temperature selects the light's
white work mode but does not turn it on.
localight health [device] performs a real local probe and reports reachability
and latency. localight --direct health bedroom bypasses the daemon, just like
the other light commands.
Devices are stored in a per-user JSON file resolved with platformdirs:
| System | Location |
|---|---|
| Windows | %APPDATA%\localight\config.json |
| Linux | ~/.config/localight/config.json |
| macOS | ~/Library/Application Support/localight/config.json |
The file contains Local Keys in plaintext. Keep it private and never commit it. Localight attempts restrictive file permissions on Linux and macOS.
Existing installations using the legacy .env variables can migrate without
deleting .env:
localight device import-env bedroomSee docs/tuya-setup.md for credential setup and docs/device-discovery.md for discovery versus provisioning.
For repeated commands from a rotary control, Localight can run a small local daemon. On Windows, install per-user autostart once:
localight daemon installThis creates a value under the current user's Windows Run key. It starts the
daemon immediately and again when that user signs in; it does not install the
Python package, require UAC, or create a Windows Service. The value runs the
exact Python environment used for installation, so if a virtual environment is
moved or deleted, run localight daemon uninstall and localight daemon install
again.
Autostart uses pythonw.exe, so it does not leave a Command Prompt window open.
localight daemon run is intentionally visible for manual debugging.
Useful lifecycle commands are:
localight daemon status
localight daemon start
localight daemon stop
localight daemon restart
localight daemon uninstall
localight daemon logsdaemon start runs in the background. daemon run remains a foreground,
manual debugging mode:
localight daemon runIt listens only on 127.0.0.1:47621, keeps device runtimes alive and caches
recent brightness and temperature for a short TTL. Its runtime is persistent,
but its Tuya transport is recoverable: a LAN transport failure rebuilds the
client and retries the already-resolved target once. This remains local-only;
there is no cloud runtime or background polling. Existing light commands use it
automatically and fall back to direct LAN control when it is unavailable.
localight daemon status
localight --direct toggle bedroomThe --direct flag bypasses the daemon for one command. The daemon is not a
cloud service or HTTP server. It listens only on 127.0.0.1:47621 and writes
small diagnostic logs to the per-user platformdirs log directory.
The current Windows workflow uses a StreamDock Hotkey control and PowerToys Keyboard Manager; no dedicated plugin is required. The detailed setup, shown with the captured configuration, is in docs/streamdock.md.
The basic mapping is:
| Action | Hotkey | Arguments |
|---|---|---|
| Rotate left | Left Ctrl + Left Alt + Left Shift + F12 |
brightness -50 |
| Rotate right | Left Ctrl + Left Alt + Left Shift + F11 |
brightness +50 |
| Press | Left Ctrl + Left Alt + Left Shift + F10 |
toggle |
PowerToys opens localight.exe with the matching arguments and should use a
hidden window. The daemon makes rapid brightness ticks more efficient.
- Tuya setup and Local Key retrieval
- Local Key notes
- LAN discovery
- Privacy and local storage
- StreamDock + PowerToys workflow
- Troubleshooting
- Networking and DHCP
- Architecture
- Daemon lifecycle and autostart
Install development dependencies and run the tests:
python -m pip install -e ".[dev]"
pytestTests mock TinyTuya and loopback sockets; they do not contact a real device or the LAN.
Implemented: multiple named devices, persistent configuration, default device,
legacy .env import, LAN discovery, direct light control and the optional local
daemon.
Future work may include configurable DPS profiles, color controls, a public Python API and packaging improvements. Cloud calls, HTTP, MQTT, Home Assistant, GUI and vendor-specific StreamDock plugins are intentionally out of scope.
Never publish .env, config.json, devices.json, tinytuya.json,
tuya-raw.json or snapshot.json. Localight sends runtime commands over LAN,
but the device firmware may independently contact vendor services if it has WAN
access. See docs/privacy.md.
See LICENSE.
