Skip to content

Commit

Permalink
thermostat clock and other from emsesp#450
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDvP committed Apr 6, 2022
1 parent 4279962 commit 5bf4858
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 36 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG_LATEST.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@
- removed system/pin command, new commands in analogsensors
- system/info device-info split to name/version/brand
- exclude list uses short-names, possible flags for web/api/mqtt excludes, readonly and favorite (selection not yet implemented)
- thermostat clock formate date-time: dd.mm.yyyy hh:mm:ss
- RC300 summermode as other thermostats `winter/summer` instead of `off/on`

## **BREAKING CHANGES:**

Expand Down
35 changes: 15 additions & 20 deletions src/devices/thermostat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,14 +1221,14 @@ void Thermostat::process_RCTime(std::shared_ptr<const Telegram> telegram) {
char buf6[6];
snprintf(date,
sizeof(date),
"%s:%s:%s %s.%s.%s",
Helpers::smallitoa(buf1, telegram->message_data[2]), // hour
Helpers::smallitoa(buf2, telegram->message_data[4]), // minute
Helpers::smallitoa(buf3, telegram->message_data[5]), // second
"%s.%s.%s %s:%s:%s",
Helpers::smallitoa(buf4, telegram->message_data[3]), // day
Helpers::smallitoa(buf5, telegram->message_data[1]), // month
// IVT reports Year with high bit set.?
Helpers::itoa((telegram->message_data[0] & 0x7F) + 2000, buf6) // year
Helpers::itoa((telegram->message_data[0] & 0x7F) + 2000, buf6), // year
Helpers::smallitoa(buf1, telegram->message_data[2]), // hour
Helpers::smallitoa(buf2, telegram->message_data[4]), // minute
Helpers::smallitoa(buf3, telegram->message_data[5]) // second
);
has_update(dateTime_, date, sizeof(dateTime_));

Expand Down Expand Up @@ -1790,7 +1790,7 @@ bool Thermostat::set_party(const char * value, const int8_t id) {
return true;
}

// set date&time as string hh:mm:ss-dd.mm.yyyy-dw-dst or "NTP" for setting to internet-time
// set date&time as string dd.mm.yyyy-hh:mm:ss-dw-dst or "NTP" for setting to internet-time
// dw - day of week (0..6), dst- summertime (0/1)
// id is ignored
bool Thermostat::set_datetime(const char * value, const int8_t id) {
Expand Down Expand Up @@ -1818,25 +1818,20 @@ bool Thermostat::set_datetime(const char * value, const int8_t id) {
data[5] = tm_->tm_sec;
data[6] = (tm_->tm_wday + 6) % 7; // Bosch counts from Mo, time from Su
data[7] = tm_->tm_isdst + 2; // set DST and flag for ext. clock
// char time_string[25];
// strftime(time_string, 25, "%FT%T%z", tm_);
// LOG_INFO(F("Date and time: %s"), time_string);
} else if (dt.length() == 23) {
data[0] = (dt[16] - '0') * 100 + (dt[17] - '0') * 10 + (dt[18] - '0'); // year
data[1] = (dt[12] - '0') * 10 + (dt[13] - '0'); // month
data[2] = (dt[0] - '0') * 10 + (dt[1] - '0'); // hour
data[3] = (dt[9] - '0') * 10 + (dt[10] - '0'); // day
data[4] = (dt[3] - '0') * 10 + (dt[4] - '0'); // min
data[5] = (dt[6] - '0') * 10 + (dt[7] - '0'); // sec
data[6] = (dt[20] - '0'); // day of week, Mo:0
data[7] = (dt[22] - '0') + 2; // DST and flag
// LOG_INFO(F("Date and time: %02d.%02d.2%03d-%02d:%02d:%02d"), data[3], data[1], data[0], data[2], data[4], data[5]);
data[0] = (dt[7] - '0') * 100 + (dt[8] - '0') * 10 + (dt[9] - '0'); // year
data[1] = (dt[3] - '0') * 10 + (dt[4] - '0'); // month
data[2] = (dt[11] - '0') * 10 + (dt[12] - '0'); // hour
data[3] = (dt[0] - '0') * 10 + (dt[1] - '0'); // day
data[4] = (dt[14] - '0') * 10 + (dt[15] - '0'); // min
data[5] = (dt[17] - '0') * 10 + (dt[18] - '0'); // sec
data[6] = (dt[20] - '0'); // day of week, Mo:0
data[7] = (dt[22] - '0') + 2; // DST and flag
} else {
LOG_WARNING(F("Set date: invalid data, wrong length"));
return false;
}
if (data[1] == 0 || data[1] > 12 || data[2] > 23 || data[3] == 0 || data[3] > 31 || data[4] > 59 || data[5] > 59 || data[6] > 6 || data[7] > 3) {
// LOG_WARNING(F("Set date: invalid data"));
LOG_WARNING(F("Invalid date/time: %02d.%02d.2%03d-%02d:%02d:%02d-%d-%d"), data[3], data[1], data[0], data[2], data[4], data[5], data[6], data[7]);
return false;
}
Expand Down Expand Up @@ -3357,7 +3352,7 @@ void Thermostat::register_device_values_hc(std::shared_ptr<Thermostat::HeatingCi
tag, &hc->heatingtype, DeviceValueType::ENUM, FL_(enum_heatingtype), FL_(heatingtype), DeviceValueUOM::NONE, MAKE_CF_CB(set_heatingtype));
register_device_value(
tag, &hc->summer_setmode, DeviceValueType::ENUM, FL_(enum_summermode), FL_(summersetmode), DeviceValueUOM::NONE, MAKE_CF_CB(set_summermode));
register_device_value(tag, &hc->summermode, DeviceValueType::BOOL, nullptr, FL_(summermode), DeviceValueUOM::NONE);
register_device_value(tag, &hc->summermode, DeviceValueType::ENUM, FL_(enum_summer), FL_(summermode), DeviceValueUOM::NONE);
register_device_value(
tag, &hc->controlmode, DeviceValueType::ENUM, FL_(enum_controlmode), FL_(controlmode), DeviceValueUOM::NONE, MAKE_CF_CB(set_controlmode));
register_device_value(tag, &hc->program, DeviceValueType::ENUM, FL_(enum_progMode), FL_(program), DeviceValueUOM::NONE, MAKE_CF_CB(set_program));
Expand Down
22 changes: 9 additions & 13 deletions src/emsdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ void EMSdevice::publish_value(void * value_p) const {
Helpers::render_value(payload, *(uint32_t *)(value_p), divider, fahrenheit);
break;
case DeviceValueType::BOOL: {
Helpers::render_boolean(payload, (bool)(*(uint8_t *)(value_p)));
Helpers::render_boolean(payload, (bool)*(uint8_t *)(value_p));
break;
}
case DeviceValueType::TIME:
Expand Down Expand Up @@ -646,12 +646,10 @@ void EMSdevice::generate_values_web(JsonObject & output) {
JsonObject obj = data.createNestedObject(); // create the object, we know there is a value
uint8_t fahrenheit = 0;

// handle Booleans (true, false)
// handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) {
bool value_b = *(bool *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
obj["v"] = value_b ? "true" : "false";
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
bool value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7];
Expand Down Expand Up @@ -765,12 +763,10 @@ void EMSdevice::generate_values_web_all(JsonArray & output) {

// create the value
if (dv.hasValue()) {
// handle Booleans (true, false)
// handle Booleans (true, false), use strings, no native true/false)
if (dv.type == DeviceValueType::BOOL) {
bool value_b = *(bool *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
obj["v"] = value_b;
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
bool value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
obj["v"] = value_b ? 1 : 0;
} else {
char s[7];
Expand Down Expand Up @@ -975,7 +971,7 @@ bool EMSdevice::get_value_info(JsonObject & output, const char * cmd, const int8

case DeviceValueType::BOOL:
if (Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) {
auto value_b = (bool)(*(uint8_t *)(dv.value_p));
bool value_b = (bool)*(uint8_t *)(dv.value_p);
if (EMSESP::system_.bool_format() == BOOL_FORMAT_TRUEFALSE) {
json[value] = value_b;
} else if (EMSESP::system_.bool_format() == BOOL_FORMAT_10) {
Expand Down Expand Up @@ -1108,7 +1104,7 @@ bool EMSdevice::generate_values(JsonObject & output, const uint8_t tag_filter, c
// handle Booleans
if (dv.type == DeviceValueType::BOOL && Helpers::hasValue(*(uint8_t *)(dv.value_p), EMS_VALUE_BOOL)) {
// see how to render the value depending on the setting
auto value_b = (bool)*(uint8_t *)(dv.value_p);
bool value_b = (bool)*(uint8_t *)(dv.value_p);
if (Mqtt::ha_enabled() && (output_target == OUTPUT_TARGET::MQTT)) {
char s[7];
json[name] = Helpers::render_boolean(s, value_b); // for HA always render as string
Expand Down
2 changes: 1 addition & 1 deletion src/locale_DE.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ MAKE_PSTR(functioning_mode, "functioning mode")
MAKE_PSTR(smoke_temperature, "Abgastemperatur")

// thermostat lists
MAKE_PSTR_LIST(tpl_datetime, F("Format: < hh:mm:ss dd/mm/yyyy-dw-dst | NTP >"))
MAKE_PSTR_LIST(tpl_datetime, F("Format: < NTP | dd.mm.yyyy-hh:mm:ss-dw-dst >"))
MAKE_PSTR_LIST(tpl_switchtime, F("Format: < nn.d.o.hh:mm >"))
MAKE_PSTR_LIST(tpl_holidays, F("Format: < dd.mm.yyyy-dd.mm.yyyy >"))
MAKE_PSTR_LIST(enum_ibaMainDisplay,
Expand Down
4 changes: 2 additions & 2 deletions src/locale_EN.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ MAKE_PSTR(functioning_mode, "functioning mode")
MAKE_PSTR(smoke_temperature, "smoke temperature")

// thermostat lists
MAKE_PSTR_LIST(tpl_datetime, F("Format: < NTP | hh:mm:ss dd.mm.yyyy-dw-dst >"))
MAKE_PSTR_LIST(tpl_datetime, F("Format: < NTP | dd.mm.yyyy-hh:mm:ss-dw-dst >"))
MAKE_PSTR_LIST(tpl_switchtime, F("Format: <nn> [ not_set | day hh:mm on|off ]"))
MAKE_PSTR_LIST(tpl_holidays, F("format: < dd.mm.yyyy-dd.mm.yyyy >"))
MAKE_PSTR_LIST(enum_ibaMainDisplay,
Expand Down Expand Up @@ -540,7 +540,7 @@ MAKE_PSTR_LIST(wwSetPumpPower, F("wwsetpumppower"), F("set pump power"))
MAKE_PSTR_LIST(wwMixerTemp, F("wwmixertemp"), F("mixer temperature"))
MAKE_PSTR_LIST(wwCylMiddleTemp, F("wwcylmiddletemp"), F("cylinder middle temperature (TS3)"))
MAKE_PSTR_LIST(wwStarts, F("wwstarts"), F("starts"))
MAKE_PSTR_LIST(wwStarts2, F("wwstarts2"), F("control starts"))
MAKE_PSTR_LIST(wwStarts2, F("wwstarts2"), F("control starts2"))
MAKE_PSTR_LIST(wwWorkM, F("wwworkm"), F("active time"))
MAKE_PSTR_LIST(wwHystOn, F("wwhyston"), F("hysteresis on temperature"))
MAKE_PSTR_LIST(wwHystOff, F("wwhystoff"), F("hysteresis off temperature"))
Expand Down

0 comments on commit 5bf4858

Please sign in to comment.