Energy (AC) - HLW8012/BL0937

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Energy (AC) - HLW8012/BL0937

#1 Post by pw444 » 09 Feb 2021, 15:22

Hya,

i got 2 HLW8012 boards, and had an esp8266-12 flashed with the ESP_Easy_mega_20201227_hard_SONOFF_POW_4M1M

wired all, and ijected 127V AC to the input of the HLW8012 board.

by devices, voltage, current, power and powerfactor, all remained 0.00.

any how to in have it testing?

TIA.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#2 Post by TD-er » 09 Feb 2021, 15:34

Here the setting I used on my Sonoff POW R1.
Do you have similar settings?
Especialy the device type (which is mentioned to be set first), you have to set it, save it and then see if the factors are read from the sensor.
Attachments
2021-02-09 15_32_55-Sonoff POW R1.png
2021-02-09 15_32_55-Sonoff POW R1.png (73.92 KiB) Viewed 17499 times

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#3 Post by pw444 » 09 Feb 2021, 15:47

that's the board

by device i have CUSTOM.
Attachments
HLW8012_High-Precision_Energy_Metering_Module_Arduino_Energy_Monitoring.png
HLW8012_High-Precision_Energy_Metering_Module_Arduino_Energy_Monitoring.png (203.72 KiB) Viewed 17494 times

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#4 Post by TD-er » 09 Feb 2021, 18:45

Have you some calibration values shown like on my screenshot?

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#5 Post by pw444 » 09 Feb 2021, 19:08

used the calbrition shown your screenshot, but reading are not good.. voltage is showing 1.00 when MM shows 128

i will try to calibrate using the example found in the hlw8012 library.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#6 Post by TD-er » 09 Feb 2021, 20:36

Those calibration values were read from the chip itself and probably stored in there by Sonoff.
They are based on the used shunt resistor and voltage divider resistors, so if you're using another set you may need to adjust the factors.
As first step I suggest to multiply the voltage factor by 128 :)

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#7 Post by pw444 » 10 Feb 2021, 17:42

did not work. i used the sketch from xoseperez, but no luck.

any hint?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#8 Post by TD-er » 10 Feb 2021, 18:49

There are quite a lot of possibilities with the configuration of SEL / CF1 / CF int edge parameters.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#9 Post by pw444 » 10 Feb 2021, 19:07

TD-er wrote: 10 Feb 2021, 18:49 There are quite a lot of possibilities with the configuration of SEL / CF1 / CF int edge parameters.
ok, and how? ;-)

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#10 Post by TD-er » 10 Feb 2021, 22:40

I would suggest to dive into the datasheet/schematics and compare it to the known units that are already listed in the ESPEasy plugin.

This is what is set in the source code:

Code: Select all

bool p076_getDeviceString(int device, String& name) {
  switch(device) {
    case P076_Custom   : name = F("Custom");          break;
    case P076_Sonoff   : name = F("Sonoff Pow (r1)"); break;
    case P076_Huafan   : name = F("Huafan SS");       break;
    case P076_KMC      : name = F("KMC 70011");       break;
    case P076_Aplic    : name = F("Aplic WDP303075"); break;
    case P076_SK03     : name = F("SK03 Outdoor");    break;
    case P076_BlitzWolf: name = F("BlitzWolf SHP");   break;
    case P076_Teckin   : name = F("Teckin");          break;
    case P076_TeckinUS : name = F("Teckin US");       break;
    case P076_Gosund   : name = F("Gosund SP1 v23");  break;
    case P076_Shelly_PLUG_S : name = F("Shelly PLUG-S");  break;
    default:
      return false;
  }
  return true;
}

