From f0a7a1f2a1538e8a5bddd29d47e96aeea812c63e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 1 Mar 2019 12:08:41 +0100 Subject: [PATCH 1/3] Fix Energy TotalStartTime Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373) --- sonoff/_changelog.ino | 1 + sonoff/support_rtc.ino | 15 +++++++++++---- sonoff/xdrv_01_webserver.ino | 5 ++--- sonoff/xdrv_03_energy.ino | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index d3b6fa238..0214da3cd 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -1,6 +1,7 @@ /* 6.4.1.19 20190222 * Add command SetOption37 for RGBCW color mapping (#5326) * Add Korean language translations (#5344) + * Fix Energy TotalStartTime when commands EnergyReset0 and/or EnergyReset3 used (#5373) * * 6.4.1.18 20190221 * Fix some exceptions and watchdogs due to lack of stack space - part 1 (#5215) diff --git a/sonoff/support_rtc.ino b/sonoff/support_rtc.ino index 35f9b61e9..e66eda691 100644 --- a/sonoff/support_rtc.ino +++ b/sonoff/support_rtc.ino @@ -43,7 +43,7 @@ uint32_t local_time = 0; uint32_t daylight_saving_time = 0; uint32_t standard_time = 0; uint32_t ntp_time = 0; -uint32_t midnight = 1451602800; +uint32_t midnight = 0; uint32_t restart_time = 0; int32_t time_timezone = 0; uint8_t midnight_now = 0; @@ -406,10 +406,17 @@ void RtcSecond(void) if (!Settings.energy_kWhtotal_time) { Settings.energy_kWhtotal_time = local_time; } } BreakTime(local_time, RtcTime); - if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second && RtcTime.valid) { - midnight = local_time; - midnight_now = 1; + + if (RtcTime.valid) { + if (!midnight) { + midnight = local_time - (RtcTime.hour * 3600) - (RtcTime.minute * 60) - RtcTime.second; + } + if (!RtcTime.hour && !RtcTime.minute && !RtcTime.second) { + midnight = local_time; + midnight_now = 1; + } } + RtcTime.year += 1970; } diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index a9fe9161c..b6783f2ab 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -146,8 +146,7 @@ const char HTTP_SCRIPT_CONSOL[] PROGMEM = "lt=setTimeout(l,{a});" "return false;" "}" - "window.onload=l;" - ""; + "window.onload=l;"; const char HTTP_MODULE_TEMPLATE_REPLACE[] PROGMEM = "\2%d'>%s (%d\3"; // \2 and \3 are used in below os.replace @@ -2021,8 +2020,8 @@ void HandleConsole(void) String page = FPSTR(HTTP_HEAD); page.replace(F("{v}"), FPSTR(S_CONSOLE)); + page += FPSTR(HTTP_SCRIPT_CONSOL); page += FPSTR(HTTP_HEAD_STYLE); - page.replace(F(""), FPSTR(HTTP_SCRIPT_CONSOL)); page += FPSTR(HTTP_FORM_CMND); page += FPSTR(HTTP_BTN_MAIN); ShowPage(page); diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 62e445c91..850a5f2d0 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -395,6 +395,7 @@ bool EnergyCommand(void) Settings.energy_kWhtoday = energy_kWhtoday; RtcSettings.energy_kWhtoday = energy_kWhtoday; energy_daily = (float)energy_kWhtoday / 100000; + if (!RtcSettings.energy_kWhtotal && !energy_kWhtoday) { Settings.energy_kWhtotal_time = LocalTime(); } break; case 2: Settings.energy_kWhyesterday = lnum *100; @@ -403,7 +404,7 @@ bool EnergyCommand(void) RtcSettings.energy_kWhtotal = lnum *100; Settings.energy_kWhtotal = RtcSettings.energy_kWhtotal; energy_total = (float)(RtcSettings.energy_kWhtotal + energy_kWhtoday) / 100000; - if (!energy_total) { Settings.energy_kWhtotal_time = LocalTime(); } + Settings.energy_kWhtotal_time = (!energy_kWhtoday) ? LocalTime() : Midnight(); break; } } From 9e8ed1ae794dbb1cc834074724b3ca477565aa4b Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Fri, 1 Mar 2019 15:37:22 +0100 Subject: [PATCH 2/3] Kudos and houskeeping Kudos and houskeeping --- README.md | 3 +- sonoff/settings.h | 84 ++++++++++++++++++------------------ sonoff/xdrv_01_webserver.ino | 2 +- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/README.md b/README.md index dda9b6227..579263ec5 100644 --- a/README.md +++ b/README.md @@ -170,7 +170,8 @@ People helping to keep the show on the road: - Andre Thomas for providing [thehackbox](http://thehackbox.org/tasmota/) OTA support and daily development builds - Joel Stein and digiblur for their Tuya research and driver - Frogmore42 and Jason2866 for providing many issue answers -- Many more providing Tips, Pocs or PRs +- Blakadder for editing the wiki and providing template management +- Many more providing Tips, Wips, Pocs or PRs ### License diff --git a/sonoff/settings.h b/sonoff/settings.h index 447db10c0..342ff1612 100644 --- a/sonoff/settings.h +++ b/sonoff/settings.h @@ -25,54 +25,54 @@ typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... uint32_t data; // Allow bit manipulation using SetOption struct { // SetOption0 .. SetOption31 - uint32_t save_state : 1; // bit 0 - uint32_t button_restrict : 1; // bit 1 - uint32_t value_units : 1; // bit 2 - uint32_t mqtt_enabled : 1; // bit 3 - uint32_t mqtt_response : 1; // bit 4 - uint32_t mqtt_power_retain : 1; // CMND_POWERRETAIN - uint32_t mqtt_button_retain : 1; // CMND_BUTTONRETAIN - uint32_t mqtt_switch_retain : 1; // CMND_SWITCHRETAIN - uint32_t temperature_conversion : 1; // bit 8 - uint32_t mqtt_sensor_retain : 1; // CMND_SENSORRETAIN - uint32_t mqtt_offline : 1; // bit 10 - uint32_t button_swap : 1; // bit 11 (v5.1.6) - uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0) - uint32_t button_single : 1; // bit 13 (v5.4.0) - uint32_t interlock : 1; // bit 14 (v5.6.0) - uint32_t pwm_control : 1; // bit 15 (v5.8.1) - uint32_t ws_clock_reverse : 1; // bit 16 (v5.8.1) - uint32_t decimal_text : 1; // bit 17 (v5.8.1) - uint32_t light_signal : 1; // bit 18 (v5.10.0c) - uint32_t hass_discovery : 1; // bit 19 (v5.11.1a) - uint32_t not_power_linked : 1; // bit 20 (v5.11.1f) - uint32_t no_power_on_check : 1; // bit 21 (v5.11.1i) - uint32_t mqtt_serial : 1; // bit 22 (v5.12.0f) - uint32_t mqtt_serial_raw : 1; // bit 23 (v6.1.1c) // Was rules_enabled until 5.14.0b - uint32_t pressure_conversion : 1; // bit 24 (v6.3.0.2) // Was rules_once until 5.14.0b - uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) KNX - uint32_t device_index_enable : 1; // bit 26 (v5.13.1a) - uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.0a) KNX - uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) - uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) - uint32_t hass_light : 1; // bit 30 (v6.0.0b) - uint32_t global_state : 1; // bit 31 (v6.1.0) + uint32_t save_state : 1; // bit 0 - SetOption0 - Save power state and use after restart + uint32_t button_restrict : 1; // bit 1 - SetOption1 - Control button multipress + uint32_t value_units : 1; // bit 2 - SetOption2 - Add units to JSON status messages + uint32_t mqtt_enabled : 1; // bit 3 - SetOption3 - Control MQTT + uint32_t mqtt_response : 1; // bit 4 - SetOption4 - Switch between MQTT RESULT or COMMAND + uint32_t mqtt_power_retain : 1; // bit 5 - CMND_POWERRETAIN + uint32_t mqtt_button_retain : 1; // bit 6 - CMND_BUTTONRETAIN + uint32_t mqtt_switch_retain : 1; // bit 7 - CMND_SWITCHRETAIN + uint32_t temperature_conversion : 1; // bit 8 - SetOption8 - Switch between Celsius or Fahrenheit + uint32_t mqtt_sensor_retain : 1; // bit 9 - CMND_SENSORRETAIN + uint32_t mqtt_offline : 1; // bit 10 - SetOption10 - Control MQTT LWT message format + uint32_t button_swap : 1; // bit 11 (v5.1.6) - SetOption11 - Swap button single and double press functionality + uint32_t stop_flash_rotate : 1; // bit 12 (v5.2.0) - SetOption12 - Switch between dynamic or fixed slot flash save location + uint32_t button_single : 1; // bit 13 (v5.4.0) - SetOption13 - Support only single press to speed up button press recognition + uint32_t interlock : 1; // bit 14 (v5.6.0) - CMND_INTERLOCK + uint32_t pwm_control : 1; // bit 15 (v5.8.1) - SetOption15 - Switch between commands PWM or COLOR/DIMMER/CT/CHANNEL + uint32_t ws_clock_reverse : 1; // bit 16 (v5.8.1) - SetOption16 - Switch between clockwise or counter-clockwise + uint32_t decimal_text : 1; // bit 17 (v5.8.1) - SetOption17 - Switch between decimal or hexadecimal output + uint32_t light_signal : 1; // bit 18 (v5.10.0c) - SetOption18 - Pair light signal with CO2 sensor + uint32_t hass_discovery : 1; // bit 19 (v5.11.1a) - SetOption19 - Control Home Assistantautomatic discovery (See SetOption59) + uint32_t not_power_linked : 1; // bit 20 (v5.11.1f) - SetOption20 - Control power in relation to Dimmer/Color/Ct changes + uint32_t no_power_on_check : 1; // bit 21 (v5.11.1i) - SetOption21 - Show voltage even if powered off + uint32_t mqtt_serial : 1; // bit 22 (v5.12.0f) - CMND_SERIALSEND and CMND_SERIALLOG + uint32_t mqtt_serial_raw : 1; // bit 23 (v6.1.1c) - CMND_SERIALSEND3 + uint32_t pressure_conversion : 1; // bit 24 (v6.3.0.2) - SetOption24 - Switch between hPa or mmHg pressure unit + uint32_t knx_enabled : 1; // bit 25 (v5.12.0l) - CMND_KNX_ENABLED + uint32_t device_index_enable : 1; // bit 26 (v5.13.1a) - SetOption26 - Switch between POWER or POWER1 + uint32_t knx_enable_enhancement : 1; // bit 27 (v5.14.0a) - CMND_KNX_ENHANCED + uint32_t rf_receive_decimal : 1; // bit 28 (v6.0.0a) - SetOption28 - RF receive data format + uint32_t ir_receive_decimal : 1; // bit 29 (v6.0.0a) - SetOption29 - IR receive data format + uint32_t hass_light : 1; // bit 30 (v6.0.0b) - SetOption30 - Enforce HAss autodiscovery as light + uint32_t global_state : 1; // bit 31 (v6.1.0) - SetOption31 - Control link led blinking }; } SysBitfield; typedef union { // Restricted by MISRA-C Rule 18.4 but so useful... uint32_t data; // Allow bit manipulation using SetOption struct { // SetOption50 .. SetOption81 - uint32_t timers_enable : 1; // bit 0 (v6.1.1b) - uint32_t user_esp8285_enable : 1; // bit 1 (v6.1.1.14) - uint32_t time_append_timezone : 1; // bit 2 (v6.2.1.2) - uint32_t gui_hostname_ip : 1; // bit 3 (v6.2.1.20) - uint32_t tuya_apply_o20 : 1; // bit 4 (v6.3.0.4) - uint32_t mdns_enabled : 1; // bit 5 (v6.4.1.4) - SetOption55 - uint32_t use_wifi_scan : 1; // bit 6 (v6.3.0.10) - uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10) - uint32_t receive_raw : 1; // bit 8 (v6.3.0.11) - uint32_t hass_tele_on_power : 1; // bit 9 (v6.3.0.13) + uint32_t timers_enable : 1; // bit 0 (v6.1.1b) - CMND_TIMERS + uint32_t user_esp8285_enable : 1; // bit 1 (v6.1.1.14) - SetOption51 - Enable ESP8285 user GPIO's + uint32_t time_append_timezone : 1; // bit 2 (v6.2.1.2) - SetOption52 - Append timezone to JSON time + uint32_t gui_hostname_ip : 1; // bit 3 (v6.2.1.20) - SetOption53 - Show hostanme and IP address in GUI main menu + uint32_t tuya_apply_o20 : 1; // bit 4 (v6.3.0.4) - SetOption54 - Apply SetOption20 settings to Tuya device + uint32_t mdns_enabled : 1; // bit 5 (v6.4.1.4) - SetOption55 - Control mDNS service + uint32_t use_wifi_scan : 1; // bit 6 (v6.3.0.10) - SetOption56 - Scan wifi network at restart for configured AP's + uint32_t use_wifi_rescan : 1; // bit 7 (v6.3.0.10) - SetOption57 - Scan wifi network every 44 minutes for configured AP's + uint32_t receive_raw : 1; // bit 8 (v6.3.0.11) - SetOption58 - Add IR Raw data to JSON message + uint32_t hass_tele_on_power : 1; // bit 9 (v6.3.0.13) - SetOption59 - Send tele/%topic%/STATE in addition to stat/%topic%/RESULT uint32_t sleep_normal : 1; // bit 10 (v6.3.0.15) - SetOption60 - Enable normal sleep instead of dynamic sleep uint32_t button_switch_force_local : 1;// bit 11 (v6.3.0.16) - SetOption61 - Force local operation when button/switch topic is set uint32_t no_hold_retain : 1; // bit 12 (v6.4.1.19) - SetOption62 - Don't use retain flag on HOLD messages diff --git a/sonoff/xdrv_01_webserver.ino b/sonoff/xdrv_01_webserver.ino index b6783f2ab..a0f01a763 100644 --- a/sonoff/xdrv_01_webserver.ino +++ b/sonoff/xdrv_01_webserver.ino @@ -774,7 +774,7 @@ void HandleRoot(void) if (idx > 0) { page += F("