A command-line interface for controlling Amazon Alexa devices using the unofficial Alexa API.
Control your smart home from the terminal. Turn lights on/off, adjust thermostats, lock doors, play music, make announcements - anything you can say to Alexa, you can script.
brew install buddyh/tap/alexacligo install github.com/buddyh/alexa-cli/cmd/alexa@latestgit clone https://github.com/buddyh/alexa-cli
cd alexa-cli
make build
./bin/alexacli --helpThis CLI uses Amazon's unofficial API (the same one the Alexa app uses). You'll need to obtain a refresh token using the alexa-cookie-cli tool.
Download alexa-cookie-cli from the releases page, then:
# For US Amazon accounts
./alexa-cookie-cli --amazonPage amazon.com --baseAmazonPage amazon.com --amazonPageProxyLanguage en_US --acceptLanguage en-USThis opens a local proxy at http://127.0.0.1:8080. Log into your Amazon account there, and the refresh token will be displayed.
# Interactive
alexacli auth
# Direct
alexacli auth <your-refresh-token>
# Or set environment variable
export ALEXA_REFRESH_TOKEN=<your-token>Configuration is stored in ~/.alexa-cli/config.json.
# List all Echo devices
alexacli devices
# JSON output for scripting
alexacli devices --json# Speak on a specific device
alexacli speak "Hello world" -d "Kitchen Echo"
# Announce to ALL devices
alexacli speak "Dinner is ready!" --announce
# Device name matching is flexible
alexacli speak "Build complete" -d Kitchen
alexacli speak "Build complete" -d "Living Room"Send any command as if you spoke it to Alexa. This is the primary way to control smart home devices:
# Smart home control - lights, switches, plugs
alexacli command "turn off the living room lights" -d Kitchen
alexacli command "turn on the porch light" -d Kitchen
alexacli command "dim the bedroom lights to 50 percent" -d Bedroom
# Thermostats and climate
alexacli command "set thermostat to 72 degrees" -d Bedroom
alexacli command "what's the temperature inside" -d Kitchen
# Locks and security
alexacli command "lock the front door" -d Kitchen
# Play music
alexacli command "play jazz music" -d "Living Room"
alexacli command "stop" -d "Living Room"
# Ask questions
alexacli command "what's the weather" -d Kitchen
# Timers and reminders
alexacli command "set a timer for 10 minutes" -d KitchenThe -d flag specifies which Echo device processes the command. The device itself doesn't need to be near the smart home device - Alexa routes the command appropriately.
Send a command and capture Alexa's text response:
# Query and get the response
alexacli ask "what's the thermostat set to" -d Kitchen
# Output: The thermostat is set to 68 degrees.
alexacli ask "what's on my calendar today" -d Kitchen
# Output: You have 2 events today. First, standup at 9 AM...
# JSON output for parsing
alexacli ask "what time is it" -d Kitchen --json
# {"data":{"device":"Kitchen","question":"what time is it","response":"The time is 3:22 PM."},"success":true}This retrieves Alexa's actual response by polling the voice activity history. Useful for:
- Querying smart home device state
- Getting Alexa-specific information (calendar, reminders, timers)
- Verifying that commands worked
View recent voice activity:
alexacli history
alexacli history --limit 5
alexacli history --jsonShows what was said and what Alexa responded with.
# List available routines
alexacli routine list
# Execute a routine
alexacli routine run "Good Night"For granular, programmatic control of smart home devices without natural language:
# List smart home devices with IDs and capabilities
alexacli sh list
# Direct device control by name
alexacli sh on "Kitchen Light"
alexacli sh off "All Lights"
alexacli sh brightness "Bedroom Lamp" 50Note: For most use cases, especially AI agents,
alexacli commandis recommended. Natural language commands are more flexible and match how you'd interact with Alexa verbally. The direct API is useful when you need exact device IDs or want to avoid natural language parsing.
All commands support --json for machine-readable output:
alexacli devices --json | jq '.[].name'
alexacli speak "test" -d Kitchen --json| Command | Description | Status |
|---|---|---|
alexacli devices |
List all Echo devices | Working |
alexacli speak <text> -d <device> |
Text-to-speech on device | Working |
alexacli speak <text> --announce |
Announce to all devices | Working |
alexacli command <text> -d <device> |
Voice command (smart home, music, etc.) | Working |
alexacli ask <text> -d <device> |
Send command, get response back | Working |
alexacli history |
View recent voice activity | Working |
alexacli auth |
Configure authentication | Working |
alexacli routine list |
List routines | WIP |
alexacli routine run <name> |
Execute routine | WIP |
alexacli sh list |
List smart home devices | WIP |
alexacli sh on/off <device> |
Control device | WIP |
Note: Routines and Direct Smart Home API are work-in-progress. Use
alexacli commandfor smart home control - it's fully working and actually preferred for AI/agentic use since natural language is more flexible than device IDs.
This CLI was built specifically to allow AI assistants to control smart home devices. The natural language command interface is ideal for agentic use - the AI can construct commands the same way a human would speak to Alexa:
# AI can control any smart home device using natural language
alexacli command "turn off all the lights" -d Kitchen
alexacli command "set the thermostat to 68" -d Kitchen
alexacli command "lock the front door" -d Kitchen
# Notifications and announcements
alexacli speak "The build finished successfully" -d Office
alexacli speak "Reminder: standup in 5 minutes" --announce#!/bin/bash
# Announce when a long-running job finishes
make build && alexacli speak "Build complete!" --announce# Morning routine script
alexacli command "good morning" -d Bedroom
alexacli command "turn on kitchen lights" -d Kitchen
alexacli command "what's on my calendar today" -d KitchenThe refresh token is valid for approximately 14 days. If you get authentication errors, run alexacli auth again with a fresh token from alexa-cookie-cli.
Run alexacli auth <token> to configure your refresh token.
Use alexacli devices to see exact device names, then match them in your commands. Partial matching is supported.
Try running the same command with alexacli command instead - this sends it as a voice command which has broader support.
This CLI uses the same unofficial API that the Alexa mobile app uses. It:
- Exchanges your refresh token for session cookies
- Obtains a CSRF token from alexa.amazon.com
- Sends commands to pitangui.amazon.com (US) or layla.amazon.com (EU)
This approach is used by many popular projects including alexa-remote-control and Home Assistant's Alexa integration.
This is an unofficial tool that uses Amazon's private APIs. It may break at any time if Amazon changes their API. Use at your own risk.
This project builds on the work of several excellent open source projects:
- alexa-cookie-cli by adn77 - Token authentication tool (required for setup)
- alexa-cookie2 by Apollon77 - The underlying authentication library
- alexa-remote-control by thorsten-gehrig - Bash implementation that documented the API
- alexa_media_player by alandtse - Home Assistant integration that proved the approach at scale
Without these projects' reverse-engineering efforts and documentation, this CLI wouldn't exist.
MIT