From 387936a8527211992d860dd9db8dfcb0c9a06c88 Mon Sep 17 00:00:00 2001 From: Theo Arends Date: Mon, 2 Jul 2018 14:25:02 +0200 Subject: [PATCH] Add support for BlitzWolf BW-SHP2 Add support for BlitzWolf BW-SHP2 (and Homecube, Gosund SP1) Energy Monitoring Smart Socket (#2223) --- README.md | 1 + sonoff/_releasenotes.ino | 1 + sonoff/sonoff_template.h | 55 ++++++++++++++++++++++++++++++--------- sonoff/xdrv_03_energy.ino | 43 +++++++++++++++++++++++------- 4 files changed, 79 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index de88efcf047b..78f9776e1f5c 100644 --- a/README.md +++ b/README.md @@ -74,6 +74,7 @@ The following devices are supported: - [MagicHome PWM LED controller](https://github.com/arendst/Sonoff-Tasmota/wiki/MagicHome-LED-strip-controller) - AriLux AL-LC01, AL-LC06 and AL-LC11 PWM LED controller - [Supla device - Espablo-inCan mod. for electrical Installation box](https://forum.supla.org/viewtopic.php?f=33&t=2188) +- [BlitzWolf BW-SHP2 Smart Socket with Energy Monitoring](https://www.banggood.com/BlitzWolf-BW-SHP2-Smart-WIFI-Socket-EU-Plug-220V-16A-Work-with-Amazon-Alexa-Google-Assistant-p-1292899.html) - [Luani HVIO board](https://luani.de/projekte/esp8266-hvio/) - Wemos D1 mini, NodeMcu and Ledunia diff --git a/sonoff/_releasenotes.ino b/sonoff/_releasenotes.ino index 31ad23fccc9f..580e5a0be154 100644 --- a/sonoff/_releasenotes.ino +++ b/sonoff/_releasenotes.ino @@ -1,4 +1,5 @@ /* 6.0.0b + * Add support for BlitzWolf BW-SHP2 (and Homecube, Gosund SP1) Energy Monitoring Smart Socket (#2223) * Add support for Sonoff iFan02 as module 44 introducing command FanSpeed 0..3 (#2839) * Add support for Sonoff S26 Smart Socket (#2808) * Add command SetOption30 to enforce Hass discovery as light group (#1784) diff --git a/sonoff/sonoff_template.h b/sonoff/sonoff_template.h index dd061cae6ee1..4eeb3bf8049c 100644 --- a/sonoff/sonoff_template.h +++ b/sonoff/sonoff_template.h @@ -200,6 +200,7 @@ enum SupportedModules { ZENGGE_ZF_WF017, SONOFF_POW_R2, SONOFF_IFAN02, + BLITZWOLF_BWSHP2, MAXMODULE }; /********************************************************************************************/ @@ -251,6 +252,7 @@ const uint8_t kNiceList[MAXMODULE] PROGMEM = { LUANIHVIO, YUNSHAN, WION, + BLITZWOLF_BWSHP2, H801, MAGICHOME, ARILUX_LC01, @@ -456,7 +458,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1, // GPIO16 Green/Blue Led (1 = On, 0 = Off) GPIO_ADC0 // ADC0 A0 Analog input }, - { "EXS Relay", // Latching relay https://ex-store.de/ESP8266-WiFi-Relay-V31 (ESP8266) + { "EXS Relay", // Latching relay (ESP8266) + // https://ex-store.de/ESP8266-WiFi-Relay-V31 // Module Pin 1 VCC 3V3, Module Pin 6 GND GPIO_KEY1, // GPIO00 Module Pin 8 - Button (firmware flash) GPIO_USER, // GPIO01 Module Pin 2 = UART0_TXD @@ -472,7 +475,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO16 Module Pin 4 0 }, - { "WiOn", // Indoor Tap https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w (ESP8266) + { "WiOn", // Indoor Tap (ESP8266) + // https://www.amazon.com/gp/product/B00ZYLUBJU/ref=s9_acsd_al_bw_c_x_3_w GPIO_USER, // GPIO00 Optional sensor (pm clock) 0, GPIO_LED1, // GPIO02 Green Led (1 = On, 0 = Off) @@ -664,7 +668,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) 0, 0, 0, 0 }, - { "Supla Espablo", // Supla Espablo (ESP8266) - http://www.wykop.pl/ramka/3325399/diy-supla-do-puszki-instalacyjnej-podtynkowej-supla-org/ + { "Supla Espablo", // Supla Espablo (ESP8266) + // http://www.wykop.pl/ramka/3325399/diy-supla-do-puszki-instalacyjnej-podtynkowej-supla-org/ 0, // GPIO00 Flash jumper GPIO_USER, // GPIO01 Serial RXD and Optional sensor GPIO_DSB, // GPIO02 DS18B20 sensor @@ -679,7 +684,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1, // GPIO16 Led (1 = On, 0 = Off) GPIO_ADC0 // ADC0 A0 Analog input }, - { "Witty Cloud", // Witty Cloud Dev Board (ESP8266) - https://www.aliexpress.com/item/ESP8266-serial-WIFI-Witty-cloud-Development-Board-ESP-12F-module-MINI-nodemcu/32643464555.html + { "Witty Cloud", // Witty Cloud Dev Board (ESP8266) + // https://www.aliexpress.com/item/ESP8266-serial-WIFI-Witty-cloud-Development-Board-ESP-12F-module-MINI-nodemcu/32643464555.html GPIO_USER, // GPIO00 D3 flash push button on interface board GPIO_USER, // GPIO01 Serial RXD and Optional sensor GPIO_LED1_INV, // GPIO02 D4 Blue Led (0 = On, 1 = Off) on ESP-12F @@ -694,7 +700,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO16 D0 optional sensor GPIO_ADC0 // ADC0 A0 Light sensor / Requires USE_ADC_VCC in user_config.h to be disabled }, - { "Yunshan Relay", // Yunshan Wifi Relay (ESP8266) - https://www.ebay.com/p/Esp8266-220v-10a-Network-Relay-WiFi-Module/1369583381 + { "Yunshan Relay", // Yunshan Wifi Relay (ESP8266) + // https://www.ebay.com/p/Esp8266-220v-10a-Network-Relay-WiFi-Module/1369583381 // Schematics and Info https://ucexperiment.wordpress.com/2016/12/18/yunshan-esp8266-250v-15a-acdc-network-wifi-relay-module/ 0, // GPIO00 Flash jumper - Module Pin 8 GPIO_USER, // GPIO01 Serial RXD and Optional sensor - Module Pin 2 @@ -705,7 +712,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0, 0, 0, 0, 0, 0, // Flash connection 0, 0, 0, 0, 0 }, - { "MagicHome", // Magic Home (aka Flux-light) (ESP8266) - https://www.aliexpress.com/item/Magic-Home-Mini-RGB-RGBW-Wifi-Controller-For-Led-Strip-Panel-light-Timing-Function-16million-colors/32686853650.html + { "MagicHome", // Magic Home (aka Flux-light) (ESP8266) + // https://www.aliexpress.com/item/Magic-Home-Mini-RGB-RGBW-Wifi-Controller-For-Led-Strip-Panel-light-Timing-Function-16million-colors/32686853650.html 0, GPIO_USER, // GPIO01 Serial RXD and Optional sensor GPIO_LED1_INV, // GPIO02 Blue onboard LED @@ -718,7 +726,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_PWM1, // GPIO14 RGB LED Red 0, 0, 0 }, - { "Luani HVIO", // ESP8266_HVIO - https://luani.de/projekte/esp8266-hvio/ + { "Luani HVIO", // ESP8266_HVIO + // https://luani.de/projekte/esp8266-hvio/ 0, // GPIO00 Flash jumper GPIO_USER, // GPIO01 Serial RXD and Optional sensor GPIO_USER, // GPIO02 Optional sensor / I2C SDA pad @@ -733,7 +742,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { 0, GPIO_ADC0 // ADC0 A0 Analog input }, - { "KMC 70011", // KMC 70011 (https://www.amazon.com/KMC-Timing-Monitoring-Network-125V-240V/dp/B06XRX2GTQ) + { "KMC 70011", // KMC 70011 + // https://www.amazon.com/KMC-Timing-Monitoring-Network-125V-240V/dp/B06XRX2GTQ GPIO_KEY1, // GPIO00 Button 0, 0, 0, GPIO_HLW_CF, // GPIO04 HLW8012 CF @@ -744,7 +754,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_REL1, // GPIO14 Relay 0, 0, 0 }, - { "Arilux LC01", // Arilux AL-LC01 (ESP8285) - https://www.banggood.com/nl/ARILUX-AL-LC01-Super-Mini-LED-WIFI-Smart-RGB-Controller-For-RGB-LED-Strip-Light-DC-9-12V-p-1058603.html + { "Arilux LC01", // Arilux AL-LC01 (ESP8285) + // https://www.banggood.com/nl/ARILUX-AL-LC01-Super-Mini-LED-WIFI-Smart-RGB-Controller-For-RGB-LED-Strip-Light-DC-9-12V-p-1058603.html // (PwmFrequency 1111Hz) GPIO_KEY1, // GPIO00 Optional Button GPIO_USER, // GPIO01 Serial RXD and Optional sensor @@ -758,7 +769,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_USER, // GPIO14 RGBW LED White (optional - set to PWM4 for Cold White or Warm White) 0, 0, 0 }, - { "Arilux LC11", // Arilux AL-LC11 (ESP8266) - https://www.banggood.com/nl/ARILUX-AL-LC11-Super-Mini-LED-WIFI-APP-Controller-RF-Remote-Control-For-RGBWW-LED-Strip-DC9-28V-p-1085112.html + { "Arilux LC11", // Arilux AL-LC11 (ESP8266) + // https://www.banggood.com/nl/ARILUX-AL-LC11-Super-Mini-LED-WIFI-APP-Controller-RF-Remote-Control-For-RGBWW-LED-Strip-DC9-28V-p-1085112.html // (PwmFrequency 540Hz) GPIO_KEY1, // GPIO00 Optional Button GPIO_USER, // GPIO01 Serial RXD and Optional sensor @@ -788,7 +800,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1_INV, // GPIO13 Blue Led (0 = On, 1 = Off) 0, 0, 0, 0 }, - { "Arilux LC06", // Arilux AL-LC06 (ESP8285) - https://www.banggood.com/ARILUX-AL-LC06-LED-WIFI-Smartphone-Controller-Romote-5-Channels-DC12-24V-For-RGBWW-Strip-light-p-1061476.html + { "Arilux LC06", // Arilux AL-LC06 (ESP8285) + // https://www.banggood.com/ARILUX-AL-LC06-LED-WIFI-Smartphone-Controller-Romote-5-Channels-DC12-24V-For-RGBWW-Strip-light-p-1061476.html GPIO_KEY1, // GPIO00 Optional Button GPIO_USER, // GPIO01 Serial RXD and Optional sensor GPIO_USER, // GPIO02 Empty pad @@ -813,7 +826,8 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_LED1_INV, // GPIO13 Green Led (0 = On, 1 = Off) 0, 0, 0, 0 }, - { "Zengge WF017", // Zenggee ZJ-WF017-A (ESP12S)) - https://www.ebay.com/p/Smartphone-Android-IOS-WiFi-Music-Controller-for-RGB-5050-3528-LED-Strip-Light/534446632?_trksid=p2047675.l2644 + { "Zengge WF017", // Zenggee ZJ-WF017-A (ESP12S)) + // https://www.ebay.com/p/Smartphone-Android-IOS-WiFi-Music-Controller-for-RGB-5050-3528-LED-Strip-Light/534446632?_trksid=p2047675.l2644 GPIO_KEY1, // GPIO00 Optional Button 0, GPIO_USER, // GPIO02 Empty pad @@ -853,6 +867,23 @@ const mytmplt kModules[MAXMODULE] PROGMEM = { GPIO_KEY4, // GPIO14 Virtual button 4 as feedback from RC GPIO_REL4, // GPIO15 Relay 4 (0 = Off, 1 = On) controlling the fan 0, 0 + }, + { "BlitzWolf SHP2", // BlitzWolf BW-SHP2 (ESP8285 - BL0937 or HJL-01 Energy Monitoring) + // https://www.banggood.com/BlitzWolf-BW-SHP2-Smart-WIFI-Socket-EU-Plug-220V-16A-Work-with-Amazon-Alexa-Google-Assistant-p-1292899.html + // https://www.amazon.de/Steckdose-Homecube-intelligente-Verbrauchsanzeige-funktioniert/dp/B076Q2LKHG/ref=sr_1_fkmr0_1 + // https://www.amazon.de/Intelligente-Stromverbrauch-Fernsteurung-Schaltbare-Energieklasse/dp/B076WZQS4S/ref=sr_1_1 + GPIO_LED2_INV, // GPIO00 Red Led (1 = On, 0 = Off) + GPIO_USER, // GPIO01 Serial RXD and Optional sensor + GPIO_LED1_INV, // GPIO02 Blue Led (1 = On, 0 = Off) + GPIO_USER, // GPIO03 Serial TXD and Optional sensor + 0, + GPIO_HLW_CF, // GPIO05 BL0937 or HJL-01 CF power + 0, 0, 0, 0, 0, 0, // Flash connection + GPIO_HLW_SEL, // GPIO12 BL0937 or HJL-01 Sel output + GPIO_KEY1, // GPIO13 Button + GPIO_HLW_CF1, // GPIO14 BL0937 or HJL-01 CF1 voltage / current + GPIO_REL1, // GPIO15 Relay (0 = Off, 1 = On) + 0, 0 } }; diff --git a/sonoff/xdrv_03_energy.ino b/sonoff/xdrv_03_energy.ino index 180e9b858f44..e862ffdcd74f 100644 --- a/sonoff/xdrv_03_energy.ino +++ b/sonoff/xdrv_03_energy.ino @@ -93,18 +93,27 @@ void EnergyUpdateToday() } /*********************************************************************************************\ - * HLW8012 - Energy (Sonoff Pow) + * HLW8012, BL0937 or HJL-01 - Energy (Sonoff Pow) * * Based on Source: Shenzhen Heli Technology Co., Ltd \*********************************************************************************************/ +// HLW8012 based (Sonoff Pow, KMC70011) #define HLW_PREF 10000 // 1000.0W #define HLW_UREF 2200 // 220.0V #define HLW_IREF 4545 // 4.545A +#define HLW_SEL_VOLTAGE 1 + +// HJL-01 based (Homecube, BlitzWolf) +#define HJL_PREF 1362 +#define HJL_UREF 822 +#define HJL_IREF 3300 +#define HJL_SEL_VOLTAGE 0 #define HLW_POWER_PROBE_TIME 10 // Number of seconds to probe for power before deciding none used byte hlw_select_ui_flag; +byte hlw_ui_flag = 1; byte hlw_load_off; byte hlw_cf1_timer; unsigned long hlw_cf_pulse_length; @@ -117,6 +126,10 @@ unsigned long hlw_cf1_voltage_pulse_length; unsigned long hlw_cf1_current_pulse_length; unsigned long hlw_energy_period_counter; +unsigned long hlw_power_ratio = 0; +unsigned long hlw_voltage_ratio = 0; +unsigned long hlw_current_ratio = 0; + unsigned long hlw_cf1_voltage_max_pulse_counter; unsigned long hlw_cf1_current_max_pulse_counter; @@ -162,7 +175,7 @@ void HlwEverySecond() hlw_len = 10000 / hlw_energy_period_counter; hlw_energy_period_counter = 0; if (hlw_len) { - energy_kWhtoday_delta += ((HLW_PREF * Settings.energy_power_calibration) / hlw_len) / 36; + energy_kWhtoday_delta += ((hlw_power_ratio * Settings.energy_power_calibration) / hlw_len) / 36; EnergyUpdateToday(); } } @@ -180,7 +193,7 @@ void HlwEvery200ms() } if (hlw_cf_pulse_length && energy_power_on && !hlw_load_off) { - hlw_w = (HLW_PREF * Settings.energy_power_calibration) / hlw_cf_pulse_length; + hlw_w = (hlw_power_ratio * Settings.energy_power_calibration) / hlw_cf_pulse_length; energy_power = (float)hlw_w / 10; } else { energy_power = 0; @@ -197,12 +210,12 @@ void HlwEvery200ms() } else { hlw_cf1_pulse_length = 0; } - if (hlw_select_ui_flag) { + if (hlw_select_ui_flag == hlw_ui_flag) { hlw_cf1_voltage_pulse_length = hlw_cf1_pulse_length; hlw_cf1_voltage_max_pulse_counter = hlw_cf1_pulse_counter; if (hlw_cf1_voltage_pulse_length && energy_power_on) { // If powered on always provide voltage - hlw_u = (HLW_UREF * Settings.energy_voltage_calibration) / hlw_cf1_voltage_pulse_length; + hlw_u = (hlw_voltage_ratio * Settings.energy_voltage_calibration) / hlw_cf1_voltage_pulse_length; energy_voltage = (float)hlw_u / 10; } else { energy_voltage = 0; @@ -213,7 +226,7 @@ void HlwEvery200ms() hlw_cf1_current_max_pulse_counter = hlw_cf1_pulse_counter; if (hlw_cf1_current_pulse_length && energy_power) { // No current if no power being consumed - hlw_i = (HLW_IREF * Settings.energy_current_calibration) / hlw_cf1_current_pulse_length; + hlw_i = (hlw_current_ratio * Settings.energy_current_calibration) / hlw_cf1_current_pulse_length; energy_current = (float)hlw_i / 1000; } else { energy_current = 0; @@ -233,6 +246,18 @@ void HlwInit() Settings.energy_current_calibration = HLW_IREF_PULSE; } + if (BLITZWOLF_BWSHP2 == Settings.module) { + hlw_power_ratio = HJL_PREF; + hlw_voltage_ratio = HJL_UREF; + hlw_current_ratio = HJL_IREF; + hlw_ui_flag = HJL_SEL_VOLTAGE; + } else { + hlw_power_ratio = HLW_PREF; + hlw_voltage_ratio = HLW_UREF; + hlw_current_ratio = HLW_IREF; + hlw_ui_flag = HLW_SEL_VOLTAGE; + } + hlw_cf_pulse_length = 0; hlw_cf_pulse_last_time = 0; hlw_cf1_pulse_length = 0; @@ -918,7 +943,7 @@ boolean EnergyCommand() else if (((ENERGY_HLW8012 == energy_flg) || (ENERGY_CSE7766 == energy_flg)) && (CMND_POWERSET == command_code)) { // Watt if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 3601)) { if ((ENERGY_HLW8012 == energy_flg) && hlw_cf_pulse_length) { - Settings.energy_power_calibration = (XdrvMailbox.payload * 10 * hlw_cf_pulse_length) / HLW_PREF; + Settings.energy_power_calibration = (XdrvMailbox.payload * 10 * hlw_cf_pulse_length) / hlw_power_ratio; } else if ((ENERGY_CSE7766 == energy_flg) && power_cycle) { Settings.energy_power_calibration = (XdrvMailbox.payload * power_cycle) / CSE_PREF; @@ -938,7 +963,7 @@ boolean EnergyCommand() else if (((ENERGY_HLW8012 == energy_flg) || (ENERGY_CSE7766 == energy_flg)) && (CMND_VOLTAGESET == command_code)) { // Volt if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 501)) { if ((ENERGY_HLW8012 == energy_flg) && hlw_cf1_voltage_pulse_length) { - Settings.energy_voltage_calibration = (XdrvMailbox.payload * 10 * hlw_cf1_voltage_pulse_length) / HLW_UREF; + Settings.energy_voltage_calibration = (XdrvMailbox.payload * 10 * hlw_cf1_voltage_pulse_length) / hlw_voltage_ratio; } else if ((ENERGY_CSE7766 == energy_flg) && voltage_cycle) { Settings.energy_voltage_calibration = (XdrvMailbox.payload * voltage_cycle) / CSE_UREF; @@ -958,7 +983,7 @@ boolean EnergyCommand() else if (((ENERGY_HLW8012 == energy_flg) || (ENERGY_CSE7766 == energy_flg)) && (CMND_CURRENTSET == command_code)) { // milliAmpere if ((XdrvMailbox.payload > 0) && (XdrvMailbox.payload < 16001)) { if ((ENERGY_HLW8012 == energy_flg) && hlw_cf1_current_pulse_length) { - Settings.energy_current_calibration = (XdrvMailbox.payload * hlw_cf1_current_pulse_length) / HLW_IREF; + Settings.energy_current_calibration = (XdrvMailbox.payload * hlw_cf1_current_pulse_length) / hlw_current_ratio; } else if ((ENERGY_CSE7766 == energy_flg) && current_cycle) { Settings.energy_current_calibration = (XdrvMailbox.payload * current_cycle) / 1000;