Energy consumption and Arlec Grid Connect (Tuya) smart plug

Good point - I admit I was being lazy. Just cracked one PC44HA open, and all the caps were visually ok ie no bulges etc. If I can be bothered I’ll take out the capacitors and test them one at a time - assumption being if I find a bad one, it will be common on all the switches.

1 Like

Where did you source this from BTW? Some kind of calibration I take it?

Yes … good question … but from where …
Found it over at Esphome install does not update firmware - #10 by Ellcon said

Of course I don’t know how much variation there may be between individual units … but personally I only want to know whether my chest freezer is running or not.


Personally I would like to standardise on zigbee for any future device purchases, and so I haven’t bought a PC191HA v2 unit yet … but I do agree the Pro’s you mention are compelling - and nothing in zigbee that comes close :frowning:

I am interested to compare your configuration, and try out any differences … though of course they are likely to be added functionality in the CB2S chip.

1 Like

All the extra’s I’ve added shouldn’t depend on the CB2S (most of it I pinched from the Anthom config which is another chip altogether (ESP8266). It’s all ESPHome level stuff.
You might like to look over adopting the “Total Energy” and “Total Daily Energy” for example.

I’ve also updated my config to include some of those calibrations and other bits.

I looked into Tuya’s dp_id 17 add_ele and discovered that it reports incremental power used since the last time it was reported … so particularly dependent on frequency of reporting (when my devices were dropping off my wi-fi) and that all values are captured and database updated (at the time I was getting ingress errors in my log).

And the history from one of my TP-Link HS110’s using TP-Link KASA integration (looks similar to Tuya) doesn’t inspire confidence…

However I have nothing to loose by trying out the ESPHome / PC191HA Energy values :smiley: thanks

Wow, the firmware might be the same, but your CB2S chip’s pin numbering is way different from my WB2S chip !
Also I’m not seeing where status_led is used

Compiled with only one section commented out - I’ll come back to that later.
Installed, and device rebooted with firmware compiled 2 days ago … so no change to the unwritten “power off for a random time to get PC191HA to activate the uploaded firmware”. Further testing tomorrow…

1 Like

Not entirely sure myself but seem to recall both red and blue led flashes when I was in the initial flashing process.
So probably the blue one is used for regular state indications and the red one for “warnings”. This could possibly be specific to my plug version.

I understand that the version 1 of PC191HA has 2 LEDs - the one we can see in the button, and apparently another inside the case which the factory uses to indicates the wi-fi status. Since I don’t want to open any up (at least while still under warranty) I never bothered programming it - what is the point of giving a visual indication that can’t be seen ?

My guess is that the “status_led” may refer to that internal LED, and so it doesn’t matter if nothing is using it. Of course assuming that v2 is the same as v1 :wink:

1 Like

I got another 4 of these flashed without much drama. Much easier and faster after you’ve done your first.

There’s an opportunity to use these things as ble scanners (or bluetooth proxies?).

But I know those things are memory intensive, so maybe not a good idea.

I had a go at using a common config using include.

In the devices yaml (arlec-smartplug-3.yaml)

<<: !include .arlec-smartplug-common.yaml
  
esphome:
  name: arlec-smartplug-3
  friendly_name: Arlec Smartplug 3
  comment: "Arlec White Grid Connect Smart Plug in Socket with Energy Meter"  
 
wifi:
  ap:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.131
    gateway: 192.168.1.1
    subnet: 255.255.255.0

in .arlec-smartplug-common.yaml

# Config for Arlec White Grid Connect Smart Plug in Socket with Energy Meter 
# Product Code: PC191HA (White) & PC191BKHA (Black). “Series 2” (CB2S module, BK7231N chip)
# https://www.bunnings.com.au/arlec-white-grid-connect-smart-plug-in-socket-with-energy-meter_p0273367
# https://upk.libretiny.eu/?profile=arlec-pc191ha-smart-plug-bk7231n-v1.1.8
# Copied some config from Athom: https://github.com/athom-tech/athom-configs/blob/e9d1218fe0d8b4631cda211d204dd3ff5ac698be/athom-smart-plug-v2.yaml

substitutions:
  relay_restore_mode: RESTORE_DEFAULT_OFF         #Adjust as required.
  hlw8012_update_interval: 30s                    #Not sure how this affects lifetime and maybe overheating? 
  

bk72xx:
  board: generic-bk7231n-qfn32-tuya #https://docs.libretiny.eu/boards/cb2s/  

logger:
mdns:
api:
  password: ""
ota:
  password: ""

globals:
  - id: total_energy
    type: float
    restore_value: yes
    initial_value: '0.0'
  
sensor:
  - platform: uptime
    name: Uptime
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
    
  - platform: hlw8012
    model: BL0937
    update_interval: ${hlw8012_update_interval}
    change_mode_every: 3
    voltage_divider: 770 #Required changing
    current_resistor: 0.001 ohm
    cf_pin:
      number: P8
      inverted: true
    cf1_pin:
      number: P7
      inverted: true
    sel_pin:
      number: P6
      inverted: true
    current:
      name: Current
      filters:
        - multiply: 0.4250 #https://community.home-assistant.io/t/esphome-install-does-not-update-firmware/544026/10?u=mahko_mahko
        - lambda: if (x < 0.01) {return 0;} else {return x;}
    voltage:
      name: Voltage
    power:
      name: Power
      id: power_sensor
      filters:
        - multiply: 0.97
        - lambda: if (x < 0.01) {return 0;} else {return x;}
    energy:
      name: Energy
      id: energy
      unit_of_measurement: kWh
      filters:
        - multiply: 0.001  # Multiplication factor from W to kW is 0.001
      on_value:
        then:
          - lambda: |-
              static float previous_energy_value = 0.0;
              float current_energy_value = id(energy).state;
              id(total_energy) += current_energy_value - previous_energy_value;
              previous_energy_value = current_energy_value;
              
  - platform: template
    name: "Total Energy"
    unit_of_measurement: kWh
    device_class: "energy"
    state_class: "total_increasing"
    icon: "mdi:lightning-bolt"
    accuracy_decimals: 3
    lambda: |-
      return id(total_energy);
    update_interval: ${hlw8012_update_interval}
    
  - platform: total_daily_energy
    name: "Total Daily Energy"
    restore: true
    power_id: power_sensor
    unit_of_measurement: kWh
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
    
output:
  - platform: libretiny_pwm
    id: output_led_1
    pin:
      number: P23
      inverted: true

light:
  - platform: monochromatic
    id: light_switch_1
    output: output_led_1

binary_sensor:
  - platform: gpio
    id: binary_switch_1
    pin:
      number: P10
      inverted: true
      mode: INPUT_PULLUP
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: switch_1
      - timing:
          - ON for at least 4s
        then:
          - button.press: Reset

switch:
  - platform: gpio
    id: switch_1
    name: Relay 1
    pin: P24
    on_turn_on:
      - light.turn_on: light_switch_1
    on_turn_off:
      - light.turn_off: light_switch_1
    restore_mode: ${relay_restore_mode}

status_led:
  pin:
    number: P26
    inverted: true
    
text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version
  - platform: wifi_info
    ip_address:
      name: "IP Address"
    ssid:
      name: "Connected SSID"
    mac_address:
      name: "Mac Address"
      
button:
  - platform: factory_reset
    name: "Restart with Factory Default Settings"
    id: Reset

  - platform: safe_mode
    name: "Safe Mode"
    internal: false
    
time:
  - platform: sntp
    id: sntp_time

I just bought a 4-pack of the PC191HA version 2, and can confirm that the Blue LED is used to indicate the switch’s ON/OFF state, and a Red LED blinks fast or slow to indicate that it is pairing.

I also found that all 4 of my devices took at least 3 attempts before they paired. Curiously the device’s LED would often stop blinking at about 1:50 on the countdown, but most often the Grid Connect app would simply time out. The MAC addresses were not consecutive, and all have firmware 1.3.5

I did have a go at this before, but didn’t get it to work. Thank you for showing the correct split between include and device.yaml. YES, working nicely … except that the v1 and v2 devices use different pin numbers … maybe i can nest includes.

I recall mine were a bit fiddly too.

I think putting them in pairing mode was a bit confusing.

Not sure if I even connected mine to an app. I don’t think so. Or maybe just the first one.

I got my include streamlined a bit further actually.

For each device:

E.g
arlec-smartplug-2.yaml

substitutions:
  static_ip_last_3chars: "130"
  plug_number: "2"
  plug_colour:  "White"

packages:
  device_base: !include common/.arlec-smartplug-common.yaml

in .arlec-smartplug-common.yaml

# Config for Arlec White Grid Connect Smart Plug in Socket with Energy Meter 
# Product Code: PC191HA (White) & PC191BKHA (Black). “Series 2” (CB2S module, BK7231N chip)
# https://www.bunnings.com.au/arlec-white-grid-connect-smart-plug-in-socket-with-energy-meter_p0273367
# https://upk.libretiny.eu/?profile=arlec-pc191ha-smart-plug-bk7231n-v1.1.8
# Copied some config from Athom: https://github.com/athom-tech/athom-configs/blob/babced13aaa8462361d6f4100430cf8be95f193a/athom-smart-plug-v2.yaml

substitutions:
  relay_restore_mode: RESTORE_DEFAULT_OFF         #Adjust as required.
  hlw8012_update_interval: 30s                    #Not sure how this affects lifetime and maybe overheating? 
  static_ip_last_3chars: "xxx"
  plug_number: "xxx"
  plug_colour:  "xxx"


esphome:
  name: arlec-smartplug-${plug_number}
  friendly_name: Arlec Smartplug ${plug_number}
  comment: Arlec ${plug_colour} Grid Connect Smart Plug in Socket with Energy Meter 
  
wifi:
  ap:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  manual_ip:
    static_ip: 192.168.1.${static_ip_last_3chars}
    gateway: 192.168.1.1
    subnet: 255.255.255.0


bk72xx:
  board: generic-bk7231n-qfn32-tuya #https://docs.libretiny.eu/boards/cb2s/  

logger:
mdns:
api:
  password: ""
ota:
  password: ""

globals:
  - id: total_energy
    type: float
    restore_value: yes
    initial_value: '0.0'
  
sensor:
  - platform: uptime
    name: Uptime
  - platform: wifi_signal
    name: "WiFi Signal"
    update_interval: 60s
    
  - platform: hlw8012
    model: BL0937
    update_interval: ${hlw8012_update_interval}
    change_mode_every: 3
    voltage_divider: 770 #Required changing
    current_resistor: 0.001 ohm
    cf_pin:
      number: P8
      inverted: true
    cf1_pin:
      number: P7
      inverted: true
    sel_pin:
      number: P6
      inverted: true
    current:
      name: Current
      filters:
        - multiply: 0.4250 #https://community.home-assistant.io/t/esphome-install-does-not-update-firmware/544026/10?u=mahko_mahko
        - lambda: if (x < 0.01) {return 0;} else {return x;}
    voltage:
      name: Voltage
    power:
      name: Power
      id: power_sensor
      filters:
        - multiply: 0.97
        - lambda: if (x < 0.01) {return 0;} else {return x;}
    energy:
      name: Energy
      id: energy
      unit_of_measurement: kWh
      filters:
        - multiply: 0.001  # Multiplication factor from W to kW is 0.001
      on_value:
        then:
          - lambda: |-
              static float previous_energy_value = 0.0;
              float current_energy_value = id(energy).state;
              id(total_energy) += current_energy_value - previous_energy_value;
              previous_energy_value = current_energy_value;
              
  - platform: template
    name: "Total Energy"
    unit_of_measurement: kWh
    device_class: "energy"
    state_class: "total_increasing"
    icon: "mdi:lightning-bolt"
    accuracy_decimals: 3
    lambda: |-
      return id(total_energy);
    update_interval: ${hlw8012_update_interval}
    
  - platform: total_daily_energy
    name: "Total Daily Energy"
    restore: true
    power_id: power_sensor
    unit_of_measurement: kWh
    accuracy_decimals: 3
    filters:
      - multiply: 0.001
    
output:
  - platform: libretiny_pwm
    id: output_led_1
    pin:
      number: P23
      inverted: true

light:
  - platform: monochromatic
    id: light_switch_1
    output: output_led_1

binary_sensor:
  - platform: gpio
    id: binary_switch_1
    pin:
      number: P10
      inverted: true
      mode: INPUT_PULLUP
    on_multi_click:
      - timing:
          - ON for at most 1s
          - OFF for at least 0.2s
        then:
          - switch.toggle: switch_1
      - timing:
          - ON for at least 4s
        then:
          - button.press: Reset

switch:
  - platform: gpio
    id: switch_1
    name: Relay 1
    pin: P24
    on_turn_on:
      - light.turn_on: light_switch_1
    on_turn_off:
      - light.turn_off: light_switch_1
    restore_mode: ${relay_restore_mode}

status_led:
  pin:
    number: P26
    inverted: true
    
text_sensor:
  - platform: libretiny
    version:
      name: LibreTiny Version
  - platform: wifi_info
    ip_address:
      name: "IP Address"
    ssid:
      name: "Connected SSID"
    mac_address:
      name: "Mac Address"
      
button:
  - platform: factory_reset
    name: "Restart with Factory Default Settings"
    id: Reset

  - platform: safe_mode
    name: "Safe Mode"
    internal: false
    
time:
  - platform: sntp
    id: sntp_time

Aaaarrrrrgggggggghhhhhhhhhhhhhh !!!

To summarise: I purchased another 4-pack of Arlec Grid Connect PC191HA series 2, and am trying to get them into HA’s ESPHome add-on in the most straight-forward manner (my previous ones required the grid connect app, Tuya website, cloudcutter, LibreTiny and a final push to ESPHome’s HA add-on).

  • Breakdown by tonyb62 shows the “Series 2” is a CB2S version (BK7231N). He states he chose “the device by firmware version - 1.1.8 - BK7231N / oem_bk7231n_plug”
  • tuya-cloudcutter gives Arlec device options “PC191HA Smart Plug BK7231N v1.1.8” and "PC191HA Smart Plug BK7231T v1.3.5
  • According to the Grid Connect phone app, my v2 units have 1.3.5 firmware … which doesn’t match with the series 2 info.
  • Curiously tuya-cloudcutter lists only one for firmware version 1.3.5 (1.3.5 - BK7231T / oem_bk7231s_dltj. )

Now I am confused. Is there a third option; a series 2 with BK7231N and v1.3.5 ??? If so, which chip does it use ?

And then… over in elektroda forum, ilium007 advises :

p.kaczmarek2 wrote:
Thanks, so let me sum up - the “Series 2” is a CB2S version (BK7231N) and older version (no Series in the title?) is WB2S?

To throw a spanner in the works… I have a PC191HA Series 2 (stamped on box and printed on back of device) that has a BK7231T / WB2S in it!

I have my PC191HA Series 2 (CB2S) running in HA using ESPHome with the pinout help from this thread - thanks! I also have a PC191HA Series 2 running the other module (WB2S). The CB2S has the red wifi LED (P11 I believe) always on unless the relay is on and the blue LED (P26) is lit.


My guess is therefore that I have some of the units labelled as series 2 which are in fact series 1 internally.

I reinstalled tuya-cloudcutter, and used it to select the device type PC191HA Smart Plug BK7231T v1.3.5 and move to my WLAN

sudo ./tuya-cloudcutter.sh -r -s dagoba password

then used cloudcutter to upload the ESPhome kickstart firmware from the files in custom-firmware and device-profiles

sudo ./tuya-cloudcutter.sh -r -f ESPHome-Kickstart-v23.08.29_bk7231t_app.ota.ug.bin -p arlec-pc191ha-smart-plug-bk7231t-v1.3.5

I have tried various things and got 2 devices online and updating from the HA ESPHome add-on with the version 1 configuration.

The other 2 devices are now bricked, with no action when pressing the button - even when holding it down 20 seconds. I have kept my receipt, so will try swapping them at Bunnings.

Im about to embark on home assistant and am researching integration of some key equipment around our property, including Grid connect. We have two grid connect power switches (white second gen compact style) located by a dam. One switching the irrigation pump the other a bore pump. To my surprise they are still working after 12 months, somewhat exposed one covered by a plastic bucket on a power post. The pumps run at 1800w for average 5 hours per day over the summer. Wifi range is 55 meters LOS to a pole mounted outdoor Unifi Access point, UAP AC M Pro. I added additional weather sealing to the join in the grid connect switch case with white electricians tape , the pairing and on button remains visible. Unlike earlier models, the compact style switches display power consumption which is very useful. The alternative industrial 2kW switch and monitoring was just a little more expensive than $25! I’m enthusiastic but fall short on programming and code skills so keep up the good work fellas…!

This post alone got me to sign up for an account,
I too ran into differing hardware versions in the same box (Multi-pack of 4)
in the end I ended up just running cloudcutter against them all on one profile, the ones that ended with “Your chosen profile did not result in an exploit” or whatever it said. I ran again using the other profile. Annoying, but I guess Arlec has to get rid of stock somehow.

1 Like

And today I noticed Arlec PC191HA series 3 at Bunnings (for the same $15 price as a single series 2 unit).

I wonder if anyone has tried one of these yet ? If so do you know what chip and firmware it uses; and whether they still use the 470uF 10V capacitors which last only 1-2 years ?

Interesting. Hadn’t seen them, but then again after having four of the older version die on me I’m thinking that they are cheap for a reason. I’m currently playing with Shelly Plus1 PM. More expensive and - in oz - have to arrange for an electrician to have it installed, but then it’s hidden behind the wall plate and has got a lot more features like ble tracking…

true, true … but they are compact (fit side-by-side in a multi-outlet box with the switches accessible), I’m renting, and … if anything better has been recommended i must have missed it.
I have resigned myself to replacing them every 1-2 years, but at $55 for a 4 pack it’s more a matter of waste than cost.

UPDATE: I purchased a 4-pack of the “series 2” … and found that they are all actually series 3 with firmware v1.1.17 (which is patched so that cloudcutter doesn’t work)

I bought one yesterday after your post and yes, can’t do OTA. Had a bit of a go but a real pain to open the housing.

Hello, I got two units yesterday. Both marked as Series 2 on the box
White is actually Series 3
Black one is series 2!

I will replace the white one for black but wont buy more. Looking forward to Ikea energy monitor plug coming to AU.

Managed to open up without damage and uses a CB2S module. No luck programming in place so will remove module and try again.

As expected, once removed conversion was straight forward. In the firmware pins 6 & 8 are swapped but everything else appears the same. A lot more work now that you can’t cut these OTA.