{"id":37452811,"url":"https://github.com/cmackenzie1/kasa-rs","last_synced_at":"2026-01-20T17:00:59.933Z","repository":{"id":331741350,"uuid":"1131925226","full_name":"cmackenzie1/kasa-rs","owner":"cmackenzie1","description":"Rust SDK and CLI for TP-Link Kasa Smart Plugs. ","archived":false,"fork":false,"pushed_at":"2026-01-15T02:57:23.000Z","size":194,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-01-18T14:43:27.006Z","etag":null,"topics":["iot","kasa","rust","tp-link"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/kasa","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cmackenzie1.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":"AGENTS.md","dco":null,"cla":null}},"created_at":"2026-01-11T00:45:32.000Z","updated_at":"2026-01-15T15:00:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/cmackenzie1/kasa-rs","commit_stats":null,"previous_names":["cmackenzie1/kasa-rs"],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/cmackenzie1/kasa-rs","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmackenzie1%2Fkasa-rs","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmackenzie1%2Fkasa-rs/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmackenzie1%2Fkasa-rs/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmackenzie1%2Fkasa-rs/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cmackenzie1","download_url":"https://codeload.github.com/cmackenzie1/kasa-rs/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cmackenzie1%2Fkasa-rs/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28607624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T16:10:39.856Z","status":"ssl_error","status_checked_at":"2026-01-20T16:10:39.493Z","response_time":117,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["iot","kasa","rust","tp-link"],"created_at":"2026-01-16T06:57:54.300Z","updated_at":"2026-01-20T17:00:59.904Z","avatar_url":"https://github.com/cmackenzie1.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# kasa-rs\n\n[![CI](https://github.com/cmackenzie1/kasa-rs/actions/workflows/rust.yml/badge.svg)](https://github.com/cmackenzie1/kasa-rs/actions/workflows/rust.yml)\n\nA CLI and library for communicating with [TP-Link Kasa](https://www.kasasmart.com/us) smart home devices.\n\n## Crates\n\n| Crate | Version | Docs | Description |\n|-------|---------|------|-------------|\n| [kasa](https://crates.io/crates/kasa) | [![Crates.io](https://img.shields.io/crates/v/kasa)](https://crates.io/crates/kasa) | - | CLI for communicating with TP-Link Kasa smart devices |\n| [kasa-core](https://crates.io/crates/kasa-core) | [![Crates.io](https://img.shields.io/crates/v/kasa-core)](https://crates.io/crates/kasa-core) | [![docs.rs](https://img.shields.io/docsrs/kasa-core)](https://docs.rs/kasa-core) | Core library for communicating with TP-Link Kasa smart devices |\n| [kasa-prometheus](https://crates.io/crates/kasa-prometheus) | [![Crates.io](https://img.shields.io/crates/v/kasa-prometheus)](https://crates.io/crates/kasa-prometheus) | - | Prometheus metrics exporter for TP-Link Kasa smart home devices |\n\n## Quickstart\n\n### Installation\n\n#### Using cargo-binstall (recommended)\n\n[cargo-binstall](https://github.com/cargo-bins/cargo-binstall) provides a convenient way to install pre-built binaries:\n\n```bash\ncargo binstall kasa\n```\n\n#### Using cargo install\n\n```bash\ncargo install kasa\n```\n\n#### From source\n\n```bash\ngit clone https://github.com/cmackenzie1/kasa-rs.git\ncd kasa-rs\ncargo install --path crates/kasa\n```\n\n### Basic Usage\n\n```bash\n# Discover devices on your local network\nkasa discover | jq\n\n# Get device info\nkasa device 192.168.1.100 info | jq\n\n# Turn on a smart plug\nkasa device 192.168.1.100 on\n\n# Turn off a smart plug  \nkasa device 192.168.1.100 off\n\n# Get energy meter readings (for devices with energy monitoring)\nkasa device 192.168.1.100 energy | jq\n\n# Turn off all devices on the network\nkasa broadcast off | jq\n```\n\n## Project Structure\n\nThis project is organized as a Cargo workspace with two crates:\n\n```\nkasa-rs/\n├── Cargo.toml              # Workspace configuration\n├── README.md\n└── crates/\n    ├── kasa/               # CLI binary\n    │   ├── Cargo.toml\n    │   └── src/\n    │       └── main.rs     # Command-line interface using clap\n    └── kasa-core/          # Core library (async)\n        ├── Cargo.toml\n        └── src/\n            └── lib.rs      # Protocol implementation and device communication\n```\n\n### `kasa-core`\n\nThe core library crate that implements the TP-Link Smart Home Protocol. Use this crate if you want to integrate Kasa device communication into your own Rust application.\n\n**Features:**\n- Async API using Tokio\n- Protocol encryption/decryption (XOR autokey cipher)\n- TCP communication with Kasa devices\n- UDP broadcast discovery to find devices on the local network\n- Broadcast commands to all devices in parallel\n- Predefined command constants for common operations\n- Support for both IP addresses and hostnames\n\n**Add to your project:**\n\n```toml\n[dependencies]\nkasa-core = \"0.1.0\"\ntokio = { version = \"1\", features = [\"rt-multi-thread\", \"macros\"] }\n```\n\n**Example usage:**\n\n```rust\nuse kasa_core::{commands, send_command, DEFAULT_PORT, DEFAULT_TIMEOUT};\n\n#[tokio::main]\nasync fn main() -\u003e std::io::Result\u003c()\u003e {\n    // Get device info\n    let response = send_command(\n        \"192.168.1.100\",\n        DEFAULT_PORT,\n        DEFAULT_TIMEOUT,\n        commands::INFO,\n    ).await?;\n    println!(\"{}\", response);\n\n    // Turn on the relay\n    send_command(\n        \"192.168.1.100\",\n        DEFAULT_PORT,\n        DEFAULT_TIMEOUT,\n        commands::RELAY_ON,\n    ).await?;\n\n    Ok(())\n}\n```\n\n### `kasa`\n\nThe command-line interface for interacting with Kasa devices. Outputs JSON by default for easy piping to tools like `jq`.\n\n**Commands:**\n\n```\nkasa discover                # Discover devices on the local network\nkasa device \u003cTARGET\u003e ...     # Send commands to a specific device\nkasa broadcast ...           # Send commands to all devices on the network\nkasa version                 # Show CLI and library versions\n```\n\n**Device Commands:**\n\n| Command | Description |\n|---------|-------------|\n| `info` | Get system information |\n| `on` | Turn relay on |\n| `off` | Turn relay off |\n| `energy` | Get real-time energy readings |\n| `energy-reset` | Reset energy meter statistics |\n| `ledon` | Turn LED indicator on |\n| `ledoff` | Turn LED indicator off |\n| `time` | Get device time |\n| `schedule` | Get schedule rules |\n| `countdown` | Get countdown rules |\n| `antitheft` | Get anti-theft rules |\n| `cloudinfo` | Get cloud connection info |\n| `wlanscan` | Scan for wireless networks |\n| `reboot` | Reboot the device |\n| `reset` | Factory reset the device |\n| `runtime-reset` | Reset runtime statistics |\n| `raw \u003cJSON\u003e` | Send a raw JSON command |\n\n**Broadcast Commands:**\n\nThe `broadcast` command sends a command to all discovered devices in parallel. For safety, destructive commands (`reset`, `reboot`, `energy-reset`, `runtime-reset`, `raw`) are not available for broadcast.\n\n| Command | Description |\n|---------|-------------|\n| `info` | Get system info from all devices |\n| `on` | Turn relay on for all devices |\n| `off` | Turn relay off for all devices |\n| `energy` | Get energy readings from all devices |\n| `ledon` | Turn LED on for all devices |\n| `ledoff` | Turn LED off for all devices |\n| `time` | Get time from all devices |\n| `schedule` | Get schedules from all devices |\n| `countdown` | Get countdowns from all devices |\n| `antitheft` | Get anti-theft rules from all devices |\n| `cloudinfo` | Get cloud info from all devices |\n| `wlanscan` | Scan networks from all devices |\n\n**Options:**\n\n```\nkasa device \u003cTARGET\u003e [OPTIONS] \u003cCOMMAND\u003e\n\nArguments:\n  \u003cTARGET\u003e  Target hostname or IP address\n\nOptions:\n  -p, --port \u003cPORT\u003e        Target port [default: 9999]\n      --timeout \u003cTIMEOUT\u003e  Timeout in seconds [default: 10]\n\nkasa broadcast [OPTIONS] \u003cCOMMAND\u003e\n\nOptions:\n      --discovery-timeout \u003cSECS\u003e  Discovery timeout in seconds [default: 3]\n      --timeout \u003cTIMEOUT\u003e         Per-device command timeout in seconds [default: 10]\n```\n\n## Supported Devices\n\nThe following devices have been tested, but others using the same protocol should work:\n\n- [HS100](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-hs100) - Smart Wi-Fi Plug\n- [HS103](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-lite-hs103) - Smart Wi-Fi Plug Lite\n- [HS110](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-energy-monitoring-hs110) - Smart Wi-Fi Plug with Energy Monitoring\n- [KP115](https://www.kasasmart.com/us/products/smart-plugs/kasa-smart-plug-slim-energy-monitoring-kp115) - Smart Wi-Fi Plug Slim with Energy Monitoring\n\n## Examples\n\n```bash\n# Discover all Kasa devices on the local network\nkasa discover | jq\n\n# Discover with a longer timeout (5 seconds)\nkasa discover --timeout 5 | jq\n\n# List discovered device names and IPs\nkasa discover | jq -r '.[] | \"\\(.alias): \\(.ip)\"'\n\n# Get device info and format with jq\nkasa device 192.168.1.100 info | jq\n\n# Get just the device alias\nkasa device 192.168.1.100 info | jq -r '.system.get_sysinfo.alias'\n\n# Get current power consumption in watts\nkasa device 192.168.1.100 energy | jq '.emeter.get_realtime.power'\n\n# Use hostname instead of IP address\nkasa device my-smart-plug.local info\n\n# Send a custom JSON command\nkasa device 192.168.1.100 raw '{\"system\":{\"get_sysinfo\":{}}}'\n\n# Enable verbose logging to see protocol details\nkasa -v device 192.168.1.100 info\n\n# Turn off all devices on the network\nkasa broadcast off | jq\n\n# Get info from all devices\nkasa broadcast info | jq\n\n# Check which devices succeeded/failed\nkasa broadcast info | jq '.[] | select(.success == false)'\n\n# Get all device aliases\nkasa broadcast info | jq -r '.[] | select(.success) | .alias'\n```\n\n## Building from Source\n\n[Install Rust](https://www.rust-lang.org/tools/install), then:\n\n```bash\n# Build all crates\ncargo build --release\n\n# Run tests\ncargo test\n\n# Build documentation\ncargo doc --open\n```\n\n## Acknowledgements\n\nThis project builds upon the work of several others who have reverse-engineered and documented the TP-Link Smart Home Protocol:\n\n- [softScheck/tplink-smartplug](https://github.com/softScheck/tplink-smartplug) - Original Python implementation and protocol reverse engineering by Lubomir Stroetmann\n- [TP-Link Smart Home Protocol Reverse Engineering](https://www.softscheck.com/en/blog/tp-link-reverse-engineering/) - Detailed blog post explaining the XOR autokey cipher used by TP-Link devices\n- [bobrik/kasa_exporter](https://github.com/bobrik/kasa_exporter) - Prometheus exporter for Kasa devices that inspired this project\n- [cshjsc/tplink-shome-protocol](https://github.com/cshjsc/tplink-shome-protocol) - Rust implementation of the TP-Link Smart Home Protocol\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmackenzie1%2Fkasa-rs","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcmackenzie1%2Fkasa-rs","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcmackenzie1%2Fkasa-rs/lists"}