bool p076_getDeviceParameters(int device, byte &SEL_Pin, byte &CF_Pin, byte &CF1_Pin, byte &Cur_read, byte &CF_Trigger, byte &CF1_Trigger) {
  switch(device) {
    case P076_Custom        : SEL_Pin =  0; CF_Pin =  0; CF1_Pin =  0; Cur_read =  LOW; CF_Trigger =     LOW; CF1_Trigger =    LOW; break;
    case P076_Sonoff        : SEL_Pin =  5; CF_Pin = 14; CF1_Pin = 13; Cur_read = HIGH; CF_Trigger =  CHANGE; CF1_Trigger = CHANGE; break;
    case P076_Huafan        : SEL_Pin = 13; CF_Pin = 14; CF1_Pin = 12; Cur_read = HIGH; CF_Trigger =  CHANGE; CF1_Trigger = CHANGE; break;
    case P076_KMC           : SEL_Pin = 12; CF_Pin =  4; CF1_Pin =  5; Cur_read = HIGH; CF_Trigger =  CHANGE; CF1_Trigger = CHANGE; break;
    case P076_Aplic         : SEL_Pin = 12; CF_Pin =  4; CF1_Pin =  5; Cur_read =  LOW; CF_Trigger =  CHANGE; CF1_Trigger = CHANGE; break;
    case P076_SK03          : SEL_Pin = 12; CF_Pin =  4; CF1_Pin =  5; Cur_read =  LOW; CF_Trigger =  CHANGE; CF1_Trigger = CHANGE; break;
    case P076_BlitzWolf     : SEL_Pin = 12; CF_Pin =  5; CF1_Pin = 14; Cur_read =  LOW; CF_Trigger = FALLING; CF1_Trigger = CHANGE; break;
    case P076_Teckin        : SEL_Pin = 12; CF_Pin =  4; CF1_Pin =  5; Cur_read =  LOW; CF_Trigger = FALLING; CF1_Trigger = CHANGE; break;
    case P076_TeckinUS      : SEL_Pin = 12; CF_Pin =  5; CF1_Pin = 14; Cur_read =  LOW; CF_Trigger = FALLING; CF1_Trigger = CHANGE; break;
    case P076_Gosund        : SEL_Pin = 12; CF_Pin =  4; CF1_Pin =  5; Cur_read =  LOW; CF_Trigger = FALLING; CF1_Trigger = CHANGE; break;
    case P076_Shelly_PLUG_S : SEL_Pin = 12; CF_Pin =  5; CF1_Pin = 14; Cur_read =  LOW; CF_Trigger = FALLING; CF1_Trigger = CHANGE; break;
    default:
      return false;
  }
  return true;
}

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#11 Post by pw444 » 18 Feb 2021, 20:29

ok, i purchased a SONOFF POWR2.

How to flash ESPeasy on it. Any good guide?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#12 Post by TD-er » 18 Feb 2021, 21:59

First a big warning.
Don't ever connect the unit to your PC when the Sonoff is connected to mains power !!!

You should use a USB to serial adapter and connect it to the pins on the Sonoff board.
Keep the button of the Sonoff pressed when powering on the Sonoff and keep it pressed till you started the flashing procedure.

Don't forget to connect the RX of the USB to serial adapter to TX of the Sonoff and vice verse.

Tasmota also has quite a lot of information about this: https://tasmota.github.io/docs/Getting-Started/

For the POW there is a special build.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#13 Post by pw444 » 18 Feb 2021, 22:20

no vcc and gnd from the usb to serial?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#14 Post by TD-er » 18 Feb 2021, 23:32

Yep otherwise your ESP will not work as you cannot (!!!!) use mains power to power the Sonoff while programming it.
But I didn't want to write down the obvious, just that you should make sure to swap RX and TX as that may not be obvious to anyone.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#15 Post by pw444 » 19 Feb 2021, 17:23

Yeah, got some confusion, but is flashed with ESPEasy.

Not, some questions:

Device leds (blue and red) - to which gpio's?

Relay?

The device is a SONOFF POW R2, so, there are some differences with the POW R1.

And is the setup the same?
Attachments
IMG_20210219_120749.jpg
IMG_20210219_120749.jpg (2.85 MiB) Viewed 17169 times
IMG_20210219_120714.jpg
IMG_20210219_120714.jpg (3.29 MiB) Viewed 17169 times

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Energy (AC) - HLW8012/BL0937

#16 Post by Micha_he » 19 Feb 2021, 17:38

Data from my SONOFF POW R2, Board V2.0:

Relais GPIO12
Push-Button GPIO0
Wifi-Status-Led (D5, blue) GPIO13 (inversed)
Status-Led (D6, red) internal connected to Relais or GPIO12

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#17 Post by pw444 » 19 Feb 2021, 17:49

thx.. can you share your setup (hardware and devices), and rules, if any?

what's the relay for?

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Energy (AC) - HLW8012/BL0937

#18 Post by Micha_he » 19 Feb 2021, 18:08

hardware.png
hardware.png (72.67 KiB) Viewed 17152 times
devices.png
devices.png (41.62 KiB) Viewed 17154 times
Task 4 is only for my special case, to remember last values...

Code: Select all

on System#Boot do
  AsyncEvent,Schalten=0
endon

