diff --git a/README.md b/README.md index 122a79f..6ba3198 100644 --- a/README.md +++ b/README.md @@ -201,10 +201,15 @@ Depending on your HP model, SG3 might be configurable in "ECO mode", "Normal mod Note: Smart Grid needs to be switched ON in the heatpump configuration menu, otherwise SG1 and SG2 contacts are not evaluated. ## Step 5 (optional) - Pulse Meter feature -ESPaltherma can communicate how much energy the HP should consume via a pulse meter. For this, uncomment and confugre `PIN_PULSE`, `PULSES_PER_kWh` and `PULSE_DURATION_MS` in `src/setup.c`. Send energy amount in Watt to MQTT channel `espaltherma/pulse/set`. Current Watt setting is available in `espaltherma/pulse/state`. +ESPaltherma can communicate how much energy the HP should consume via a pulse meter. For this, uncomment and confugre `PIN_PULSE`, `PULSES_PER_kWh` and `PULSE_DURATION_MS` in `src/setup.h`. Send energy amount in Watt to MQTT channel `espaltherma/pulse/set`. Current Watt setting is available in `espaltherma/pulse/state`. *TODO more close description what it is to do* +Note the limits to reporded Watt. Both limits depend on +* `PULSES_PER_kWh` (default is 1000) +* `PULSE_DURATION_MS` (default is 75) +For these defaults, the minimum reported power is 60 and the maximum is 21 kWh. If you need to represent more power, try reducing `PULSE_DURATION_MS`. If this is not sufficient, adapt `PULSES_PER_kWh` but keep it in sync with the HP setting. + # Troubleshooting ## Specific issues with M5 diff --git a/include/mqtt.h b/include/mqtt.h index 1e29238..8fdc78b 100644 --- a/include/mqtt.h +++ b/include/mqtt.h @@ -258,18 +258,24 @@ void callbackPulse(byte *payload, unsigned int length) String ss((char*)payload); long target_watt = ss.toInt(); - // TODO check for maximum supported watt setting (smaller duration between pulse than pulse lenght) - // also converts from kWh to Wh - float WH_PER_PULSE = 1.0 / PULSES_PER_kWh * 1000; + float WH_PER_PULSE = (1.0 / PULSES_PER_kWh) * 1000; - ms_until_pulse = (3600.0 / target_watt * WH_PER_PULSE * 1000) - PULSE_DURATION_MS; + ms_until_pulse = ((3600.0 / target_watt) * WH_PER_PULSE * 1000) - PULSE_DURATION_MS; if ((ms_until_pulse + PULSE_DURATION_MS) > 60 * 1000) { // cap the maximum pulse length to 1 minute // a change of the pulse is only applied, after the current pulse is finished. Thus if the pulse rate is very low, // it will take a long time to adjust the rate ms_until_pulse = 60 * 1000; - Serial.printf("Capping pulse to %d Watt to ensure pulse rate is <= 60 sec\n", (int) WH_PER_PULSE * 60); + target_watt = (long) WH_PER_PULSE * 60; + Serial.printf("Capping pulse to %d Watt to ensure pulse rate is <= 60 sec\n", target_watt); + } + if (ms_until_pulse < 20) { + // ensure a 20 ms gap between two pulses + ms_until_pulse = 20; + long original_target = target_watt; + target_watt = (long) ((1000 * WH_PER_PULSE * 3600) / (ms_until_pulse + PULSE_DURATION_MS)); + Serial.printf("WARNING pulse frequency to high, capping at %d Watt! Target is %d Watt. Decrease PULSE_DURATION or PULSES_PER_kWh\n", target_watt, original_target); } if (timerPulseStart == NULL) { setupPulseTimer();