Instructions for AI coding agents working with this repository.
This project provides two methods to connect Tuya BLE plant sensors (SGS01) to Home Assistant when the HA instance has no local Bluetooth hardware.
├── docs/ # Architecture and SOPs
├── esphome/ # Option A: ESP32 BLE proxy configs
├── home-assistant/ # HA automations and dashboard cards
├── pi-fallback/ # Option B: Raspberry Pi implementation
docs/architecture.md- System design and data flow diagramsdocs/sop.md- Step-by-step setup proceduresesphome/ble-proxy.yaml- ESPHome configuration for ESP32pi-fallback/ble_poller.py- Main Python poller scriptpi-fallback/tuya_ble.py- Tuya BLE protocol implementation
- ESPHome YAML configuration in
esphome/ - No code changes typically needed; just update
substitutionsfor new devices
- Python 3.9+ with async/await patterns
- Uses
bleakfor BLE,paho-mqttfor MQTT - Tuya BLE protocol implementation in
tuya_ble.py
secrets.yaml- WiFi/API credentialsconfig.yaml- MQTT credentials and device keys- Any file containing
local_key,device_id, or passwords
- Python: Follow PEP 8, use type hints where practical
- YAML: 2-space indentation
- Keep scripts compatible with Raspberry Pi Zero W (ARM, limited resources)
This repository enforces Conventional Commits via pre-commit. All commit messages must follow the format:
type(scope): subject
Allowed types: feat, fix, chore, docs, refactor, ci, test, style, perf, revert
Examples:
feat: add MQTT reconnect logic
fix(ble_poller): handle timeout on sensor scan
chore: update pre-commit hook versions
docs: add architecture diagram to README
refactor(tuya_ble): simplify packet parsing
ci: add GitHub Actions lint workflow
The scope is optional. To activate the commit-msg hook after cloning, run:
make install-hooks# Option B: Test single poll
sudo /opt/ble-poller/venv/bin/python /opt/ble-poller/ble_poller.py --once
# Scan for BLE devices
sudo /opt/ble-poller/venv/bin/python /opt/ble-poller/ble_poller.py --scan