mirror of https://github.com/arendst/Tasmota.git
Init Energy Total on energy monitoring devices with Energy Total Register
Init Energy Total on energy monitoring devices with Energy Total Register (#6282)
This commit is contained in:
parent
3ee83ae147
commit
b3562e030e
|
@ -146,6 +146,22 @@ void EnergyUpdateToday(void)
|
|||
}
|
||||
}
|
||||
|
||||
void EnergyUpdateTotal(float value, bool kwh)
|
||||
{
|
||||
uint32_t multiplier = (kwh) ? 100000 : 100; // kWh or Wh to deca milli Wh
|
||||
|
||||
if (0 == Energy.start_energy || (value < Energy.start_energy)) {
|
||||
Energy.start_energy = value; // Init after restart and handle roll-over if any
|
||||
RtcSettings.energy_kWhtotal = (unsigned long)(value * multiplier);
|
||||
Energy.kWhtoday = 0;
|
||||
}
|
||||
else if (value != Energy.start_energy) {
|
||||
Energy.kWhtoday += (unsigned long)((value - Energy.start_energy) * multiplier);
|
||||
Energy.start_energy = value;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
}
|
||||
|
||||
/*********************************************************************************************/
|
||||
|
||||
void Energy200ms(void)
|
||||
|
|
|
@ -181,12 +181,7 @@ void PzemEvery200ms(void)
|
|||
Energy.active_power = value;
|
||||
break;
|
||||
case 4: // Total energy as 99999Wh
|
||||
if (!Energy.start_energy || (value < Energy.start_energy)) Energy.start_energy = value; // Init after restart and hanlde roll-over if any
|
||||
if (value != Energy.start_energy) {
|
||||
Energy.kWhtoday += (unsigned long)((value - Energy.start_energy) * 100);
|
||||
Energy.start_energy = value;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
EnergyUpdateTotal(value, false);
|
||||
break;
|
||||
}
|
||||
pzem_read_state++;
|
||||
|
|
|
@ -82,12 +82,7 @@ void PzemAcEverySecond(void)
|
|||
Energy.power_factor = (float)((buffer[19] << 8) + buffer[20]) / 100.0; // 1.00
|
||||
float energy = (float)((buffer[15] << 24) + (buffer[16] << 16) + (buffer[13] << 8) + buffer[14]); // 4294967295 Wh
|
||||
|
||||
if (!Energy.start_energy || (energy < Energy.start_energy)) { Energy.start_energy = energy; } // Init after restart and handle roll-over if any
|
||||
if (energy != Energy.start_energy) {
|
||||
Energy.kWhtoday += (unsigned long)((energy - Energy.start_energy) * 100);
|
||||
Energy.start_energy = energy;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
EnergyUpdateTotal(energy, false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,12 +61,7 @@ void PzemDcEverySecond(void)
|
|||
Energy.active_power = (float)((buffer[9] << 24) + (buffer[10] << 16) + (buffer[7] << 8) + buffer[8]) / 10.0; // 429496729.0 W
|
||||
float energy = (float)((buffer[13] << 24) + (buffer[14] << 16) + (buffer[11] << 8) + buffer[12]); // 4294967295 Wh
|
||||
|
||||
if (!Energy.start_energy || (energy < Energy.start_energy)) { Energy.start_energy = energy; } // Init after restart and handle roll-over if any
|
||||
if (energy != Energy.start_energy) {
|
||||
Energy.kWhtoday += (unsigned long)((energy - Energy.start_energy) * 100);
|
||||
Energy.start_energy = energy;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
EnergyUpdateTotal(energy, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ void SDM120Every200ms(void)
|
|||
Energy.data_valid = 0;
|
||||
|
||||
float value;
|
||||
((uint8_t*)&value)[3] = buffer[3]; // Get float values
|
||||
((uint8_t*)&value)[3] = buffer[3]; // Get float values
|
||||
((uint8_t*)&value)[2] = buffer[4];
|
||||
((uint8_t*)&value)[1] = buffer[5];
|
||||
((uint8_t*)&value)[0] = buffer[6];
|
||||
|
@ -129,14 +129,7 @@ void SDM120Every200ms(void)
|
|||
break;
|
||||
|
||||
case 7:
|
||||
if (!Energy.start_energy || (value < Energy.start_energy)) { // 484.708 kWh
|
||||
Energy.start_energy = value; // Init after restart and hanlde roll-over if any
|
||||
}
|
||||
if (value != Energy.start_energy) {
|
||||
Energy.kWhtoday += (unsigned long)((value - Energy.start_energy) * 100000); // kWh to deca milli Wh
|
||||
Energy.start_energy = value;
|
||||
}
|
||||
EnergyUpdateToday();
|
||||
EnergyUpdateTotal(value, true); // 484.708 kWh
|
||||
break;
|
||||
|
||||
#ifdef USE_SDM220
|
||||
|
|
Loading…
Reference in New Issue