mirror of https://github.com/arendst/Tasmota.git
Merge pull request #10423 from curzon01/development
Add EnergyReset optional time param
This commit is contained in:
commit
fb2ff5b869
|
@ -558,14 +558,16 @@ void EnergyCommandCalResponse(uint32_t nvalue)
|
||||||
|
|
||||||
void CmndEnergyReset(void)
|
void CmndEnergyReset(void)
|
||||||
{
|
{
|
||||||
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 3)) {
|
uint32_t values[2] = { 0 };
|
||||||
char *p;
|
uint32_t params = ParseParameters(2, values);
|
||||||
unsigned long lnum = strtoul(XdrvMailbox.data, &p, 10);
|
values[0] *= 100;
|
||||||
if (p != XdrvMailbox.data) {
|
|
||||||
|
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 5)) {
|
||||||
|
if (params > 0) {
|
||||||
switch (XdrvMailbox.index) {
|
switch (XdrvMailbox.index) {
|
||||||
case 1:
|
case 1:
|
||||||
// Reset Energy Today
|
// Reset Energy Today
|
||||||
Energy.kWhtoday_offset = lnum *100;
|
Energy.kWhtoday_offset = values[0];
|
||||||
Energy.kWhtoday = 0;
|
Energy.kWhtoday = 0;
|
||||||
Energy.kWhtoday_delta = 0;
|
Energy.kWhtoday_delta = 0;
|
||||||
Energy.start_energy = 0;
|
Energy.start_energy = 0;
|
||||||
|
@ -573,56 +575,55 @@ void CmndEnergyReset(void)
|
||||||
Settings.energy_kWhtoday = Energy.kWhtoday_offset;
|
Settings.energy_kWhtoday = Energy.kWhtoday_offset;
|
||||||
RtcSettings.energy_kWhtoday = Energy.kWhtoday_offset;
|
RtcSettings.energy_kWhtoday = Energy.kWhtoday_offset;
|
||||||
Energy.daily = (float)Energy.kWhtoday_offset / 100000;
|
Energy.daily = (float)Energy.kWhtoday_offset / 100000;
|
||||||
if (!RtcSettings.energy_kWhtotal && !Energy.kWhtoday_offset) {
|
if( params > 1) {
|
||||||
Settings.energy_kWhtotal_time = LocalTime();
|
Settings.energy_kWhtotal_time = values[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (!RtcSettings.energy_kWhtotal && !Energy.kWhtoday_offset) {
|
||||||
|
Settings.energy_kWhtotal_time = LocalTime();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
// Reset Energy Yesterday
|
// Reset Energy Yesterday
|
||||||
Settings.energy_kWhyesterday = lnum *100;
|
Settings.energy_kWhyesterday = values[0];
|
||||||
|
if( params > 1) {
|
||||||
|
Settings.energy_kWhtotal_time = values[1];
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
// Reset Energy Total
|
// Reset Energy Total
|
||||||
RtcSettings.energy_kWhtotal = lnum *100;
|
RtcSettings.energy_kWhtotal = values[0];
|
||||||
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
|
Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal;
|
||||||
// Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
// Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||||
Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight();
|
if( params > 1) {
|
||||||
|
Settings.energy_kWhtotal_time = values[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
Settings.energy_kWhtotal_time = (!Energy.kWhtoday_offset) ? LocalTime() : Midnight();
|
||||||
|
}
|
||||||
RtcSettings.energy_usage.last_usage_kWhtotal = (uint32_t)(Energy.total * 1000);
|
RtcSettings.energy_usage.last_usage_kWhtotal = (uint32_t)(Energy.total * 1000);
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if ((XdrvMailbox.index > 3) && (XdrvMailbox.index <= 5)) {
|
|
||||||
uint32_t values[2] = { 0 };
|
|
||||||
uint32_t position = ParseParameters(2, values);
|
|
||||||
values[0] *= 100;
|
|
||||||
values[1] *= 100;
|
|
||||||
|
|
||||||
switch (XdrvMailbox.index)
|
|
||||||
{
|
|
||||||
case 4:
|
case 4:
|
||||||
// Reset energy_usage.usage totals
|
// Reset energy_usage.usage totals
|
||||||
if (position > 0) {
|
RtcSettings.energy_usage.usage1_kWhtotal = values[0];
|
||||||
RtcSettings.energy_usage.usage1_kWhtotal = values[0];
|
if (params > 1) {
|
||||||
}
|
RtcSettings.energy_usage.usage2_kWhtotal = values[1] * 100;
|
||||||
if (position > 1) {
|
|
||||||
RtcSettings.energy_usage.usage2_kWhtotal = values[1];
|
|
||||||
}
|
}
|
||||||
Settings.energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal;
|
Settings.energy_usage.usage1_kWhtotal = RtcSettings.energy_usage.usage1_kWhtotal;
|
||||||
Settings.energy_usage.usage2_kWhtotal = RtcSettings.energy_usage.usage2_kWhtotal;
|
Settings.energy_usage.usage2_kWhtotal = RtcSettings.energy_usage.usage2_kWhtotal;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
// Reset energy_usage.return totals
|
// Reset energy_usage.return totals
|
||||||
if (position > 0) {
|
RtcSettings.energy_usage.return1_kWhtotal = values[0];
|
||||||
RtcSettings.energy_usage.return1_kWhtotal = values[0];
|
if (params > 1) {
|
||||||
}
|
RtcSettings.energy_usage.return2_kWhtotal = values[1] * 100;
|
||||||
if (position > 1) {
|
|
||||||
RtcSettings.energy_usage.return2_kWhtotal = values[1];
|
|
||||||
}
|
}
|
||||||
Settings.energy_usage.return1_kWhtotal = RtcSettings.energy_usage.return1_kWhtotal;
|
Settings.energy_usage.return1_kWhtotal = RtcSettings.energy_usage.return1_kWhtotal;
|
||||||
Settings.energy_usage.return2_kWhtotal = RtcSettings.energy_usage.return2_kWhtotal;
|
Settings.energy_usage.return2_kWhtotal = RtcSettings.energy_usage.return2_kWhtotal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
Energy.total = (float)(RtcSettings.energy_kWhtotal + Energy.kWhtoday_offset + Energy.kWhtoday) / 100000;
|
||||||
|
|
Loading…
Reference in New Issue