Skip to content

Commit

Permalink
Add support for BlitzWolf BW-SHP2
Browse files Browse the repository at this point in the history
Add support for BlitzWolf BW-SHP2 (and Homecube, Gosund SP1) Energy
Monitoring Smart Socket (arendst#2223)
  • Loading branch information
arendst committed Jul 2, 2018
1 parent f10ee76 commit 387936a
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 21 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions sonoff/_releasenotes.ino
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
55 changes: 43 additions & 12 deletions sonoff/sonoff_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ enum SupportedModules {
ZENGGE_ZF_WF017,
SONOFF_POW_R2,
SONOFF_IFAN02,
BLITZWOLF_BWSHP2,
MAXMODULE };

/********************************************************************************************/
Expand Down Expand Up @@ -251,6 +252,7 @@ const uint8_t kNiceList[MAXMODULE] PROGMEM = {
LUANIHVIO,
YUNSHAN,
WION,
BLITZWOLF_BWSHP2,
H801,
MAGICHOME,
ARILUX_LC01,
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
};

Expand Down
43 changes: 34 additions & 9 deletions sonoff/xdrv_03_energy.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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();
}
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 387936a

Please sign in to comment.