Change Energy totals max supported value

- Change Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh
- Bump version to v12.3.1.3
This commit is contained in:
Theo Arends 2023-01-01 11:32:30 +01:00
parent ca82877362
commit c63919d783
5 changed files with 63 additions and 40 deletions

View File

@ -3,7 +3,19 @@ All notable changes to this project will be documented in this file.
## [Unreleased] - Development
## [12.3.1.2]
## [12.3.1.3]
### Added
### Breaking Changed
### Changed
- Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh
### Fixed
### Removed
## [12.3.1.2] 20221231
### Added
- Berry crypto add ``EC_P256`` and ``PBKDF2_HMAC_SHA256`` algorithms required by Matter protocol
- Berry crypto add ``random`` to generate series of random bytes
@ -13,8 +25,6 @@ All notable changes to this project will be documented in this file.
- Support for IPv6 only networks on Ethernet (not yet Wifi)
- Support for TM1650 display as used in some clocks by Stefan Oskamp (#17594)
### Breaking Changed
### Changed
- ESP32 Framework (Core) from v2.0.5.4 to v2.0.6 (IPv6 support)
- Tasmota OTA scripts now support both unzipped and gzipped file uploads (#17378)
@ -27,8 +37,6 @@ All notable changes to this project will be documented in this file.
- Modbus transmit enable GPIO enabled once during write buffer
- ESP8266 set GPIO's to input on power on fixing relay spikes (#17531)
### Removed
## [12.3.1.1] 20221221
### Added
- Support for IPv6 DNS records (AAAA) and IPv6 ``Ping`` for ESP32 and ESP8266 (#17417)

View File

@ -107,7 +107,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
[Complete list](BUILDS.md) of available feature and sensors.
## Changelog v12.3.1.2
## Changelog v12.3.1.3
### Added
- Support for up to 3 single phase modbus energy monitoring device using generic Energy Modbus driver- Support for RGB displays [#17414](https://github.com/arendst/Tasmota/issues/17414)
- Support for IPv6 DNS records (AAAA) and IPv6 ``Ping`` for ESP32 and ESP8266 [#17417](https://github.com/arendst/Tasmota/issues/17417)
@ -123,6 +123,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm
### Changed
- ESP32 Framework (Core) from v2.0.5.3 to v2.0.6 (IPv6 support)
- Energy totals max supported value from +/-21474.83647 to +/-2147483.647 kWh
- TuyaMcu rewrite by btsimonh [#17051](https://github.com/arendst/Tasmota/issues/17051)
- Tasmota OTA scripts now support both unzipped and gzipped file uploads [#17378](https://github.com/arendst/Tasmota/issues/17378)

View File

@ -20,6 +20,6 @@
#ifndef _TASMOTA_VERSION_H_
#define _TASMOTA_VERSION_H_
const uint32_t VERSION = 0x0C030102; // 12.3.1.2
const uint32_t VERSION = 0x0C030103; // 12.3.1.3
#endif // _TASMOTA_VERSION_H_

View File

@ -1614,6 +1614,20 @@ void SettingsDelta(void) {
if (Settings->version < 0x0C030102) { // 12.3.1.2
Settings->shutter_motorstop = 0;
}
if (Settings->version < 0x0C030103) { // 12.3.1.3
for (uint32_t i = 0; i < 3; i++) {
RtcSettings.energy_kWhtotal_ph[i] /= 100;
Settings->energy_kWhtotal_ph[i] /= 100;
RtcSettings.energy_kWhexport_ph[i] /= 100;
Settings->energy_kWhexport_ph[i] /= 100;
RtcSettings.energy_usage.usage1_kWhtotal /= 100;
RtcSettings.energy_usage.usage2_kWhtotal /= 100;
RtcSettings.energy_usage.return1_kWhtotal /= 100;
RtcSettings.energy_usage.return2_kWhtotal /= 100;
RtcSettings.energy_usage.last_return_kWhtotal /= 100;
RtcSettings.energy_usage.last_usage_kWhtotal /= 100;
}
}
Settings->version = VERSION;
SettingsSave(1);

View File

@ -252,15 +252,15 @@ void EnergyUpdateToday(void) {
Energy.kWhtoday_delta[i] -= (delta * 1000);
Energy.kWhtoday[i] += delta;
if (delta < 0) { // Export energy
RtcSettings.energy_kWhexport_ph[i] += (delta *-1);
RtcSettings.energy_kWhexport_ph[i] += ((delta / 100) *-1);
}
}
RtcSettings.energy_kWhtoday_ph[i] = Energy.kWhtoday_offset[i] + Energy.kWhtoday[i];
Energy.daily[i] = (float)(RtcSettings.energy_kWhtoday_ph[i]) / 100000;
Energy.total[i] = (float)(RtcSettings.energy_kWhtotal_ph[i] + RtcSettings.energy_kWhtoday_ph[i]) / 100000;
Energy.total[i] = ((float)(RtcSettings.energy_kWhtotal_ph[i]) / 1000) + ((float)(RtcSettings.energy_kWhtoday_ph[i]) / 100000);
if (Energy.local_energy_active_export) {
Energy.export_active[i] = (float)(RtcSettings.energy_kWhexport_ph[i]) / 100000;
Energy.export_active[i] = (float)(RtcSettings.energy_kWhexport_ph[i]) / 1000;
}
Energy.total_sum += Energy.total[i];
@ -276,13 +276,13 @@ void EnergyUpdateToday(void) {
if (RtcTime.valid){ // We calc the difference only if we have a valid RTC time.
uint32_t energy_diff = (uint32_t)(Energy.total_sum * 100000) - RtcSettings.energy_usage.last_usage_kWhtotal;
RtcSettings.energy_usage.last_usage_kWhtotal = (uint32_t)(Energy.total_sum * 100000);
uint32_t energy_diff = (uint32_t)(Energy.total_sum * 1000) - RtcSettings.energy_usage.last_usage_kWhtotal;
RtcSettings.energy_usage.last_usage_kWhtotal = (uint32_t)(Energy.total_sum * 1000);
uint32_t return_diff = 0;
if (!isnan(Energy.export_active[0])) {
// return_diff = (uint32_t)(Energy.export_active * 100000) - RtcSettings.energy_usage.last_return_kWhtotal;
// RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(Energy.export_active * 100000);
// return_diff = (uint32_t)(Energy.export_active * 1000) - RtcSettings.energy_usage.last_return_kWhtotal;
// RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(Energy.export_active * 1000);
float export_active = 0.0f;
for (uint32_t i = 0; i < Energy.phase_count; i++) {
@ -290,8 +290,8 @@ void EnergyUpdateToday(void) {
export_active += Energy.export_active[i];
}
}
return_diff = (uint32_t)(export_active * 100000) - RtcSettings.energy_usage.last_return_kWhtotal;
RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(export_active * 100000);
return_diff = (uint32_t)(export_active * 1000) - RtcSettings.energy_usage.last_return_kWhtotal;
RtcSettings.energy_usage.last_return_kWhtotal = (uint32_t)(export_active * 1000);
}
if (EnergyTariff1Active()) { // Tarrif1 = Off-Peak
@ -311,18 +311,18 @@ void EnergyUpdateTotal(void) {
AddLog(LOG_LEVEL_DEBUG_MORE, PSTR("NRG: EnergyTotal[%d] %4_f kWh"), i, &Energy.import_active[i]);
if (0 == Energy.start_energy[i] || (Energy.import_active[i] < Energy.start_energy[i])) {
Energy.start_energy[i] = Energy.import_active[i]; // Init after restart and handle roll-over if any
Energy.start_energy[i] = Energy.import_active[i]; // Init after restart and handle roll-over if any
}
else if (Energy.import_active[i] != Energy.start_energy[i]) {
Energy.kWhtoday[i] = (int32_t)((Energy.import_active[i] - Energy.start_energy[i]) * 100000);
}
if ((Energy.total[i] < (Energy.import_active[i] - 0.01f)) && // We subtract a little offset to avoid continuous updates
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
// The following calculation allows total usage (Energy.import_active[i]) up to +/-21474 kWh
RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy.import_active[i] * 100000) - Energy.kWhtoday_offset[i] - Energy.kWhtoday[i]);
Settings->flag3.hardware_energy_total) { // SetOption72 - Enable hardware energy total counter as reference (#6561)
// The following calculation allows total usage (Energy.import_active[i]) up to +/-2147483.647 kWh
RtcSettings.energy_kWhtotal_ph[i] = (int32_t)((Energy.import_active[i] * 1000) - ((Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100));
Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i];
Energy.total[i] = (float)(RtcSettings.energy_kWhtotal_ph[i] + Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100000;
Energy.total[i] = Energy.import_active[i];
Settings->energy_kWhtotal_time = (!Energy.kWhtoday_offset[i]) ? LocalTime() : Midnight();
// AddLog(LOG_LEVEL_DEBUG, PSTR("NRG: Energy Total updated with hardware value"));
}
@ -357,7 +357,7 @@ void Energy200ms(void)
for (uint32_t i = 0; i < 3; i++) {
Settings->energy_kWhyesterday_ph[i] = RtcSettings.energy_kWhtoday_ph[i];
RtcSettings.energy_kWhtotal_ph[i] += RtcSettings.energy_kWhtoday_ph[i];
RtcSettings.energy_kWhtotal_ph[i] += (RtcSettings.energy_kWhtoday_ph[i] / 100);
Settings->energy_kWhtotal_ph[i] = RtcSettings.energy_kWhtotal_ph[i];
Settings->energy_kWhexport_ph[i] = RtcSettings.energy_kWhexport_ph[i];
@ -652,9 +652,9 @@ void ResponseCmndEnergyTotalYesterdayToday(void) {
float energy_yesterday_ph[3];
for (uint32_t i = 0; i < Energy.phase_count; i++) {
energy_yesterday_ph[i] = (float)Settings->energy_kWhyesterday_ph[i] / 100000;
Energy.total[i] = (float)(RtcSettings.energy_kWhtotal_ph[i] + Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100000;
Energy.total[i] = ((float)(RtcSettings.energy_kWhtotal_ph[i]) / 1000) + ((float)(Energy.kWhtoday_offset[i] + Energy.kWhtoday[i]) / 100000);
if (Energy.local_energy_active_export) {
Energy.export_active[i] = (float)(RtcSettings.energy_kWhexport_ph[i]) / 100000;
Energy.export_active[i] = (float)(RtcSettings.energy_kWhexport_ph[i]) / 1000;
}
}
@ -677,7 +677,7 @@ void CmndEnergyTotal(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy.phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Total
RtcSettings.energy_kWhtotal_ph[phase] = values[0] * 100;
RtcSettings.energy_kWhtotal_ph[phase] = values[0];
Settings->energy_kWhtotal_ph[phase] = RtcSettings.energy_kWhtotal_ph[phase];
if (params > 1) {
Settings->energy_kWhtotal_time = values[1];
@ -739,7 +739,7 @@ void CmndEnergyExportActive(void) {
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= Energy.phase_count) && (params > 0)) {
uint32_t phase = XdrvMailbox.index -1;
// Reset Energy Export Active
RtcSettings.energy_kWhexport_ph[phase] = values[0] * 100;
RtcSettings.energy_kWhexport_ph[phase] = values[0];
Settings->energy_kWhexport_ph[phase] = RtcSettings.energy_kWhexport_ph[phase];
if (params > 1) {
Settings->energy_kWhtotal_time = values[1];
@ -750,10 +750,10 @@ void CmndEnergyExportActive(void) {
}
void ResponseCmndEnergyUsageExport(void) {
float usage1_kWhtotal = (float)Settings->energy_usage.usage1_kWhtotal / 100000;
float usage2_kWhtotal = (float)Settings->energy_usage.usage2_kWhtotal / 100000;
float return1_kWhtotal = (float)Settings->energy_usage.return1_kWhtotal / 100000;
float return2_kWhtotal = (float)Settings->energy_usage.return2_kWhtotal / 100000;
float usage1_kWhtotal = (float)Settings->energy_usage.usage1_kWhtotal / 1000;
float usage2_kWhtotal = (float)Settings->energy_usage.usage2_kWhtotal / 1000;
float return1_kWhtotal = (float)Settings->energy_usage.return1_kWhtotal / 1000;
float return2_kWhtotal = (float)Settings->energy_usage.return2_kWhtotal / 1000;
Response_P(PSTR("{\"%s\":{\"" D_JSON_USAGE "\":[%*_f,%*_f],\"" D_JSON_EXPORT "\":[%*_f,%*_f]}}"),
XdrvMailbox.command,
@ -768,9 +768,9 @@ void CmndEnergyUsage(void) {
uint32_t params = ParseParameters(2, values);
if (params > 0) {
// Reset energy_usage.usage totals
RtcSettings.energy_usage.usage1_kWhtotal = values[0] * 100;
RtcSettings.energy_usage.usage1_kWhtotal = values[0];
if (params > 1) {
RtcSettings.energy_usage.usage2_kWhtotal = values[1] * 100;
RtcSettings.energy_usage.usage2_kWhtotal = values[1];
}
Settings->energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal;
Settings->energy_usage.usage2_kWhtotal = RtcSettings.energy_usage.usage2_kWhtotal;
@ -1214,10 +1214,10 @@ void EnergyShow(bool json) {
float energy_usage[2];
float energy_return[2];
if (Settings->tariff[0][0] != Settings->tariff[1][0]) {
energy_usage[0] = (float)RtcSettings.energy_usage.usage1_kWhtotal / 100000; // Tariff1
energy_usage[1] = (float)RtcSettings.energy_usage.usage2_kWhtotal / 100000; // Tariff2
energy_return[0] = (float)RtcSettings.energy_usage.return1_kWhtotal / 100000; // Tariff1
energy_return[1] = (float)RtcSettings.energy_usage.return2_kWhtotal / 100000; // Tariff2
energy_usage[0] = (float)RtcSettings.energy_usage.usage1_kWhtotal / 1000; // Tariff1
energy_usage[1] = (float)RtcSettings.energy_usage.usage2_kWhtotal / 1000; // Tariff2
energy_return[0] = (float)RtcSettings.energy_usage.return1_kWhtotal / 1000; // Tariff1
energy_return[1] = (float)RtcSettings.energy_usage.return2_kWhtotal / 1000; // Tariff2
energy_tariff = true;
}
@ -1316,10 +1316,10 @@ void EnergyShow(bool json) {
char energy_usage_chr[2][FLOATSZ];
char energy_return_chr[2][FLOATSZ];
dtostrfd((float)RtcSettings.energy_usage.usage1_kWhtotal / 100, 1, energy_usage_chr[0]); // Tariff1
dtostrfd((float)RtcSettings.energy_usage.usage2_kWhtotal / 100, 1, energy_usage_chr[1]); // Tariff2
dtostrfd((float)RtcSettings.energy_usage.return1_kWhtotal / 100, 1, energy_return_chr[0]);
dtostrfd((float)RtcSettings.energy_usage.return2_kWhtotal / 100, 1, energy_return_chr[1]);
dtostrfd((float)RtcSettings.energy_usage.usage1_kWhtotal, 1, energy_usage_chr[0]); // Tariff1
dtostrfd((float)RtcSettings.energy_usage.usage2_kWhtotal, 1, energy_usage_chr[1]); // Tariff2
dtostrfd((float)RtcSettings.energy_usage.return1_kWhtotal, 1, energy_return_chr[0]);
dtostrfd((float)RtcSettings.energy_usage.return2_kWhtotal, 1, energy_return_chr[1]);
DomoticzSensorP1SmartMeter(energy_usage_chr[0], energy_usage_chr[1], energy_return_chr[0], energy_return_chr[1], (int)active_power_sum);
}