{"id":31798262,"url":"https://github.com/ngoviet/esp32-smart-led-control","last_synced_at":"2026-04-20T04:03:32.411Z","repository":{"id":318293358,"uuid":"1070669142","full_name":"ngoviet/esp32-smart-led-control","owner":"ngoviet","description":" ESP32 Smart LED Control System with Home Assistant integration, environmental sensors, motion detection, and intelligent automation. Modular ESPHome architecture for easy maintenance and expansion.","archived":false,"fork":false,"pushed_at":"2025-10-06T09:25:11.000Z","size":39,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-10-06T11:29:17.308Z","etag":null,"topics":["automation","bme280","esp32","esphome","home-assistant","iot","led-control","motion-sensor","smart-home"],"latest_commit_sha":null,"homepage":null,"language":"Batchfile","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/ngoviet.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2025-10-06T09:24:26.000Z","updated_at":"2025-10-06T09:24:37.000Z","dependencies_parsed_at":"2025-10-06T11:29:19.295Z","dependency_job_id":"04ca8b7a-ce6f-4c0b-9b7d-40c22b0d9b90","html_url":"https://github.com/ngoviet/esp32-smart-led-control","commit_stats":null,"previous_names":["ngoviet/esp32-smart-led-control"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ngoviet/esp32-smart-led-control","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngoviet%2Fesp32-smart-led-control","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngoviet%2Fesp32-smart-led-control/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngoviet%2Fesp32-smart-led-control/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngoviet%2Fesp32-smart-led-control/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ngoviet","download_url":"https://codeload.github.com/ngoviet/esp32-smart-led-control/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ngoviet%2Fesp32-smart-led-control/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279005410,"owners_count":26083883,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-10T02:00:06.843Z","response_time":62,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["automation","bme280","esp32","esphome","home-assistant","iot","led-control","motion-sensor","smart-home"],"created_at":"2025-10-10T21:16:33.027Z","updated_at":"2025-10-10T21:16:34.714Z","avatar_url":"https://github.com/ngoviet.png","language":"Batchfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ESP32 Smart LED Control System\n\n🚀 **Hệ thống điều khiển LED thông minh với cảm biến môi trường và Home Assistant**\n\n## ✨ Tính năng chính\n\n- 🏠 **Tích hợp Home Assistant** - Điều khiển từ xa qua HA\n- 🌡️ **Giám sát môi trường** - Nhiệt độ, độ ẩm, áp suất (BME280)\n- 🌧️ **Cảm biến mưa** - Phát hiện mưa tự động\n- 👤 **Cảm biến chuyển động** - LD2410 phát hiện người\n- 🕐 **Tự động theo thời gian** - Hoạt động 18:00-06:00\n- 🧠 **LED2 thông minh** - Điều khiển thủ công với tự động quay về\n- 📊 **Giám sát hệ thống** - RAM, CPU, WiFi, uptime\n- 🔧 **Cấu trúc modular** - Dễ bảo trì và mở rộng\n\n## 🛠️ Phần cứng\n\n- **ESP32 WROOM-32** (4MB Flash, 320KB RAM)\n- **BME280** - Cảm biến nhiệt độ, độ ẩm, áp suất (I2C)\n- **LD2410** - Cảm biến chuyển động (UART)\n- **Rain Sensor** - Cảm biến mưa (ADC)\n- **2x LED strips** - Đèn LED điều khiển\n- **MOSFET 24V** - Điều khiển công suất cao\n\n## 📋 Kết nối GPIO\n\n```\nGPIO21 (SDA) ➜ BME280 SDA\nGPIO22 (SCL) ➜ BME280 SCL\nGPIO16 (RX)  ➜ LD2410 TX  \nGPIO17 (TX)  ➜ LD2410 RX\nGPIO36 (ADC) ➜ Rain Sensor\nGPIO12       ➜ LED 1 Control\nGPIO13       ➜ LED 2 Control  \nGPIO27       ➜ Manual Button\n```\n\n## 🚀 Cài đặt nhanh\n\n### 1. Chuẩn bị môi trường\n```bash\npip install esphome\n```\n\n### 2. Cấu hình WiFi\n```bash\ncp secrets.template.yaml secrets.yaml\n# Sửa thông tin WiFi trong secrets.yaml\n```\n\n### 3. Compile \u0026 Flash\n```bash\n# Windows\nflash.bat\n\n# Linux/MacOS  \nesphome run main.yaml\n```\n\n## 🏗️ Cấu trúc dự án (Modular Architecture)\n\n```\nesp32_led_temp_pressure/\n├── main.yaml                    # File cấu hình chính (MODULAR)\n├── components/                  # Thư mục chứa các module\n│   ├── common.yaml              # Cấu hình cơ bản (Logger, API, OTA, I2C)\n│   ├── motion_sensor.yaml       # Cảm biến chuyển động LD2410\n│   ├── led_controls.yaml        # Điều khiển LED và nút bấm\n│   ├── environment_sensors.yaml # Cảm biến môi trường (BME280, mưa)\n│   ├── wifi_monitoring.yaml     # WiFi cấu hình cơ bản\n│   ├── diagnostic.yaml          # 🆕 Chẩn đoán hệ thống tổng hợp\n│   └── time_automation.yaml     # Quản lý thời gian và tự động hóa\n├── backup/                      # 📁 Old files (không còn dùng)\n│   ├── esp32_led_temp_pressure.yaml # File gốc monolithic  \n│   ├── flash.bat                # Script flash cũ\n│   ├── esare.bat                # Script erase cũ\n│   ├── log.bat                  # Script log cũ\n│   └── README_BACKUP.md         # Hướng dẫn backup\n├── build_modular.bat            # 🆕 Script build/upload mới\n├── validate_modular.py          # 🆕 Script validation  \n├── so_do_esp32_led_24v_mosfet.pdf # Sơ đồ mạch\n└── README.md                    # File này\n```\n\n## 📋 Mô tả các module\n\n### 1. `common.yaml` - Cấu hình cơ bản\n- Cấu hình ESP32, WiFi, Logger\n- API, OTA, Web Server\n- I2C, Button restart\n- Interval kiểm tra WiFi\n\n### 2. `motion_sensor.yaml` - Cảm biến chuyển động\n- Cấu hình LD2410 UART\n- Binary sensor phát hiện người\n- Logic tự động bật/tắt LED2 theo thời gian\n\n### 3. `led_controls.yaml` - Điều khiển LED\n- 2 LED (GPIO12, GPIO13)\n- Chế độ tự động LED2\n- Nút bấm vật lý và cảm ứng\n- Logic xử lý các loại nhấn nút\n\n### 4. `environment_sensors.yaml` - Cảm biến môi trường\n- BME280: nhiệt độ, áp suất, độ ẩm\n- Cảm biến mưa (ADC)\n- Binary sensor phát hiện mưa với ngưỡng\n\n### 5. `wifi_monitoring.yaml` - Cấu hình WiFi cơ bản\n- Cấu hình WiFi fallback và captive portal\n- mDNS và network discovery settings\n\n### 6. `diagnostic.yaml` - Chẩn đoán \u0026 Giám sát hệ thống  \n- **WiFi Diagnostics**: RSSI, quality %, signal bars, connection info\n- **System Health**: Memory usage %, CPU load, temperature monitoring\n- **Uptime Tracking**: Seconds và human-readable format\n- **Alert Systems**: Low memory, high temp, poor WiFi warnings\n- **Health Scoring**: Overall system health assessment\n\n### 6. `time_automation.yaml` - Tự động hóa theo thời gian\n- Đồng bộ thời gian với Home Assistant và SNTP\n- Tự động bật/tắt chế độ auto LED2 theo khung giờ\n- Quản lý các biến toàn cục thời gian\n\n## 🚀 Cách sử dụng\n\n### Biên dịch với file mới:\n```bash\nesphome compile main.yaml\nesphome upload main.yaml\n```\n\n### Hoặc dùng script tiện lợi:\n```cmd\nbuild_modular.bat\n```\n\n### Khôi phục file cũ (nếu cần):\n```cmd\n# Copy file gốc từ backup\ncopy backup\\esp32_led_temp_pressure.yaml .\n\n# Sử dụng scripts cũ\nbackup\\flash.bat\nbackup\\log.bat\n```\n\n### Để sửa đổi:\n1. **Thay đổi cấu hình WiFi**: Sửa trong `components/common.yaml`\n2. **Điều chỉnh cảm biến**: Sửa trong `components/environment_sensors.yaml` \n3. **Thay đổi GPIO**: Sửa trong `components/led_controls.yaml`\n4. **Cập nhật logic motion**: Sửa trong `components/motion_sensor.yaml`\n5. **Điều chỉnh thời gian**: Sửa trong `components/time_automation.yaml`\n\n## 🔧 Cấu hình Hardware\n\n### GPIO Mapping:\n- **GPIO12**: LED 1\n- **GPIO13**: LED 2  \n- **GPIO14**: Nút bấm LED 1 (INPUT_PULLUP)\n- **GPIO16**: LD2410 RX\n- **GPIO17**: LD2410 TX\n- **GPIO21**: I2C SDA (BME280)\n- **GPIO22**: I2C SCL (BME280)\n- **GPIO27**: ~~Nút cảm ứng LED 2~~ (VÔ HIỆU HÓA)\n- **GPIO32**: Cảm biến mưa (ADC)\n\n### Cảm biến:\n- **LD2410**: Cảm biến chuyển động mmWave\n- **BME280**: Nhiệt độ, áp suất, độ ẩm (I2C 0x76)\n- **Rain Sensor**: Cảm biến mưa analog\n\n## 🏠 Tích hợp Home Assistant\n\nCần tạo các input_datetime helpers trong HA:\n- `input_datetime.auto_led2_start`: Thời gian bắt đầu tự động\n- `input_datetime.auto_led2_end`: Thời gian kết thúc tự động\n\n## ⚡ Ưu điểm cấu trúc modular\n\n1. **Dễ bảo trì**: Mỗi chức năng trong file riêng\n2. **Tái sử dụng**: Có thể dùng lại các module cho dự án khác\n3. **Debug dễ**: Dễ tìm và sửa lỗi trong từng module\n4. **Mở rộng**: Thêm tính năng mới không ảnh hưởng code cũ\n5. **Cộng tác**: Nhiều người có thể làm việc trên các module khác nhau\n6. **Version control**: Git tracking thay đổi từng module riêng biệt\n\n## 🔄 Backup \u0026 Restore\n\n- File gốc `esp32_led_temp_pressure.yaml` được giữ lại làm backup\n- Để khôi phục: copy nội dung file gốc vào `main.yaml`\n- Để cập nhật từ modular về monolithic: tổng hợp tất cả components vào 1 file","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngoviet%2Fesp32-smart-led-control","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fngoviet%2Fesp32-smart-led-control","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fngoviet%2Fesp32-smart-led-control/lists"}