powersync-energy-plugin-etm/extension/PLAN_EXTENSION.md

235 lines
8.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# Plan d'extension — Pompe à chaleur, ECS, Gestion d'énergie
## Vue d'ensemble
L'extension suit l'architecture existante du plugin :
```
energypluginnymea.cpp (init)
├── SmartChargingManager (existant — VE)
├── HeatPumpManager (NOUVEAU — PAC + ECS)
├── EnergyPriorityManager (NOUVEAU — allocation puissance)
└── NymeaEnergyJsonHandler (étendu — nouvelles méthodes RPC)
```
---
## Fichiers à créer / modifier
### Fichiers NOUVEAUX
| Fichier | Rôle |
|---|---|
| `energyplugin/heatpumpmanager.h/.cpp` | Wrapper PAC + ECS, detection via ThingManager |
| `energyplugin/energyprioritymanager.h/.cpp` | Allocation de puissance par priorité |
### Fichiers MODIFIÉS
| Fichier | Modification |
|---|---|
| `energyplugin/energypluginnymea.cpp` | `init()` instancie les 2 nouveaux managers |
| `energyplugin/nymeaenergyjsonhandler.h` | Ajout déclarations Q_INVOKABLE + signals |
| `energyplugin/nymeaenergyjsonhandler.cpp` | Enregistrement + implémentation RPC |
| `energyplugin/energyplugin.pri` | Ajout des nouveaux .h/.cpp aux HEADERS/SOURCES |
| Plugin d'intégration ETM (JSON) | Ajout ThingClasses heatPump + domesticHotWater |
---
## Étape 1 — Définir les ThingClasses dans le plugin d'intégration ETM
Le fichier `extension/heatpump_dhw_thingclasses.json` contient les définitions JSON
complètes à intégrer dans le fichier `.json` du plugin d'intégration ETM.
### UUIDs à retenir
| Thing | UUID ThingClass |
|---|---|
| Pompe à chaleur | `b5a8f3d2-4c1e-4a9f-8b2d-3e6c0f1d5a7b` |
| ECS (Eau Chaude Sanitaire) | `c7d2e4f1-5b3a-4c0d-9e6f-2a4b7c1d3e5f` |
### États PAC
| State | UUID | Type | Writable |
|---|---|---|---|
| connected | `c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f` | bool | non |
| power | `d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a` | bool | **oui** |
| mode | `e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b` | QString | **oui** |
| targetTemperature | `f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c` | double [1565°C] | **oui** |
| currentTemperature | `a7b8c9d0-e1f2-4a3b-4c5d-6e7f8a9b0c1d` | double | non |
| outdoorTemperature | `b8c9d0e1-f2a3-4b4c-5d6e-7f8a9b0c1d2e` | double | non |
| currentPower | `c9d0e1f2-a3b4-4c5d-6e7f-8a9b0c1d2e3f` | double (W) | non |
| cop | `d0e1f2a3-b4c5-4d6e-7f8a-9b0c1d2e3f4a` | double | non |
| defrostActive | `e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b` | bool | non |
| errorCode | `f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c` | uint | non |
### Actions PAC
| Action | UUID | Params |
|---|---|---|
| setMode | `a3b4c5d6-e7f8-4a9b-0c1d-2e3f4a5b6c7d` | mode: heating/cooling/auto/standby |
| setTargetTemperature | `c5d6e7f8-a9b0-4c1d-2e3f-4a5b6c7d8e9f` | targetTemperature: double |
### États ECS
| State | UUID | Type | Writable |
|---|---|---|---|
| connected | `c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f` | bool | non |
| power | `d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a` | bool | **oui** |
| targetTemperature | `e3f4a5b6-c7d8-4e9f-0a1b-2c3d4e5f6a7b` | double [4075°C] | **oui** |
| currentTemperature | `f4a5b6c7-d8e9-4f0a-1b2c-3d4e5f6a7b8c` | double | non |
| boostMode | `a5b6c7d8-e9f0-4a1b-2c3d-4e5f6a7b8c9d` | bool | **oui** |
| currentPower | `b6c7d8e9-f0a1-4b2c-3d4e-5f6a7b8c9d0e` | double (W) | non |
### Actions ECS
| Action | UUID | Params |
|---|---|---|
| triggerBoost | `d8e9f0a1-b2c3-4d4e-5f6a-7b8c9d0e1f2a` | duration: uint (15120 min) |
---
## Étape 2 — Intégrer HeatPumpManager dans le plugin energy
### Dans `energyplugin.pri` — ajouter :
```qmake
HEADERS += \
$$PWD/heatpumpmanager.h \
$$PWD/energyprioritymanager.h \
SOURCES += \
$$PWD/heatpumpmanager.cpp \
$$PWD/energyprioritymanager.cpp \
```
### Dans `energypluginnymea.cpp` — `init()` :
```cpp
// [AJOUT] Après la création de SmartChargingManager
HeatPumpManager *heatPumpManager = new HeatPumpManager(
energyManager(), thingManager(), this);
EnergyPriorityManager *priorityManager = new EnergyPriorityManager(
energyManager(), thingManager(), this);
// Passer les nouveaux managers au JSON handler (modifier sa signature)
jsonRpcServer()->registerExperienceHandler(
new NymeaEnergyJsonHandler(spotMarketManager, chargingManager,
heatPumpManager, priorityManager, this),
0, 9); // Version incrémentée à 9
```
---
## Étape 3 — Nouvelles méthodes API JSON-RPC
### Méthodes Pompe à chaleur
| Méthode | Description |
|---|---|
| `NymeaEnergy.GetHeatPumps` | Liste PAC + états |
| `NymeaEnergy.SetHeatPumpPower` | On/off |
| `NymeaEnergy.SetHeatPumpMode` | Mode heating/cooling/auto/standby |
| `NymeaEnergy.SetHeatPumpTargetTemperature` | Consigne température |
### Méthodes ECS
| Méthode | Description |
|---|---|
| `NymeaEnergy.GetDHWDevices` | Liste ECS + états |
| `NymeaEnergy.SetDHWPower` | On/off |
| `NymeaEnergy.SetDHWTargetTemperature` | Consigne température [4075°C] |
| `NymeaEnergy.TriggerDHWBoost` | Mode boost (15120 min) |
### Méthodes Gestion d'énergie
| Méthode | Description |
|---|---|
| `NymeaEnergy.GetManagedLoads` | Toutes les charges avec priorité + puissance |
| `NymeaEnergy.SetLoadPriority` | Modifier la priorité (0=Critical → 4=Optional) |
| `NymeaEnergy.SetAllocatedPower` | Forcer puissance allouée à une charge |
| `NymeaEnergy.GetTotalAvailablePower` | Puissance totale disponible |
| `NymeaEnergy.SetTotalAvailablePower` | Modifier la puissance totale disponible |
### Nouvelles notifications push
| Notification | Déclencheur |
|---|---|
| `NymeaEnergy.HeatPumpStateChanged` | Changement état PAC (température, mode…) |
| `NymeaEnergy.DHWStateChanged` | Changement état ECS |
| `NymeaEnergy.ManagedLoadChanged` | Changement priorité / puissance allouée |
| `NymeaEnergy.TotalAvailablePowerChanged` | Changement puissance totale disponible |
---
## Étape 4 — Logique EnergyPriorityManager
### Algorithme de rééquilibrage (rebalance())
```
1. Calculer la puissance disponible = totalAvailablePower - reservedForCritical
2. Trier les charges par priorité croissante (Critical d'abord)
3. Pour chaque charge (par priorité) :
a. Si puissance disponible ≥ requestedPower → allouer requestedPower, active=true
b. Sinon si puissance disponible > 0 → allouer le disponible, active=true (throttle)
c. Sinon → allouer 0W, active=false (couper)
d. Déduire de la puissance disponible
4. Émettre managedLoadChanged() pour chaque charge modifiée
5. Appliquer les actions sur les Things correspondants
```
### Priorités recommandées par type de charge
| Charge | Priorité recommandée |
|---|---|
| Chauffage PAC hiver | Critical (0) |
| ECS (sécurité légionellose) | Critical (0) |
| Chauffage PAC standard | High (1) |
| ECS normale | Normal (2) |
| Recharge VE mode Normal | Normal (2) |
| Recharge VE mode Eco | Low (3) |
| ECS boost | Low (3) |
| Recharge VE spot market | Optional (4) |
---
## Récapitulatif des UUIDs à générer
```
Plugin d'intégration ETM — nouvelles ThingClasses :
HEAT_PUMP_THING_CLASS_ID = b5a8f3d2-4c1e-4a9f-8b2d-3e6c0f1d5a7b
DHW_THING_CLASS_ID = c7d2e4f1-5b3a-4c0d-9e6f-2a4b7c1d3e5f
États PAC (StateTypes) :
HP_STATE_CONNECTED = c3d4e5f6-a7b8-4c9d-0e1f-2a3b4c5d6e7f
HP_STATE_POWER = d4e5f6a7-b8c9-4d0e-1f2a-3b4c5d6e7f8a
HP_STATE_MODE = e5f6a7b8-c9d0-4e1f-2a3b-4c5d6e7f8a9b
HP_STATE_TARGET_TEMP = f6a7b8c9-d0e1-4f2a-3b4c-5d6e7f8a9b0c
HP_STATE_CURRENT_TEMP = a7b8c9d0-e1f2-4a3b-4c5d-6e7f8a9b0c1d
HP_STATE_OUTDOOR_TEMP = b8c9d0e1-f2a3-4b4c-5d6e-7f8a9b0c1d2e
HP_STATE_CURRENT_POWER = c9d0e1f2-a3b4-4c5d-6e7f-8a9b0c1d2e3f
HP_STATE_COP = d0e1f2a3-b4c5-4d6e-7f8a-9b0c1d2e3f4a
HP_STATE_DEFROST_ACTIVE = e1f2a3b4-c5d6-4e7f-8a9b-0c1d2e3f4a5b
HP_STATE_ERROR_CODE = f2a3b4c5-d6e7-4f8a-9b0c-1d2e3f4a5b6c
Actions PAC (ActionTypes) :
HP_ACTION_SET_MODE = a3b4c5d6-e7f8-4a9b-0c1d-2e3f4a5b6c7d
HP_ACTION_PARAM_MODE = b4c5d6e7-f8a9-4b0c-1d2e-3f4a5b6c7d8e
HP_ACTION_SET_TARGET_TEMP = c5d6e7f8-a9b0-4c1d-2e3f-4a5b6c7d8e9f
HP_ACTION_PARAM_TARGET_TEMP = d6e7f8a9-b0c1-4d2e-3f4a-5b6c7d8e9f0a
États ECS (StateTypes) :
DHW_STATE_CONNECTED = c1d2e3f4-a5b6-4c7d-8e9f-0a1b2c3d4e5f
DHW_STATE_POWER = d2e3f4a5-b6c7-4d8e-9f0a-1b2c3d4e5f6a
DHW_STATE_TARGET_TEMP = e3f4a5b6-c7d8-4e9f-0a1b-2c3d4e5f6a7b
DHW_STATE_CURRENT_TEMP = f4a5b6c7-d8e9-4f0a-1b2c-3d4e5f6a7b8c
DHW_STATE_BOOST_MODE = a5b6c7d8-e9f0-4a1b-2c3d-4e5f6a7b8c9d
DHW_STATE_CURRENT_POWER = b6c7d8e9-f0a1-4b2c-3d4e-5f6a7b8c9d0e
Actions ECS (ActionTypes) :
DHW_ACTION_TRIGGER_BOOST = d8e9f0a1-b2c3-4d4e-5f6a-7b8c9d0e1f2a
DHW_ACTION_PARAM_DURATION = e9f0a1b2-c3d4-4e5f-6a7b-8c9d0e1f2a3b
```