Elektroda.com
Elektroda.com
X

Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

jessemclachlan 2151 43
  • Hi All,

    This is my first post, after watching this project over the last few months, and deciding I should give it a go!

    This is a quick teardown of the Arlec Grid Connect PC191 Smart Plug-In Socket with Energy Meter

    These are available through Bunnings in Australia individually for about AU$20 and in an even cheaper 4 pack

    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    TLDR I have also built a Cloudcutter profile for this, so its not necessary to open the unit if you want to flash custom firmware. I've raised a pull request with cloudcutter which hopefully gets merged, but otherwise "tuya-generic-nas-wr01w-smart-plug" has the same profile and so should work as well.

    This uses a Tuya WB2S module with a BK7231T chip.
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    The device itself is fully ultrasonically welded in its plastic case, so not easy to dismantle without damage, however a generous tap with a small set of pliers while working around the seam with a thin, wide spudger was enough to break it free. Once disassembled there are no screws inside and the mains terminals pull through the enclosure. This also means reassembly will need to be strong enough to maintain mains isolation, so don't skimp on the super glue :)

    Inside I was relieved to see dual relays for switching active and neutral, though as with most of these devices, there is is a non-isolated power supply for the wifi module, so all IO are live, beware while debugging or flashing.
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    As the TX/RX pins are used for the LED and Button, Dumping/Flashing also requires removing the module (or at least desoldering the TX/RX pins).
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    There is one button, a red 'wifi' status LED, a blue relay indicator, a single relay control for both active and neutral relays, and a BL0937 energy meter.

    P6 (PWM0) is the Relay
    P7 (PWM1) is the BL0937CF pin
    P8 (PWM2) is the BL0937CF1 pin
    P24 (PWM4) is the BL0939SEL pin
    P26 (PWM5) is the LED
    P11 (TXD1) is the Button
    P10 (RXD1) is the Wifi LED
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    Safely reassemble it all, and then don't forget to calibrate the BL0937.
    I did an unloaded Voltage measurement for VoltageSet, then hooked up my calibrated multimeter an measured the True RMS current with a large load (2kW heater), then ran CurrentSet. Note that this does not appear to automatically calculate Power properly, so you should use a resistive load (like a simple radiator heater with no fan), and note that if it is a large load, it will cause voltage in your house wiring to drop, and so it's important to measure the voltage and the current at the same time if possible, to calculate the power.
    On one of my units it did seem to calculate the correct power without a PowerSet command, however on 3 others it did not - I'm not sure why this is, but this may be because the one unit had already paired to Tuya previously, or this may be a red herring?

    I also noticed that (on OBK 1.15.241) relay state changes do not update over MQTT if wifi is not connected, for example, if the unit is unplugged while on, then plugged back in, it will not revert the HA state to off once it reconnects to wifi. This also means if you plug in the device and press the physical button to turn the relay on before wifi connects, that state is not reflected.

    Cool? Ranking DIY
    About Author
    jessemclachlan
    Level 2  
    Offline 
    jessemclachlan wrote 2 posts with rating 1. Been with us since 2022 year.
  • #2
    p.kaczmarek2
    Moderator Smart Home
    Hello, thank you for teardown. This is very informative.

    Regarding your concern - there is a flag 'broadcast self state on MQTT connect, which in older versions was not set by default. Maybe you just need to tick it?

    Regarding this:
    Quote:

    On one of my units it did seem to calculate the correct power without a PowerSet command, however on 3 others it did not - I'm not sure why this is, but this may be because the one unit had already paired to Tuya previously, or this may be a red herring?

    We are not using any calibration from Tuya so you just must have lucked out. Maybe the default calibration data was good enough for your power measurement?

    PS: This device has two relays and one button, right? Why don't you set second channel of Button to channel 1, so single click toggles first relay and double click toggles second relay?
  • #3
    jessemclachlan
    Level 2  
    Thanks, I will try the mqtt flag.

    Although there are 2 relays they can't be independently controlled and are both wired to the same pin on the module so they operate together. One relay switches the active wire and one switches the neutral wire for only one mains output - you would never want only one relay active.
  • #4
    p.kaczmarek2
    Moderator Smart Home
    Ah ok, so it explains everything. I assumed too quickly that there are two completely separate relays and overlooked photos.
    If they must work together, then everything is ok.
    By the way, it's the first time ever I see a device with two relays used together. All products so far were just disconnecting live wire and keeping neutral connected.
    So your device is good and very nice in terms of safety.
  • #5
    jaysmith
    Level 2  
    Good Afternoon,

    I was able to install firmware to one of these devices today using the cloud cutter method, everything seems to work fine. Thanks for the detailed teardown.
    I am new to this firmware, is there an option or command to get the button press's to publish to MQTT?

    When I press the button the relay toggles which is great but I would like the button press's to publish to MQTT so I can pick up these events and trigger automations in Home Assistant.

    I can see the button press's in the logs of the device but not on the MQTT server.

    Info:GEN:11 Button_OnInitialPressDown
    Info:GEN:11 key_short_press
    Info:GEN:11 Button_OnInitialPressDown
    Info:GEN:11 key_short_press
    Info:GEN:11 Button_OnInitialPressDown
    Info:GEN:11 key_double_press
    Info:GEN:11 Button_OnInitialPressDown
    Info:GEN:11 key_triple_press
    Info:GEN:11 Button_OnInitialPressDown
    Info:GEN:11 Button_OnLongPressHoldStart
    Info:GEN:11 Button_OnLongPressHold

    Thanks,
  • #6
    p.kaczmarek2
    Moderator Smart Home
    Hello, it's very easy to do this in OpenBeken! We have already a topic about that here:
    [OpenBeken] Push button actions multi press and hold down etc
    The sample code for autoexec.bat (from LittleFS from Web Application Tab) is here:
    https://www.elektroda.com/rtvforum/viewtopic.php?p=20367050#20367050
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    But to make it easier for you, I will give you an example here:
    
    // 23 is GPIO number
    addEventHandler OnDblClick 20 publish myBtnEvent click2
    addEventHandler OnClick 20 publish myBtnEvent click
    addEventHandler On3Click 20 publish myBtnEvent click3
    addEventHandler On4Click 20 publish myBtnEvent click4
    addEventHandler On4Click 20 publish myBtnEvent click4
    addEventHandler OnHoldStart 20 publish myBtnEvent holdStart
    addEventHandler OnHold 20 publish myBtnEvent holdRepeat
    addEventHandler OnPress 20 publish myBtnEvent press
    addEventHandler OnRelease 20 publish myBtnEvent release
    

    Remember to reboot after setting that.
    But if you just want to play around, use the console and set event there, in that case event handler will be forgotten with reboot.

    Please also consult our commands list here:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/commands.md
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    You can also use events to start a script with a button event and do things in the script.

    Remember, if you want to have button without "automatic" interactions, use Btn_ScriptOnly role instead of Btn.
  • #7
    jaysmith
    Level 2  
    Thanks for your quick reply, I was able to add the event handler rules and now I get MQTT messages, I will read though the links you posted when I get home and try work out the best way to get those events into home assistant.

    Thanks again.
  • #8
    fokcuk
    Level 5  
    I tried to flash it but cloudcutter failed to connect to it. What am I doing wrong?


    Wiping NetworkManager configs
    Scanning for open Tuya SmartLife AP
    ...
    Found access point name: "GRID-CD05", trying to connect...
    Error: No network with SSID 'GRID-CD05' found.
    Error: GRID-CD05 - no such connection profile.
    Wiping NetworkManager configs
    ....
    Found access point name: "GRID-CD05", trying to connect...
    Error: No network with SSID 'GRID-CD05' found.
    Error: GRID-CD05 - no such connection profile.
    Wiping NetworkManager configs
    ...
    Found access point name: "GRID-CD05", trying to connect...
    Error: No network with SSID 'GRID-CD05' found.
    Error: GRID-CD05 - no such connection profile.
    Wiping NetworkManager configs
  • #9
    tonyb62
    Level 6  
    Do you get any access point errors when first starting the cloudcutter script?

    I personally ended up have to use and wi-pi usb wifi adapter after trying multiple other devices with internal wifi adapters.
  • #10
    fokcuk
    Level 5  
    eventually it worked, but I am trying now to find esphome code for it =)
  • #12
    fokcuk
    Level 5  
    OK... I have ventured into the world I dont yet understand =(
    I thought it was an easy update =( Created a bin file with ESPHome, it all went well and works without any GPIO pin definitions.
    But as soon I start defining them in ESPHome, I get compilation errors like these:
    src/main.cpp: In function 'void setup()':
    src/main.cpp:279:47: error: 'PIN_FUNCTION_P14' was not declared in this scope; did you mean 'PIN_FUNCTION_P10'?
    279 | libretuya_arduinointernalgpiopin_2->set_pin(PIN_FUNCTION_P14);
    | ^~~~~~~~~~~~~~~~
    | PIN_FUNCTION_P10
    src/main.cpp:330:47: error: 'PIN_FUNCTION_P13' was not declared in this scope; did you mean 'PIN_FUNCTION_P10'?
    330 | libretuya_arduinointernalgpiopin_3->set_pin(PIN_FUNCTION_P13);
    | ^~~~~~~~~~~~~~~~
    | PIN_FUNCTION_P10
    src/main.cpp:405:47: error: 'PIN_FUNCTION_P12' was not declared in this scope; did you mean 'PIN_FUNCTION_P10'?
    405 | libretuya_arduinointernalgpiopin_4->set_pin(PIN_FUNCTION_P12);
    | ^~~~~~~~~~~~~~~~
    | PIN_FUNCTION_P10
    src/main.cpp:410:47: error: 'PIN_FUNCTION_P4' was not declared in this scope; did you mean 'PIN_FUNCTION_P24'?
    410 | libretuya_arduinointernalgpiopin_5->set_pin(PIN_FUNCTION_P4);
    | ^~~~~~~~~~~~~~~
    | PIN_FUNCTION_P24
    src/main.cpp:415:47: error: 'PIN_FUNCTION_P5' was not declared in this scope; did you mean 'PIN_FUNCTION_P0'?
    415 | libretuya_arduinointernalgpiopin_6->set_pin(PIN_FUNCTION_P5);
    | ^~~~~~~~~~~~~~~
    | PIN_FUNCTION_P0


    Maybe its not ESPHome compatible...
    But how do I flash (OTA) a different firmware file that can work? MQTT would be good if I cannot get ESPHome going
  • #13
    p.kaczmarek2
    Moderator Smart Home
    Sorry I don't know anything about that firmware. As I said, we're using OpenBeken with online builds here.

    You just go to Releases tab, and get binary, and done. No problems, no compiling, more time for fun.

    Get UG file here:
    https://github.com/openshwprojects/OpenBK7231T_App/releases

    Visit our repository here:
    https://github.com/openshwprojects/OpenBK7231T_App

    Visit our youtube channel here:
    https://www.youtube.com/@elektrodacom
  • #14
    fokcuk
    Level 5  
    thanks. Learning as I go...
    If I dont get any readings from the BL0937, does it mean the pins are incorrect?
  • #15
    p.kaczmarek2
    Moderator Smart Home
    Well, it depends... you should have set the pins and restarted the device, and BL0937 driver should be running.

    If you still have no data, then indeed, it might be caused by wrong pins selection.

    Tuya changes device internals often, sometimes they even swap BL0937 to BL0942, etc.. that's why opening device can be useful.

    We also have some templates here:
    https://openbekeniot.github.io/webapp/devicesList.html
  • #16
    fokcuk
    Level 5  
    Are there any UF2 firmware files I can use? Or can someone recommend a method of converting release files to UF2?[/tiktok]
  • #17
    wolfieeewolf
    Level 7  
    Have any of you had issues with getting this device to update to the latest firmware?

    I've had no luck getting it to update since the initial install.

    Just wanted to see if it's something on my end or if it's a systemic problem with the device.

    I have 5 of them now and none of them will update.

    I have marked it as an issue on the Github page but it appears my only option is to open the device and flash it manually which I'm reluctant to do as it looks like it will cause issues down the track with trying to seal it back up again to the same standard. I feel I'd go to pull the plug out of the wall and the whole device would come apart.
  • #18
    p.kaczmarek2
    Moderator Smart Home
    We've seen your report and tried reproducing your problems and haven't managed to get the same error.

    One thing you may try, albeit it's a bit risky, is to first download RF partition backup and then use "Restore RF" button:
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    Make sure to download RF backup first. There is no "Write old RF backup" option yet, but I may add one soon. Then reboot and check if device works and if OTA works.

    Even if it won't help, you want to open the device anyway, so I hope it won't be the problem if it just decreases WiFi quality. But as I said, use this tip at your own risk.

    Maybe also first try.... do PowerSave 1 and then OTA?
  • #19
    wolfieeewolf
    Level 7  
    Sadly none of those options worked.

    After reading the teardown information I don't think I'll be opening up the device.

    The firmware works for now so I'll leave it as that.
  • #20
    MnM1
    Level 2  
    For my devices I apply the updates via OTA (in the app).

    Update seems to be OK but after the reboot the old version is shown.

    I have to physically take out the smart plug from the wall socket while pressing the button. Wait about 5 seconds and plug it back (and this whole time keep the button pressed) and release the button just after is plugged back in the wall socket. It will show that is running the new firmware after this process.

    Not ideal with many devices, but I guess if a new firmware is really required then there is an option.

    Hopefully there will be fix (without opening the case - as the firmware is updating but only following the process above) so we can use other way to bulk update the devices (TasmoAdmin).

    Cheers.

    Edit - forgot to mention that a couple of times (maybe I updated one device about 20 times with newer firmware) the new firmware just worked after the OTA update (didn't have to do anything just wait for the reboot and it showed the new firmware). No idea why...
  • #21
    p.kaczmarek2
    Moderator Smart Home
    This is totally new to me and I have quite a few devices. @MnM1 do you have the same plug model as @wolfieeewolf ?

    Are you saying that.... you have to disconnect power for OTA to finish? This is very strange. Does it happen only for plugs, or also for LEDs?

    Here's my LSPA9, one of few, it updates well without any further actions:
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
  • #22
    MnM1
    Level 2  
    Yes I have a few of the Arlec Grid Connect PC191 Smart Plug-In Socket with Energy Meter - like 10 or so of them.

    They all behave the same.

    I update them via the the app:

    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    The below is an updated device - it was updated to 1.17.98 but it still shows the old firmware as I didnt go through the process yet.

    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown

    Added after 1 [minutes]:

    And this is after I followed my process:

    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
  • #23
    p.kaczmarek2
    Moderator Smart Home
    So the problem occurs on that one particular device?
  • #24
    tonyb62
    Level 6  
    Appears these devices have been updated.

    I recently bought a new 4 pack of these sockets from Bunnings and quickly found that flashing these devices with cloudcutter didn't work.
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    Note the fine print
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    Opening the device shows a CB2S
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    Again note the fine print
    Arlec Grid Connect PC191HA Plug-In Socket with Energy Meter Teardown
    Was able to connect to the CB2S without removing from the board and program using the Openbeken apt (BK7231N) and functional with the follow config

    Code: json
    Log in, to see the code

    Going to try cloudcutter again now that i know what is inside.
  • #25
    MnM1
    Level 2  
    Here is a step by step:

    1. Go to app
    2. Download the latest firmware
    3. Apply the latest firmware
    4. Wait for device to reboot
    5. Press the button on the device and keep it pressed
    6. Pull the device out from the wall power socket while keeping the button pressed
    7. Wait 5 seconds and keep the button pressed
    8. Plug the device back into wall power socket and release the button
    9. Wait for device to boot and see the new firmware

    Added after 1 [minutes]:

    p.kaczmarek2 wrote:
    So the problem occurs on that one particular device?


    All my Arlec Grid Connect PC191 (10 or so of them) behave the same.

    Added after 3 [minutes]:

    tonyb62 wrote:
    Going to try cloudcutter again now that i know what is inside.


    Let us know if it works and if it did the steps and options you had to select in cloud-cutter

    Added after 5 [minutes]:

    Just updated that device to 1.17.104 - had to go through the process to show that the device is running the new firmware.
    The strange part is that out of the many firmware I updated this device to, a couple of times it just worked without having to go through the above process.
  • #26
    tonyb62
    Level 6  
    @MnM1 I could recreate the same issue with flashing the devices, but mine (4total) where all different. Some would update fine others would require a "reset" as you montioned. Some would update fine if i turned the outlet off first.
    It appears the chip doesn't restart cleanly and hangs onto the old firmware, but will restart with the new firmware after a power cycle.

    For the newer model PC191HA Series 2, I was able to OTA flash them using cloudcutter using the following steps.
    Grid connect app reports its running the v1.1.8 firmware.
    To flash the BK7231N with latest firmware 1.17.104
    - Choose the device by firmware version - 1.1.8 - BK7231N / oem_bk7231n_plug
    - Select brand - Tuya Generic
    - Select device LSPA9 Plug v1.1.8

    Then loaded the config as posted previously.
  • #27
    wolfieeewolf
    Level 7  
    Thank goodness it was not just me having issues. I was going crazy thinking I did something wrong when I flashed the device.

    I have the series 1 version of the PC191HA. Holding down the button and power cycling the devices has updated them to the latest firmware. I was power cycling the device but there must be something about holding the button that puts It into a reset mode or wipes the old flash or something.

    I did notice it took a long time to reboot when you hold the button down compared to the very quick restart when you just update its OTA. Maybe that has something to do with why it doesn't update. Could be that holding the button down discharges whatever power is still stored on the device which then eventually cold boots the flash. Very strange behaviour whatever it is.
  • #28
    tonyb62
    Level 6  
    Ive noticed the different boot times too.

    Ive also noted on the updated sockets, that the button is connected to the RX1 pin on the CB2S.

    Ive not pulled the original model apart to see what its connected too.
  • #29
    MnM1
    Level 2  
    Yeah it is strange how these PC191HA v1 behaves.
    Hopefully is an issue that can be fixed. Would love to be able to use TasmoAdmin and upgrade all (after testing the new firmware on a device first of course)
  • #30
    tonyb62
    Level 6  
    I was thinking about it and wonder if the reboot is attached in some way to Flag37 - Quick connect to WiFi on reboot.
    Disabling this flag changes the reboot time to similar to your restart procedure.

    Is there something that is kept alive that retains old settings? with this flag enabled that prevents a firmware update from completing or being loaded?