A powerful command-line interface for controlling your Home Assistant instance. Control lights, switches, monitor energy usage, and query entity states directly from your terminal.
# Install
git clone https://github.com/Ajp121/ha-cli.git && cd ha-cli
pip install -r requirements.txt && pip install -e .
# Configure
ha configure # Enter your HA URL and token
# Use it!
ha light list
ha light on bedroom --brightness 50
ha energy status- π§ Easy Setup: Interactive configuration wizard on first run
- π‘ Light Control: Turn lights on/off, adjust brightness, set colors
- π Switch Control: Control switches with simple commands
- β‘ Energy Monitoring: Monitor power usage and energy consumption
- π State Queries: View and monitor entity states
- πΎ Persistent Config: Stores your HA URL and token securely
- π¨ Color Output: Beautiful, color-coded terminal output
- π§ͺ Tested: Comprehensive test suite included
- Python 3.7 or higher
- Home Assistant instance with API access
- Long-lived access token from Home Assistant
# Clone the repository
git clone https://github.com/Ajp121/ha-cli.git
cd ha-cli
# Install dependencies
pip install -r requirements.txt
# Install the CLI tool
pip install -e .This installs the ha command globally on your system.
Note: If the ha command isn't found after installation, you may need to add Python's Scripts directory to your PATH, or use:
python -m ha_cli.cli --helppython -m ha_cli.cli --help- Log into your Home Assistant web interface
- Click on your username in the bottom left
- Scroll to the bottom and click "Create Token" under "Long-Lived Access Tokens"
- Give it a name (e.g., "CLI Tool") and click "OK"
- Copy the token (you won't be able to see it again!)
Run the configuration command:
ha configureYou'll be prompted for:
- Home Assistant URL: e.g.,
http://homeassistant.local:8123orhttp://192.168.1.100:8123 - Access Token: Your long-lived access token from above
The tool will test the connection and save your configuration to ~/.ha-cli/config.json.
Turn on a light:
ha light on living_room
ha light on light.bedroomTurn on with brightness (0-100%):
ha light on living_room --brightness 50
ha light on living_room -b 75Turn on with color:
ha light on living_room --color red
ha light on living_room --color "255,128,0" # RGB formatSupported color names: red, green, blue, white, yellow, orange, purple
Turn off a light:
ha light off living_roomList all lights:
ha light list # Available lights only
ha light list --all # Include unavailable
ha light list --filter bedroom # Filter by nameTurn on a switch:
ha switch on plug_1
ha switch on switch.coffee_makerTurn off a switch:
ha switch off plug_1List all switches:
ha switch list # Available switches only
ha switch list --all # Include unavailable
ha switch list --filter kitchen # Filter by nameGet state of a specific entity:
ha state get light.living_room
ha state get sensor.temperatureList all entities:
ha state listList entities by domain:
ha state list --domain light
ha state list --domain sensorFilter by name:
ha state list --filter bedroom
ha state list --all # Include unavailable entitiesQuick energy overview:
ha energy statusCurrent power usage:
ha energy power # All circuits and devices
ha energy power --circuit 5 # Specific circuit onlyToday's energy consumption:
ha energy today # All circuits
ha energy today --circuit 1 # Specific circuitReconfigure connection:
ha configureGet help:
ha --help
ha light --help
ha switch --help
ha energy --help# Turn on bedroom light at 30% brightness
ha light on bedroom -b 30
# Turn on living room with warm white color
ha light on living_room --color "255,200,150"
# Check if coffee maker is on
ha state get switch.coffee_maker
# List all available lights (hides unavailable)
ha light list
# See your current power usage
ha energy status
# Check power draw on specific circuit
ha energy power --circuit 5
# Turn off lights
ha light off bedroom_main
ha light off bedroom_sideConfiguration is stored in ~/.ha-cli/config.json:
{
"url": "http://homeassistant.local:8123",
"token": "your-long-lived-access-token"
}- Verify your Home Assistant is running and accessible
- Check the URL is correct (include
http://orhttps://) - Ensure you're on the same network as your Home Assistant instance
- Generate a new long-lived access token
- Run
ha configureagain with the new token
- Check the entity ID exists in Home Assistant
- Entity IDs are case-sensitive
- You can omit the domain prefix (e.g., use
bedroominstead oflight.bedroom)
ha-cli/
βββ ha_cli/
β βββ __init__.py
β βββ cli.py # Main CLI commands
β βββ config.py # Configuration management
β βββ ha_api.py # Home Assistant API client
β βββ entities.py # Entity formatting utilities
β βββ setup.py # Setup utilities
βββ requirements.txt
βββ setup.py
βββ README.md
# Install test dependencies
pip install -r requirements.txt
# Run all tests
pytest
# Run with coverage report
pytest --cov=ha_cli
# Run specific test file
pytest tests/test_entities.pySee tests/README.md for more details.
MIT License - feel free to use and modify as needed!
Contributions welcome! This is a personal project but feel free to fork and customize for your needs.
Potential features to add:
- Scene activation
- Automation triggering
- Climate control
- Media player control
- Notification sending
- Bulk operations
- Interactive TUI mode