Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00

Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488)
This commit is contained in:
Theo Arends 2019-09-25 14:24:49 +02:00
parent 6ad2d3b86f
commit 5bd19d54db
5 changed files with 50 additions and 24 deletions

View File

@ -1,5 +1,6 @@
/*********************************************************************************************\ /*********************************************************************************************\
* 6.6.0.14 20190925 * 6.6.0.14 20190925
* Change command Tariffx to allow time entries like 23 (hours), 1320 (minutes) or 23:00. NOTE: As this is development branch previous tariffs are lost! (#6488)
* *
* 6.6.0.13 20190922 * 6.6.0.13 20190922
* Add command EnergyReset4 x,x to initialize total usage for two tarrifs * Add command EnergyReset4 x,x to initialize total usage for two tarrifs

View File

@ -373,8 +373,9 @@ struct SYSCFG {
TuyaFnidDpidMap tuya_fnid_map[MAX_TUYA_FUNCTIONS]; // E00 32 bytes TuyaFnidDpidMap tuya_fnid_map[MAX_TUYA_FUNCTIONS]; // E00 32 bytes
uint16_t ina226_r_shunt[4]; // E20 uint16_t ina226_r_shunt[4]; // E20
uint16_t ina226_i_fs[4]; // E28 uint16_t ina226_i_fs[4]; // E28
uint16_t tariff[4][2]; // E30
uint8_t free_e30[456]; // E30 uint8_t free_e40[440]; // E40
uint32_t cfg_timestamp; // FF8 uint32_t cfg_timestamp; // FF8
uint32_t cfg_crc32; // FFC uint32_t cfg_crc32; // FFC

View File

@ -252,7 +252,7 @@ enum SettingsParamIndex { P_HOLD_TIME, P_MAX_POWER_RETRY, P_ex_TUYA_DIMMER_ID, P
P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48 P_ex_ENERGY_TARIFF1, P_ex_ENERGY_TARIFF2, // SetOption47 .. SetOption48
P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 P_MAX_PARAM8 }; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49
enum SettingsRegister8 { R8_ENERGY_TARIFF1_ST, R8_ENERGY_TARIFF2_ST, R8_ENERGY_TARIFF1_DS, R8_ENERGY_TARIFF2_DS, enum SettingsRegister8 { R8_SPARE00, R8_SPARE01, R8_SPARE02, R8_SPARE03,
R8_SPARE04, R8_SPARE05, R8_SPARE06, R8_SPARE07, R8_SPARE04, R8_SPARE05, R8_SPARE06, R8_SPARE07,
R8_SPARE08, R8_SPARE09, R8_SPARE10, R8_SPARE11, R8_SPARE08, R8_SPARE09, R8_SPARE10, R8_SPARE11,
R8_SPARE12, R8_SPARE13, R8_SPARE14, R8_SPARE15, R8_SPARE12, R8_SPARE13, R8_SPARE14, R8_SPARE15,

View File

@ -120,10 +120,17 @@ String GetBuildDateAndTime(void)
return String(bdt); // 2017-03-07T11:08:02 return String(bdt); // 2017-03-07T11:08:02
} }
String GetMinuteTime(uint32_t minutes)
{
char tm[6];
snprintf_P(tm, sizeof(tm), PSTR("%02d:%02d"), minutes / 60, minutes % 60);
return String(tm); // 03:45
}
String GetTimeZone(void) String GetTimeZone(void)
{ {
char tz[7]; char tz[7];
snprintf_P(tz, sizeof(tz), PSTR("%+03d:%02d"), Rtc.time_timezone / 60, abs(Rtc.time_timezone % 60)); snprintf_P(tz, sizeof(tz), PSTR("%+03d:%02d"), Rtc.time_timezone / 60, abs(Rtc.time_timezone % 60));
return String(tz); // -03:45 return String(tz); // -03:45

View File

@ -129,18 +129,18 @@ Ticker ticker_energy;
bool EnergyTariff1Active() // Off-Peak hours bool EnergyTariff1Active() // Off-Peak hours
{ {
uint8_t tariff1 = Settings.register8[R8_ENERGY_TARIFF1_ST]; uint8_t dst = 0;
uint8_t tariff2 = Settings.register8[R8_ENERGY_TARIFF2_ST]; if (IsDst() && (Settings.tariff[0][1] != Settings.tariff[1][1])) {
if (IsDst() && (Settings.register8[R8_ENERGY_TARIFF1_DS] != Settings.register8[R8_ENERGY_TARIFF2_DS])) { dst = 1;
tariff1 = Settings.register8[R8_ENERGY_TARIFF1_DS];
tariff2 = Settings.register8[R8_ENERGY_TARIFF2_DS];
} }
if (tariff1 != tariff2) { if (Settings.tariff[0][dst] != Settings.tariff[1][dst]) {
return ((RtcTime.hour < tariff2) || // Tarrif1 = Off-Peak uint32_t minutes = MinutesPastMidnight();
(RtcTime.hour >= tariff1) || return ((minutes < Settings.tariff[1][dst]) || // Tarrif1 = Off-Peak
(minutes >= Settings.tariff[0][dst]) ||
(Settings.flag3.energy_weekend && ((RtcTime.day_of_week == 1) || (Settings.flag3.energy_weekend && ((RtcTime.day_of_week == 1) ||
(RtcTime.day_of_week == 7))) (RtcTime.day_of_week == 7)))
); );
} else { } else {
return false; return false;
} }
@ -583,30 +583,46 @@ void CmndEnergyReset(void)
void CmndTariff(void) void CmndTariff(void)
{ {
// Tariff1 22,23 - Tariff1 start hour for Standard Time and Daylight Savings Time // Tariff1 22:00,23:00 - Tariff1 start hour for Standard Time and Daylight Savings Time
// Tariff2 6,7 - Tariff2 start hour for Standard Time and Daylight Savings Time // Tariff2 6:00,7:00 - Tariff2 start hour for Standard Time and Daylight Savings Time
// Tariffx 1320, 1380 = minutes and also 22:00, 23:00
// Tariffx 22, 23 = hours and also 22:00, 23:00
// Tariff9 0/1 // Tariff9 0/1
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 2)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= 2)) {
char *p; uint32_t tariff = XdrvMailbox.index -1;
char *str = strtok_r(XdrvMailbox.data, ", ", &p);
uint32_t time_type = 0; uint32_t time_type = 0;
while ((str != nullptr) && (time_type <= 2)) { char *p;
uint8_t value = strtol(str, nullptr, 10); char *str = strtok_r(XdrvMailbox.data, ", ", &p); // 23:15, 22:30
if ((value >= 0) && (value < 24)) { while ((str != nullptr) && (time_type < 2)) {
Settings.register8[R8_ENERGY_TARIFF1_ST + (XdrvMailbox.index -1) + time_type] = value; char *q;
uint32_t value = strtol(str, &q, 10); // 23 or 22
Settings.tariff[tariff][time_type] = value;
if (value < 24) { // Below 24 is hours
Settings.tariff[tariff][time_type] *= 60; // Multiply hours by 60 minutes
char *minute = strtok_r(nullptr, ":", &q);
if (minute) {
value = strtol(minute, nullptr, 10); // 15 or 30
if (value > 59) {
value = 59;
}
Settings.tariff[tariff][time_type] += value;
}
}
if (Settings.tariff[tariff][time_type] > 1439) {
Settings.tariff[tariff][time_type] = 1439; // Max is 23:59
} }
str = strtok_r(nullptr, ", ", &p); str = strtok_r(nullptr, ", ", &p);
time_type += 2; time_type++;
} }
} }
else if (XdrvMailbox.index == 9) { else if (XdrvMailbox.index == 9) {
Settings.flag3.energy_weekend = XdrvMailbox.payload & 1; Settings.flag3.energy_weekend = XdrvMailbox.payload & 1;
} }
Response_P(PSTR("{\"%s\":{\"Off-Peak\":[%d,%d],\"Standard\":[%d,%d],\"Weekend\":\"%s\"}}"), Response_P(PSTR("{\"%s\":{\"Off-Peak\":{\"STD\":\"%s\",\"DST\":\"%s\"},\"Standard\":{\"STD\":\"%s\",\"DST\":\"%s\"},\"Weekend\":\"%s\"}}"),
XdrvMailbox.command, XdrvMailbox.command,
Settings.register8[R8_ENERGY_TARIFF1_ST], Settings.register8[R8_ENERGY_TARIFF1_DS], GetMinuteTime(Settings.tariff[0][0]).c_str(),GetMinuteTime(Settings.tariff[0][1]).c_str(),
Settings.register8[R8_ENERGY_TARIFF2_ST], Settings.register8[R8_ENERGY_TARIFF2_DS], GetMinuteTime(Settings.tariff[1][0]).c_str(),GetMinuteTime(Settings.tariff[1][1]).c_str(),
GetStateText(Settings.flag3.energy_weekend)); GetStateText(Settings.flag3.energy_weekend));
} }
@ -954,7 +970,8 @@ void EnergyShow(bool json)
char export_active_chr[3][FLOATSZ]; char export_active_chr[3][FLOATSZ];
dtostrfd(Energy.export_active, Settings.flag2.energy_resolution, export_active_chr[0]); dtostrfd(Energy.export_active, Settings.flag2.energy_resolution, export_active_chr[0]);
uint8_t energy_total_fields = 1; uint8_t energy_total_fields = 1;
if (Settings.register8[R8_ENERGY_TARIFF1_ST] != Settings.register8[R8_ENERGY_TARIFF2_ST]) {
if (Settings.tariff[0][0] != Settings.tariff[1][0]) {
dtostrfd((float)RtcSettings.energy_usage.usage1_kWhtotal / 100000, Settings.flag2.energy_resolution, energy_total_chr[1]); // Tariff1 dtostrfd((float)RtcSettings.energy_usage.usage1_kWhtotal / 100000, Settings.flag2.energy_resolution, energy_total_chr[1]); // Tariff1
dtostrfd((float)RtcSettings.energy_usage.usage2_kWhtotal / 100000, Settings.flag2.energy_resolution, energy_total_chr[2]); // Tariff2 dtostrfd((float)RtcSettings.energy_usage.usage2_kWhtotal / 100000, Settings.flag2.energy_resolution, energy_total_chr[2]); // Tariff2
dtostrfd((float)RtcSettings.energy_usage.return1_kWhtotal / 100000, Settings.flag2.energy_resolution, export_active_chr[1]); // Tariff1 dtostrfd((float)RtcSettings.energy_usage.return1_kWhtotal / 100000, Settings.flag2.energy_resolution, export_active_chr[1]); // Tariff1