A location-based smart air conditioning control system that automatically manages your AC based on your proximity to home using Home Assistant, IFTTT, and AI.
- Location-based automation: Automatically turns AC on/off based on your distance from home
- Smart distance logic:
> 2 miles awayβ Turn AC OFF0.25-2 miles approachingβ Turn AC ON< 0.25 miles (home)β No action
- Cloud deployment ready: Deploy to GCP or run locally
- Home Assistant integration: Excellent mobile app for location tracking
- IFTTT compatibility: Works with any AC system that supports IFTTT
- AI-powered decisions: Uses OpenAI for intelligent decision making
- Easy migration: Switch between cloud and local (Coral dev board) deployments
Phone Location β Home Assistant β AC Agent β IFTTT β Your AC
- Home Assistant: Tracks your phone's location via mobile app
- AC Agent: FastAPI service that makes smart decisions based on distance
- IFTTT: Triggers your AC control system
- Docker: Containerized deployment for easy setup
-
Clone and setup:
git clone <this-repo> cd smart-ac-agent cp env.example .env
-
Configure environment:
# Edit .env with your values IFTTT_KEY=your_ifttt_webhook_key OPENAI_API_KEY=your_openai_api_key HOME_LAT=40.7128 HOME_LON=-74.0060 -
Deploy to GCP:
./scripts/deploy-cloud.sh
-
Run locally:
docker-compose up -d
-
Access services:
- Home Assistant: http://localhost:8123
- AC Agent: http://localhost:8000
- Create IFTTT applets:
- AC On: Webhook trigger
ac_onβ Your AC control - AC Off: Webhook trigger
ac_offβ Your AC control
- AC On: Webhook trigger
- Get your webhook key from https://ifttt.com/maker_webhooks
- Complete initial setup wizard
- Install Home Assistant mobile app
- Enable location permissions
- Configure webhook automation (see
SETUP.md)
# Test AC Agent directly
curl -X POST http://your-server:8000/ping \
-H "Content-Type: application/json" \
-d '{"lat": 40.7500, "lon": -74.0500, "speed_mph": 25}'smart-ac-agent/
βββ main.py # FastAPI AC Agent service
βββ docker-compose.yml # Local deployment
βββ docker-compose.cloud.yml # Cloud deployment with profiles
βββ dockerfile # AC Agent container
βββ requirements.txt # Python dependencies
βββ .env # Environment configuration
βββ scripts/
β βββ deploy-cloud.sh # Cloud deployment script
β βββ migrate-to-local.sh # Migration script
β βββ check-gcp-status.sh # GCP status checker
βββ caddy/
β βββ Caddyfile # SSL reverse proxy config
βββ homeassistant/
β βββ configuration.yaml # HA automation config
βββ docs/
β βββ SETUP.md # Detailed setup guide
β βββ CLOUD_DESIGN.md # Architecture documentation
β βββ GCP_DEPLOYMENT_GUIDE.md # GCP deployment guide
βββ README.md # This file
| Variable | Description | Example |
|---|---|---|
DEPLOYMENT_MODE |
Deployment environment | cloud or local |
IFTTT_KEY |
IFTTT webhook key | abc123def456 |
IFTTT_AC_ON_EVENT |
IFTTT AC on event name | ac_on |
IFTTT_AC_OFF_EVENT |
IFTTT AC off event name | ac_off |
HOME_LAT |
Home latitude | 40.7128 |
HOME_LON |
Home longitude | -74.0060 |
OPENAI_API_KEY |
OpenAI API key | sk-... |
EXTERNAL_URL |
External HA URL | http://34.73.50.34:8123 |
WEBHOOK_URL |
AC Agent webhook URL | http://34.73.50.34:8000/ping |
- Cloud profile: Includes Caddy reverse proxy for SSL
- Local profile: Simple local deployment
- Monitoring profile: Adds Prometheus/Grafana (optional)
# Install dependencies
pip install -r requirements.txt
# Run AC Agent
uvicorn main:app --reload
# Run Home Assistant
docker run -d --name homeassistant \
-p 8123:8123 \
-v $(pwd)/homeassistant:/config \
ghcr.io/home-assistant/home-assistant:stable# Run tests
python test_ac_standalone.py
# Test IFTTT connectivity
curl -X POST "https://maker.ifttt.com/trigger/ac_on/with/key/YOUR_KEY"# AC Agent logs
docker-compose logs -f smart-ac-agent
# Home Assistant logs
docker-compose logs -f homeassistant
# All services
docker-compose logs -f- AC Agent:
http://your-server:8000/health - Home Assistant:
http://your-server:8123
./scripts/migrate-to-local.shThis script:
- Backs up your configuration
- Switches to local profile
- Configures for Coral dev board deployment
- AC Agent not starting: Check OpenAI API key in
.env - IFTTT not triggering: Verify webhook key and event names
- Location not updating: Check Home Assistant mobile app permissions
- Automation not working: Verify device tracker name in
configuration.yaml
# Check service status
docker-compose ps
# Check AC Agent health
curl http://localhost:8000/health
# Test manual trigger
curl -X POST http://localhost:8000/ping \
-H "Content-Type: application/json" \
-d '{"lat": YOUR_LAT, "lon": YOUR_LON, "speed_mph": 0}'- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
- Home Assistant team for excellent location tracking
- IFTTT for device integration
- OpenAI for AI decision making
- Docker for containerization
π Enjoy your smart, location-aware AC system! π