{"id":47339171,"url":"https://github.com/bewithdhanu/modem-power","last_synced_at":"2026-03-17T22:26:15.702Z","repository":{"id":200269840,"uuid":"705160566","full_name":"bewithdhanu/modem-power","owner":"bewithdhanu","description":"🔋 Smart modem power management with battery monitoring, automated charging, and FastAPI web interface","archived":false,"fork":false,"pushed_at":"2025-10-18T07:43:40.000Z","size":60,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-19T04:47:48.213Z","etag":null,"topics":["airtel","airtel-modem","automation","battery-monitoring","docker","fastapi","modem","power-management","smart-plug","tuya","tuya-api","tuya-devices"],"latest_commit_sha":null,"homepage":"http://localhost:8765/docs","language":"Python","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/bewithdhanu.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":null,"dco":null,"cla":null}},"created_at":"2023-10-15T07:56:55.000Z","updated_at":"2025-10-18T07:43:38.000Z","dependencies_parsed_at":"2023-10-16T10:19:39.717Z","dependency_job_id":"391441f9-e82a-4080-bbd9-b17cab42d825","html_url":"https://github.com/bewithdhanu/modem-power","commit_stats":null,"previous_names":["bewithdhanu/local-network-airtel-modem-control-with-tuya-smart-plug"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/bewithdhanu/modem-power","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bewithdhanu%2Fmodem-power","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bewithdhanu%2Fmodem-power/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bewithdhanu%2Fmodem-power/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bewithdhanu%2Fmodem-power/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bewithdhanu","download_url":"https://codeload.github.com/bewithdhanu/modem-power/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bewithdhanu%2Fmodem-power/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30633247,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-17T17:32:55.572Z","status":"ssl_error","status_checked_at":"2026-03-17T17:32:38.732Z","response_time":56,"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":["airtel","airtel-modem","automation","battery-monitoring","docker","fastapi","modem","power-management","smart-plug","tuya","tuya-api","tuya-devices"],"created_at":"2026-03-17T22:26:14.996Z","updated_at":"2026-03-17T22:26:15.692Z","avatar_url":"https://github.com/bewithdhanu.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# ModemPower 🔋 - Airtel Modem Control with Tuya Smart Plug\n\n![GitHub license](https://img.shields.io/badge/license-MIT-blue.svg)\n\n## Overview\n\nModemPower is an intelligent modem management system that automatically controls your Airtel modem using a Tuya Smart Plug. It monitors battery levels, manages power consumption, and provides automated control through a web API and scheduled tasks.\n\n## Features\n\n- **🔋 Battery Monitoring**: Automatically checks modem battery levels via local network\n- **⚡ Smart Power Management**: Automatically turns off modem when battery \u003e 80%, turns on when \u003c 20%\n- **🌐 FastAPI**: Modern RESTful API with automatic Swagger UI documentation\n- **⏰ Smart Scheduling**: Automated 4-hour charging cycles with 5-minute battery monitoring\n- **🔌 Tuya Integration**: Seamless control via Tuya Smart Plug\n- **🐳 Docker Support**: Easy deployment with Docker Compose\n- **📱 Cross-Platform**: Works on macOS, Linux, and Windows\n- **🛡️ Internet Connectivity Check**: Only operates when connected to modem network\n- **📧 Email Notifications**: Sends email alerts when modem is unreachable\n\n## Prerequisites\n\nBefore you get started, ensure you have the following:\n\n- **Airtel Modem**: Compatible with local network access (192.168.1.1)\n- **Tuya Smart Plug**: Connected to your network and configured\n- **Tuya IoT Platform Account**: For API access\n- **Python 3.x**: Installed on your system\n- **macOS or Linux**: For cron job support\n\n## Installation\n\n### Option 1: Docker (Recommended)\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/bewithdhanu/modem-power.git\n   cd ModemPower\n   ```\n\n2. **Configure environment:**\n   ```bash\n   cp env.example .env\n   # Edit .env with your Tuya credentials and modem IP\n   ```\n\n3. **Start with Docker:**\n   ```bash\n   ./start.sh\n   # Or manually: docker-compose up -d\n   ```\n\n### Option 2: Manual Installation\n\n1. **Clone the repository:**\n   ```bash\n   git clone https://github.com/bewithdhanu/modem-power.git\n   cd ModemPower\n   ```\n\n2. **Create virtual environment:**\n   ```bash\n   python -m venv venv\n   source venv/bin/activate  # On macOS/Linux\n   ```\n\n3. **Install dependencies:**\n   ```bash\n   pip install -r requirements.txt\n   ```\n\n## Configuration\n\n1. **Copy environment file:**\n   ```bash\n   cp env.py.example env.py\n   ```\n\n2. **Update `.env` with your credentials:**\n   ```bash\n   ACCESS_ID=your_tuya_access_id\n   ACCESS_KEY=your_tuya_access_key\n   USERNAME=your_tuya_username\n   PASSWORD=your_tuya_password\n   DEVICE_ID=your_tuya_device_id\n   ENDPOINT=https://openapi.tuyain.com\n   MODEM_IP=192.168.1.1  # Your modem's IP address\n   # Brevo email configuration:\n   BREVO_API_KEY=your_brevo_api_key\n   SENDER_EMAIL=your_email@example.com\n   RECIPIENT_EMAIL=recipient@example.com\n   TZ=Asia/Kolkata  # Indian timezone\n   ```\n\n## Usage\n\n\n### Docker Usage (Recommended)\n\n1. **Start services:**\n   ```bash\n   docker-compose up -d\n   ```\n\n2. **Access the API:**\n   - Main API: `http://localhost:8765`\n   - **Swagger UI**: `http://localhost:8765/docs` (Interactive API documentation)\n   - **ReDoc**: `http://localhost:8765/redoc` (Alternative API documentation)\n\n3. **View logs:**\n   ```bash\n   docker-compose logs -f\n   ```\n\n4. **Stop services:**\n   ```bash\n   docker-compose down\n   ```\n\n### Manual Usage\n\n1. **Start the Flask service:**\n   ```bash\n   source venv/bin/activate\n   python service.py\n   ```\n\n2. **Access the web interface:**\n   - Open your browser and go to `http://127.0.0.1:8765`\n\n### API Endpoints\n\n| Endpoint | Method | Description |\n|----------|--------|-------------|\n| `/` | GET | **Redirects to Swagger UI** |\n| `/docs` | GET | **Swagger UI** - Interactive API documentation |\n| `/redoc` | GET | **ReDoc** - Alternative API documentation |\n| `/automate-modem` | GET | Run modem automation (check battery, turn on/off) - Auto-scheduled every 5 minutes |\n| `/turn-on-charger` | GET | Turn on charger (with modem reachability check) - Auto-scheduled every 4 hours |\n| `/turn-off-charger` | GET | Turn off charger |\n| `/restart-modem` | GET | Restart the modem |\n| `/scheduler-status` | GET | Check scheduler status and next scheduled jobs |\n\n\u003e **🎯 Pro Tip**: Visit `http://localhost:8765/docs` to see the interactive Swagger UI where you can test all endpoints directly from your browser!\n\n\n## Troubleshooting\n\n### Common Issues\n\n1. **Internet connectivity issues:**\n   - Ensure you're connected to the modem's WiFi network\n   - Check if the modem is accessible at `192.168.1.1`\n\n2. **Tuya API errors:**\n   - Verify your credentials in `env.py`\n   - Check if your Tuya subscription is active\n   - Ensure device ID is correct\n\n### Manual Testing\n\nTest individual components:\n\n```bash\n# Test internet connectivity\npython -c \"from modem import is_wifi_connected; print('Connected:', is_wifi_connected())\"\n\n# Test battery reading\npython -c \"from modem import getBatteryPercent; print('Battery:', getBatteryPercent())\"\n\n# Test device control\npython -c \"from device import getStatus; print('Device status:', getStatus())\"\n```\n\n## Docker Services\n\nThe Docker Compose setup includes two services:\n\n1. **modem-power**: Flask web service running on port 8765\n2. **cron**: Uses `willfarrell/crontab` image for simple scheduling:\n   - Turn on modem every day at 1:00 PM\n   - Check battery and auto-manage every 5 minutes\n   - Standard crontab format for easy customization\n\n### Network Configuration\n\nThe containers use **host networking** to access your router:\n- Containers share the host's network interface\n- Can directly access your modem at `192.168.1.1` (or configured IP)\n- No port mapping needed for internal communication\n- Flask service accessible at `http://localhost:8765`\n\n### Simple Cron Scheduling\n\nEdit the `crontab` file to customize schedules:\n\n```bash\n# Edit the crontab file\nnano crontab\n\n# Current default schedules:\n# 0 13 * * * curl -s http://localhost:8765/turn-on-charger  # Daily 1PM\n# */5 * * * * curl -s http://localhost:8765/automate-modem  # Every 5 minutes\n```\n\n**Cron Examples**:\n- `0 13 * * *` - Every day at 1:00 PM\n- `*/5 * * * *` - Every 5 minutes  \n- `0 9 * * 1-5` - Weekdays at 9:00 AM\n- `0 14 * * 0` - Every Sunday at 2:00 PM\n\n### Brevo Email Service (Free \u0026 Easy)\n\nWhen the modem is unreachable, the system will send you a beautiful HTML email notification via Brevo API.\n\n#### Setup Brevo (2 minutes):\n1. **Create free account**: Go to [brevo.com](https://brevo.com) and sign up\n2. **Get API key**: Go to [API Keys](https://app.brevo.com/settings/keys/api) and create a new key\n3. **Add to `.env`**:\n   ```bash\n   BREVO_API_KEY=your_brevo_api_key\n   SENDER_EMAIL=your_email@example.com\n   SENDER_NAME=ModemPower\n   RECIPIENT_EMAIL=recipient@example.com\n   RECIPIENT_NAME=Your Name\n   ```\n\n#### Why Brevo is Perfect:\n- ✅ **Free**: 300 emails/day free forever\n- ✅ **No SMTP**: Uses simple REST API\n- ✅ **No passwords**: Just API key authentication\n- ✅ **Beautiful emails**: HTML formatted notifications\n- ✅ **Reliable**: Enterprise-grade email delivery\n- ✅ **Easy setup**: 2 minutes to configure\n- ✅ **No app passwords**: No complex authentication\n\n## File Structure\n\n```\nModemPower/\n├── device.py              # Tuya device control\n├── modem.py               # Modem management\n├── service.py             # Flask web service\n├── crontab                # Simple cron schedule file\n├── env.py                 # Configuration (legacy)\n├── env.example            # Environment template\n├── docker-compose.yml     # Docker services configuration\n├── Dockerfile             # Container definition\n├── start.sh               # Startup script\n└── requirements.txt       # Dependencies\n```\n\n## Security Notes\n\n- Keep your `.env` file secure and never commit it to version control\n- The service runs on localhost (127.0.0.1:8765) by default\n- All API calls are made over your local network\n- Tuya credentials are stored in environment variables\n- Port 8765 is used to avoid conflicts with common services\n- Docker containers run in isolated network environment\n\n## Contributing\n\n1. Fork the repository\n2. Create a feature branch\n3. Make your changes\n4. Test thoroughly\n5. Submit a pull request\n\n## Acknowledgments\n\n- [Tuya Official Python SDK](https://github.com/tuya/tuya-iot-python-sdk)\n- Flask web framework\n- Airtel modem API\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n\n## Authors\n\n|Name|Type|\n|--|--|\n|[Dhanu K](https://github.com/bewithdhanu)|Author|","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewithdhanu%2Fmodem-power","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbewithdhanu%2Fmodem-power","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbewithdhanu%2Fmodem-power/lists"}