on MQTT#Connected do
  AsyncEvent,HoleStatus
endon

on Taster#Status=1 do
  AsyncEvent,Schalten
endon

on Schalten do
  if %eventvalue%=1
    if [Relais#Status]=0
      GPIO,12,1
    endif
  else
    if %eventvalue%=0
      if [Relais#Status]=1
        GPIO,12,0
      endif
    else
      if %eventvalue%>1 or %eventvalue%<0
        // nichts machen
      else
        // umschalten
        GPIO,12,[Relais#Status#!Z]
      endif
    endif
  endif
endon

on HoleStatus do
  publish,%sysname%/status/CON,Connected
  publish,%sysname%/Relais/Status,[Relais#Status]
endon
The rule is a template, that I use on many ESPEasy-switches.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#19 Post by pw444 » 19 Feb 2021, 18:13

Danke!
how is the device messdaten defined?
Vielen dank nochmal.

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Energy (AC) - HLW8012/BL0937

#20 Post by Micha_he » 19 Feb 2021, 18:31

device1.png
device1.png (81.12 KiB) Viewed 17146 times
But the configuration data (three Ref parameter), can be other at your device.
You can use the hlwcalibrate-command to calibrate your device.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#21 Post by pw444 » 19 Feb 2021, 18:44

and where do i find hlwcalibrate-command?

Micha_he
Normal user
Posts: 369
Joined: 07 Feb 2018, 19:14
Location: Helmstedt, Germany

Re: Energy (AC) - HLW8012/BL0937

#22 Post by Micha_he » 19 Feb 2021, 18:49

Look here https://espeasy.readthedocs.io/en/lates ... /P076.html
and execute it in your ESP under /Tools/Command.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#23 Post by TD-er » 19 Feb 2021, 20:30

Just FYI, if you go to Tools->Factory reset, you'll find a number of "Pre-defined config" settings.
One of them (on a POW build) is for the POW and one for the POW2.

If you reset it to such a pre-defined config, almost all is already configured for you.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#24 Post by pw444 » 20 Feb 2021, 13:00

thanks for all.

i'm just not getting the relay to work.

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#25 Post by TD-er » 20 Feb 2021, 13:28

Have you tried the "factory reset" I mentioned?

Code: Select all

on Button1#switch do
  if [Button1#switch]=1
    gpio,12,1
  else
    gpio,12,0
  endif
endon

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#26 Post by pw444 » 22 Feb 2021, 17:34

worked perfectly with the sonoff pow r2.

now i have to struggle ith the hlw8012.

Haldi_2
Normal user
Posts: 53
Joined: 24 Aug 2020, 18:10

Re: Energy (AC) - HLW8012/BL0937

#27 Post by Haldi_2 » 28 Feb 2021, 23:20

Couldn't find much in the documentation. But what is the maximum refresh rate of these HLW8012/BLE0937 devices?

TD-er
Core team member
Posts: 8643
Joined: 01 Sep 2017, 22:13
Location: the Netherlands
Contact:

Re: Energy (AC) - HLW8012/BL0937

#28 Post by TD-er » 01 Mar 2021, 09:31

refresh rate as in how often the task may give a new value?
I guess the lowest value for the "Interval" is 1 second, but to be honest I don't know how often the internal values in the measurement chip are updated.

pw444
Normal user
Posts: 155
Joined: 23 Apr 2019, 15:34
Location: rio de janeiro

Re: Energy (AC) - HLW8012/BL0937

#29 Post by pw444 » 01 Mar 2021, 14:10

i did not change the refresh rates..... acepted as is. and it's working, for the sonoff pow r2.

Haldi_2
Normal user
Posts: 53
Joined: 24 Aug 2020, 18:10

Re: Energy (AC) - HLW8012/BL0937

#30 Post by Haldi_2 » 21 Mar 2021, 09:57

I've bought an NX-SM400 Wallplug with HLW8012/BL0937 Chip. Configured it. But seems like sometimes i get Errors that Voltage gets reportet waaaay to high and Current and Powerfactor get reported as 0. Only Power is shown correctly.
Screenshot 2021-03-21 095213.png
Screenshot 2021-03-21 095213.png (69.76 KiB) Viewed 15964 times

The Configuration of the NX-Sm400 was done in this thread. But now it seems to be some isses with the hardware of the chip.

P.S
I'v set 1 Second as Interval and that worked the same.

Post Reply

Who is online

Users browsing this forum: No registered users and 26 guests