Skip to main content

Add your description here

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kasabuttons-0.3.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

kasabuttons-0.3.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file kasabuttons-0.3.0.tar.gz.

File metadata

  • Download URL: kasabuttons-0.3.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for kasabuttons-0.3.0.tar.gz
Algorithm Hash digest
SHA256 afa44d2d703b8458bc9dda2ef85011d036613c63bdf6e6b08414d4d8619a2d3e
MD5 2bb5e5ec5313cdbef222c3d72f9a5f0e
BLAKE2b-256 2119183889a4c54002c944c54db133ece45792663e05fc269eb12a537d04926f

See more details on using hashes here.

File details

Details for the file kasabuttons-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: kasabuttons-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for kasabuttons-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 99daf04cf8102ed31340c5c4449f508fe773f320d43bab23ea2cd7fcf12fcf99
MD5 0c8e856dac59456b14b75c9b4648b626
BLAKE2b-256 9c7d6e9a4ce62ad3cd27a836da422c08c130f9bf298627031512b20f516f9663

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page