From 164b3aaf111ee1514741fedba8b5b236854fda46 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Tue, 4 Jun 2019 17:30:03 +0200 Subject: [PATCH] Add command SetOption39 1..255 to control CSE7766 (Pow R2) or HLW8032 (Blitzwolf SHP5) handling of power loads below 6W Add command SetOption39 1..255 to control CSE7766 (Pow R2) or HLW8032 (Blitzwolf SHP5) handling of power loads below 6W. Default setting is 128 (#5756) --- sonoff/_changelog.ino | 1 + sonoff/sonoff.h | 2 +- sonoff/xnrg_02_cse7766.ino | 11 ++++++++--- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sonoff/_changelog.ino b/sonoff/_changelog.ino index 0a0f6c90f..2a94dec7a 100644 --- a/sonoff/_changelog.ino +++ b/sonoff/_changelog.ino @@ -2,6 +2,7 @@ * Change webserver HTML input, button, textarea, and select name based on id * Fix webserver multiple Javascript window.onload functionality * Fix PZem startup issue (#5875) + * Add command SetOption39 1..255 to control CSE7766 (Pow R2) or HLW8032 (Blitzwolf SHP5) handling of power loads below 6W. Default setting is 128 (#5756) * * 6.5.0.13 20190527 * Add command SetOption38 6..255 to set IRReceive protocol detection sensitivity mimizing UNKNOWN protocols (#5853) diff --git a/sonoff/sonoff.h b/sonoff/sonoff.h index d7d4ef905..d6c4f20b1 100644 --- a/sonoff/sonoff.h +++ b/sonoff/sonoff.h @@ -236,7 +236,7 @@ enum ButtonStates { PRESSED, NOT_PRESSED }; enum Shortcuts { SC_CLEAR, SC_DEFAULT, SC_USER }; -enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 +enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_TUYA_DIMMER_ID, P_MDNS_DELAYED_START, P_BOOT_LOOP_OFFSET, P_RGB_REMAP, P_IR_UNKNOW_THRESHOLD, P_CSE7766_INVALID_POWER, P_MAX_PARAM8}; // Max is PARAM8_SIZE (18) - SetOption32 until SetOption49 enum DomoticzSensors {DZ_TEMP, DZ_TEMP_HUM, DZ_TEMP_HUM_BARO, DZ_POWER_ENERGY, DZ_ILLUMINANCE, DZ_COUNT, DZ_VOLTAGE, DZ_CURRENT, DZ_AIRQUALITY, DZ_MAX_SENSORS}; diff --git a/sonoff/xnrg_02_cse7766.ino b/sonoff/xnrg_02_cse7766.ino index b2b2cecca..793cf08ce 100644 --- a/sonoff/xnrg_02_cse7766.ino +++ b/sonoff/xnrg_02_cse7766.ino @@ -1,5 +1,5 @@ /* - xnrg_02_cse7766.ino - CSE7766 energy sensor support for Sonoff-Tasmota + xnrg_02_cse7766.ino - CSE7766 and HLW8032 energy sensor support for Sonoff-Tasmota Copyright (C) 2019 Theo Arends @@ -21,6 +21,7 @@ #ifdef USE_CSE7766 /*********************************************************************************************\ * CSE7766 - Energy (Sonoff S31 and Sonoff Pow R2) + * HLW8032 - Energy (Blitzwolf SHP5) * * Based on datasheet from http://www.chipsea.com/UploadFiles/2017/08/11144342F01B5662.pdf \*********************************************************************************************/ @@ -44,7 +45,7 @@ long power_cycle = 0; long power_cycle_first = 0; long cf_pulses = 0; long cf_pulses_last_time = CSE_PULSES_NOT_INITIALIZED; -uint8_t cse_power_invalid = CSE_MAX_INVALID_POWER; +uint8_t cse_power_invalid = 0; void CseReceived(void) { @@ -106,7 +107,7 @@ void CseReceived(void) } } } else { - if (cse_power_invalid < CSE_MAX_INVALID_POWER) { // Allow measurements down to about 1W + if (cse_power_invalid < Settings.param[P_CSE7766_INVALID_POWER]) { // Allow measurements down to about 1W cse_power_invalid++; } else { power_cycle_first = 0; @@ -209,6 +210,10 @@ void CseDrvInit(void) if ((3 == pin[GPIO_CSE7766_RX]) && (1 == pin[GPIO_CSE7766_TX])) { // As it uses 8E1 currently only hardware serial is supported baudrate = 4800; serial_config = SERIAL_8E1; + if (0 == Settings.param[P_CSE7766_INVALID_POWER]) { + Settings.param[P_CSE7766_INVALID_POWER] = CSE_MAX_INVALID_POWER; // SetOption39 1..255 + } + cse_power_invalid = Settings.param[P_CSE7766_INVALID_POWER]; energy_flg = XNRG_02; } }