Skip to main content

KasaButtons

Overview

This project aims to allow control over Kasa and/or Tapo smart devices (mostly bulbs) using a computer (including Raspberry Pi devices) and a keyboard (especially small macro keyboards). Future versions, may also include support of GPIO buttons.

Usage

Installation

The project can be installed as a python package, kasabuttons.

Via pipx:

pipx install kasabuttons

Or rye:

rye install kasabuttons

Or into you virtual environment using your preferred mechanism for installing python packages.

The only installed command is kasa-buttons.

Configuration

kasa-buttons expects there to be a kasabuttons.toml file or optionally, specified via parameters --config your_config_file.yaml. You can specify either a yaml or toml file. Example configration here will be in toml format.

The minimum configuration would be associating one button on a keyboard to one Kasa or Tapo device.

[[buttons]]
button_text = "b"
device_name = "Smart Bulb"
long_press = "dim-"
short_press = "toggle"
dim_states = [10, 50, 100]

The above example configuration configures a device named Smart Bulb to be associated with the b key on the keyboard. NOTE: The device_name value must match exactly (including case) with the device as it is setup. A short press will toggle the bulb on/off. A long press (greater than half a second), results in dimming the bulb following the dim_states order headed to the left. A setting of dim+ would change the dim state of the bulb to the right. Currently, the program loops around, so a long press while the bulb is at 10% brightness in the above example, will result in a new brightness of 100%.

Other options: discovery_timeout = 10 sets the number of seconds to scan the network for devices. 10 (seconds) is the default value.

Logging configuration:

[[logging.handlers]]
sink = "ext://sys.stderr"
format = "<green>{time:YYYY-MM-DD HH:mm:ss.SSS}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>"

[[logging.handlers]]
sink = {"()" = "kasabuttons.logging_utils.custom_loki_handler", "url" = "http://my-local-loki-server.local:3100/loki/api/v1/push"}
serialize = true
backtrace = false

The above example sets both the default Loguru stderr output as well as sending logs to a local Loki server.

Environment Configuration / Authentication

Tapo devices require authentication, so if any of your devices are Tapo devices, they will only work correctly if you also provide credentials. These credentials can be provided in the .toml file but it's recommended to set them as environment variables or in a .env file.

KASA_USERNAME=me@example.com
KASA_PASSWORD=your-password-here

The program looks only in the current directory when the script is run for both the default kasabuttons.toml file as well as the .env file if that is the method being used to set these values.

Development and Testing

This project uses rye for dependency and virtual environment management.

Install the dependencies for KasaButtons

rye sync

Run the tests

rye test

NOTE: This project has not been tested in Windows. Of particular issue: the keyboard handlers need massive amounts of permissions to gain access to keyboard events. It seems unlikely to me that this project will work correctly in WSL/WSL2. It should work correctly with the pynput keyboard handler under windows but has not been tested.

Run the program

rye run kasa-buttons

This runs the command line tool that starts the async loop. Note: you need to have set up a kasabuttons.toml or kasabuttons.yaml file to configure which keys you want to map to which Kasa/Tapo devices. See configuration section.

Metadata

Release files for kasabuttons 0.3.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for kasabuttons 0.3.2
File Size Uploaded Provenance Actions
kasabuttons-0.3.2.tar.gz 13.6 kB Without provenance Details for kasabuttons-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for kasabuttons 0.3.2
File Interpreter ABI Platform Actions
kasabuttons-0.3.2-py3-none-any.whl Python 3 none any Details for kasabuttons-0.3.2-py3-none-any.whl

Total release size: 25.6 kB

Release files / kasabuttons-0.3.2.tar.gz

Download URL kasabuttons-0.3.2.tar.gz
Size 13.6 kB
Tags Source
SHA-256 checksum
How to use checksums
40423d6837487fbfa38247958720dae95d4c23e51eb2f3bc0a3e67bf66af5a3d
BLAKE2b-256 checksum
How to use checksums
c1f74e41315e07058ee11b29deb72f1faaea4f6f2938a155629d43f276b01e2a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Release files / kasabuttons-0.3.2-py3-none-any.whl

Download URL kasabuttons-0.3.2-py3-none-any.whl
Size 12.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8713c0969323ae99262787569d007487b541d1e2bd667146fac980b07812ead
BLAKE2b-256 checksum
How to use checksums
fc5ae60334f0479860c53e3831bc4f4045ad90d12f7214ab5215fe711fe978e2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.3

Security for kasabuttons 0.3.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page