thermostat
This commit is contained in:
190
tools/README_device_simulator.md
Normal file
190
tools/README_device_simulator.md
Normal file
@@ -0,0 +1,190 @@
|
||||
# Device Simulator
|
||||
|
||||
Unified MQTT device simulator für das Home Automation System.
|
||||
|
||||
## Übersicht
|
||||
|
||||
Dieser Simulator ersetzt die einzelnen Simulatoren (`sim_test_lampe.py`, `sim_thermo.py`) und vereint alle Device-Typen in einer einzigen Anwendung.
|
||||
|
||||
## Unterstützte Geräte
|
||||
|
||||
### Lampen (3 Geräte)
|
||||
- `test_lampe_1` - Mit Power und Brightness
|
||||
- `test_lampe_2` - Mit Power und Brightness
|
||||
- `test_lampe_3` - Mit Power und Brightness
|
||||
|
||||
**Features:**
|
||||
- `power`: "on" oder "off"
|
||||
- `brightness`: 0-100
|
||||
|
||||
### Thermostaten (1 Gerät)
|
||||
- `test_thermo_1` - Vollständiger Thermostat mit Temperatur-Simulation
|
||||
|
||||
**Features:**
|
||||
- `mode`: "off", "heat", oder "auto"
|
||||
- `target`: Soll-Temperatur (5.0-30.0°C)
|
||||
- `current`: Ist-Temperatur (wird simuliert)
|
||||
- `battery`: Batteriestand (90%)
|
||||
- `window_open`: Fensterstatus (false)
|
||||
|
||||
**Temperatur-Simulation:**
|
||||
- Alle 5 Sekunden wird die Ist-Temperatur angepasst
|
||||
- **HEAT/AUTO Mode**: Drift zu `target` (+0.2°C pro Intervall)
|
||||
- **OFF Mode**: Drift zu Ambient-Temperatur 18°C (-0.2°C pro Intervall)
|
||||
|
||||
## MQTT-Konfiguration
|
||||
|
||||
- **Broker**: 172.16.2.16:1883 (konfigurierbar via ENV)
|
||||
- **QoS**: 1 für alle Publishes
|
||||
- **Retained**: Ja für alle State-Messages
|
||||
- **Client ID**: device_simulator
|
||||
|
||||
### Topics
|
||||
|
||||
Für jedes Gerät:
|
||||
- Subscribe: `vendor/{device_id}/set` (QoS 1)
|
||||
- Publish: `vendor/{device_id}/state` (QoS 1, retained)
|
||||
|
||||
## Verwendung
|
||||
|
||||
### Starten
|
||||
|
||||
```bash
|
||||
poetry run python tools/device_simulator.py
|
||||
```
|
||||
|
||||
Oder im Hintergrund:
|
||||
|
||||
```bash
|
||||
poetry run python tools/device_simulator.py > /tmp/simulator.log 2>&1 &
|
||||
```
|
||||
|
||||
### Umgebungsvariablen
|
||||
|
||||
```bash
|
||||
export MQTT_BROKER="172.16.2.16" # MQTT Broker Host
|
||||
export MQTT_PORT="1883" # MQTT Broker Port
|
||||
```
|
||||
|
||||
## Testen
|
||||
|
||||
Ein umfassendes Test-Skript ist verfügbar:
|
||||
|
||||
```bash
|
||||
./tools/test_device_simulator.sh
|
||||
```
|
||||
|
||||
Das Test-Skript:
|
||||
1. Stoppt alle laufenden Services
|
||||
2. Startet Abstraction Layer, API und Simulator
|
||||
3. Testet alle Lampen-Operationen
|
||||
4. Testet alle Thermostat-Operationen
|
||||
5. Verifiziert MQTT State Messages
|
||||
6. Zeigt Simulator-Logs
|
||||
|
||||
## Beispiele
|
||||
|
||||
### Lampe einschalten
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/devices/test_lampe_1/set \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type":"light","payload":{"power":"on"}}'
|
||||
```
|
||||
|
||||
### Helligkeit setzen
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/devices/test_lampe_1/set \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type":"light","payload":{"brightness":75}}'
|
||||
```
|
||||
|
||||
### Thermostat Mode setzen
|
||||
|
||||
```bash
|
||||
curl -X POST http://localhost:8001/devices/test_thermo_1/set \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"type":"thermostat","payload":{"mode":"heat","target":22.5}}'
|
||||
```
|
||||
|
||||
### State abfragen via MQTT
|
||||
|
||||
```bash
|
||||
# Lampe
|
||||
mosquitto_sub -h 172.16.2.16 -t 'vendor/test_lampe_1/state' -C 1
|
||||
|
||||
# Thermostat
|
||||
mosquitto_sub -h 172.16.2.16 -t 'vendor/test_thermo_1/state' -C 1
|
||||
```
|
||||
|
||||
## Architektur
|
||||
|
||||
```
|
||||
Browser/API
|
||||
↓ POST /devices/{id}/set
|
||||
API Server (Port 8001)
|
||||
↓ MQTT: home/{type}/{id}/set
|
||||
Abstraction Layer
|
||||
↓ MQTT: vendor/{id}/set
|
||||
Device Simulator
|
||||
↓ MQTT: vendor/{id}/state (retained)
|
||||
Abstraction Layer
|
||||
↓ MQTT: home/{type}/{id}/state (retained)
|
||||
↓ Redis Pub/Sub: ui:updates
|
||||
UI / Dashboard
|
||||
```
|
||||
|
||||
## Logs
|
||||
|
||||
Der Simulator loggt alle Aktivitäten:
|
||||
- Startup und MQTT-Verbindung
|
||||
- Empfangene SET-Commands
|
||||
- State-Änderungen
|
||||
- Temperature-Drift (Thermostaten)
|
||||
- Publizierte State-Messages
|
||||
|
||||
Log-Level: INFO
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Simulator startet nicht
|
||||
|
||||
```bash
|
||||
# Prüfe ob Port bereits belegt
|
||||
lsof -ti:1883
|
||||
|
||||
# Prüfe MQTT Broker
|
||||
mosquitto_sub -h 172.16.2.16 -t '#' -C 1
|
||||
```
|
||||
|
||||
### Keine State-Updates
|
||||
|
||||
```bash
|
||||
# Prüfe Simulator-Log
|
||||
tail -f /tmp/simulator.log
|
||||
|
||||
# Prüfe MQTT Topics
|
||||
mosquitto_sub -h 172.16.2.16 -t 'vendor/#' -v
|
||||
```
|
||||
|
||||
### API antwortet nicht
|
||||
|
||||
```bash
|
||||
# Prüfe ob API läuft
|
||||
curl http://localhost:8001/devices
|
||||
|
||||
# Prüfe API-Log
|
||||
tail -f /tmp/api.log
|
||||
```
|
||||
|
||||
## Integration
|
||||
|
||||
Der Simulator integriert sich nahtlos in das Home Automation System:
|
||||
|
||||
1. **Abstraction Layer** empfängt Commands und sendet sie an Simulator
|
||||
2. **Simulator** reagiert und publiziert neuen State
|
||||
3. **Abstraction Layer** empfängt State und publiziert zu Redis
|
||||
4. **UI** empfängt Updates via SSE und aktualisiert Dashboard
|
||||
|
||||
Alle Komponenten arbeiten vollständig asynchron über MQTT.
|
||||
Reference in New Issue
Block a user