Elektroda.com
Elektroda.com
X

Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

p.kaczmarek2 27654 169
This content has been translated flag-pl » flag-en View the original version here.
  • Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Hello. I would like to present here a short teardown and OpenBeken configuration guide for LSPA9 power measurement socket. LSPA9 comes in various versions, but in this case it's based on CB2S (BK7231N) module and BL0942 energy metering chip with UART interface. I will show here step by step how to flash OpenBeken to LSPA9 and I will also explain step by step how the communication with BL0942 works. The BL0942 protocol section of this article will be dedicated to programmers and people who want to dig deeper into technical details, and can be skipped if you want to just flash OpenBeken and get readouts in Home Assistant.

    Related Topics
    General topics about my firmware for BK7231:
    [BK7231T] My HTTP server, configurator, MQTT support from Home Assistant
    WB2S/BK7231 Tutorial - writing custom firmware - UDP/TCP/HTTP/MQTT
    Topics about uploading OpenBK to other products:
    LED WiFi RGBCW Tuya - teardown, BK7231N, programming with my Tasmota replacement
    Garden Tuya CCWFIO232PK Double Relay - BK7231T - Programming
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    My firmware repository:
    https://github.com/openshwprojects/OpenBK7231T_App

    Purchase of the LSPA9 EU socket
    You can find the socket by searching for something like LSPA9 EU Smart Plug WiFi Smart Outlet Socket Voice Control Works for Alexa , I paid about $17 ($14 product + VAT tax and shipping):
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    The socket works normally with the Tuya application, but I have already tested it in other topics in this section:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    This time there was no shipment from the Czech Republic and the transport took a really long time. More than a month, I guess. Fortunately, no additional payments were required.
    The package was sent like from Wiazowna (FASTPRO), but it is obviously just a reshipper.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    There is only a sticker with the product model (LSPA9) on the package, otherwise it would not be known what socket model it is:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    The set includes a socket and instructions:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942


    The teardown of the LSPA9 EU
    I skipped any tests with the manufacturer's application. This has already been discussed in other topics.
    It is hard to get inside, I broke the casing a bit.
    Need to pry from the top edge:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    The CB2S module emerges:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    CB2S - a WiFi module based on BK7231N. Already supported by OpenB7231N.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    In addition, you can see the energy measurement chip - BL0942, nearby there is a LDO 3.3V AMS1117-3.3 (because the power supply supply provides 12V to control the relay, and the WiFi module requires 3.3V), J3Y transistors (to switch the relay on):
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    And here is the power supply itself (transformerless!) Is based on the BP2525. This is not the first time I encounter this chip in a smart device.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    This big resistor is probably a fusible resistor. I can't see any more protection circuitry here. No varistor?
    The relay is on the bottom side of the PCB:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    A brief analysis of the PCB with the multilimeter already tells us what is going on here.
    This is a standard smart socket, with BL0942 connected via UART to the CB2S. BL0942 also offers SPI mode, but it is not used here. It's a pity, because the same UART port from CB2S is used for firmware update - will there be a problem with that?
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942


    Uploading your own firmware - OpenBK7231N - part 1
    Same as in the previous topics in the series:
    LED WiFi RGBCW Tuya - teardown, BK7231N, programming with my Tasmota replacement
    Garden Tuya CCWFIO232PK Double Relay - BK7231T - Programming
    Qiachip Smart Switch - BK7231N / CB2S - interior, programming
    Soldering cables to RX / TX and CEN (aka RESET):
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Soldering the cables before the LDO (so that 5V from USB is given at the AMS1117 input):
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    But at this stage I stopped, because first I wanted to see the CB2S communication with BL0942 with my UART converter.


    Communication with BL0942
    Datasheet of BL0942 shows that baud rate 4200 is used.
    Let's see what UART packets I was able to intercept.
    Sent by CB2S:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Sent by BL0942:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    So the host sends two bytes, always the same (even without CRC?), In the form of a request for measurements and BL0942 responds with the measurement results.
    I think of the header 0x55 as TuyaMCU, but it's not the TuyaMCU protocol.
    One might guess its content here, but we do have a catalog note.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    The annotation {0,1,0,1,1,0, A2, A1} proves that the system supports the connection of several sensors (four, that many addresses are allowed by two address bits) to one UART bus. The way this works is that all four devices listen for the call, and only the one whose address is in that call responds to it.
    There is a single chip in our socket, however, so no problem.
    The measurement results in the packet are broken down into separate bytes. Each of them is a three-byte number. Among others, RMS values, frequency, power.
    There is also a one-byte checksum, used to detect possible transmission errors. The checksum is calculated from the remaining bytes of the packet, its value is placed at the end of the packet when it is sent. If, upon receipt, we count the value of the checksum and it is different than the one placed at the end of the packet by the sender, we know that the content of such packet has changed (disturbed) and should be discarded.
    In order to verify the formula for the checksum, I wrote a program:
    Code: c
    Log in, to see the code

    Running it on Windows allowed me to quickly verify that the calculations are performed correctly.
    I did the rest of the implementation in my OpenBK:
    https://github.com/openshwprojects/OpenBK7231T_App/
    I have already prepared a UART system with a receiving circular buffer which discussed here (PL only so far) .
    Sending a measurement request is simple:
    Code: c
    Log in, to see the code

    It works very much like a simpler version TuyaMCU. I regularly check that the number of bytes in the circular buffer is not less than the length of the expected packet. Additionally, I know that the packet header is always 0x55, so when there is the first other byte, I skip it.
    Code: c
    Log in, to see the code

    Then I know that the whole packet has been received, so I check its checksum.
    Code: c
    Log in, to see the code

    If the checksum is not correct then the packet is discarded - UART_ConsumeBytes (BL0942_PACKET_LEN) .
    Now it's time to get the measurements out of it. We need to combine separate bytes into a four byte integer (there are three bytes here, but on this platform the integer is 4 bytes). NOTE: the obtained number will still have to be processed, more on that later.
    Code: c
    Log in, to see the code

    Operator << is a bitwise shift and | is a logical sum.
    That will result in an integer like 3569180, which is far from 230V (the voltage we have in Poland at mains).
    This integer will have to be divided by a certain constant, which is also used for the calibration.
    This constant is calibrated at production time by Tuya, but sadly, when flashing new firmware we have no access to calibration data.
    We will have to figure out that constant itself in order to calibrate socket.
    How to get that constant?
    Well, this is very simple - just measure the voltage with a reliable voltage meter and then take raw_unscaled_voltage sent by plug and divide it by measured voltage.
    For me, the constants turned out to be:
    Code: c
    Log in, to see the code

    And finally, this is how you get result voltage, power and current measurements (in V, A and W).
    Code: c
    Log in, to see the code


    How the calibration API is implemented in OpenBK
    Of course no one wants to do calibration by hand. That's why I prepared a handy set of functions that will do everything for users. User only inputs the measured value (real voltage, current and power) and the function calculates the calibration constant - BL0942_PREF, BL0942_UREF, BL0942_IREF.
    Code: c
    Log in, to see the code

    The same approach is used for voltage and power.


    Flashing the firmware by UART - OpenBK7231N - part2
    At first I decided to desolder the BL0942, but do not worry - it turned out to be not necessary. I will just leave the photos here for the reference.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    By the way, the Tuya firmware noticed the BL0942 missing right of the bat.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    And here is my flashing setup:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Flashing:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    For rebooting the chip, I used the CEN method. It is tricky because you have to connect to CEN to ground for a very short while. That sometimes confuses beginners.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Then I soldered BL0942 and checked flashing again - it still worked. Most likely the baud rate difference and/or the specific packet expected by BL0942 to send reply was enough to ensure that it will stay silent during flashing.
    All next software updates were made by OTA (remotely by WiFi), which is already supported by my firwmare for BK7231N and BK7321T.
    Of course then you have to setup WiFi SSID, passphrase, etc, but I assume you already know how to do that (if not, see other OpenBeken topics from the series).
    Pin roles:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942


    So how to calibrate BL0942 in OpenBeken?
    This section is for all users. You must do that. Otherwise you will get unreliable measurements!
    The calibration is very much like in Tasmota, even the command names are the same.
    At this point, I assume you already have OpenBeken flashed.
    First, run the BL0942 driver. Command:
    
    startDriver BL0942
    

    Remember that you can enter commands at the Javascript frontend app of OpenBeken:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    After that, the main page should start showing measurements:
    Measurements with no load, before calibration:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    That voltage value is way too high! This is not acceptable. We need to calibrate.
    The measurements of 60W bulb without calibration:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Again, those are wrong.
    So, let's calibrate. Take a reliable power meter and measure how much in reality current and power the bulb consumes. Also write down the voltage in the socket. You will need that values later.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Now, move the plug to the OpenBeken socket and enable it (OpenBeken must be measuring the very same bulb when you do the calibration, the bulb must be on!).
    Now, in the command line, type commends: VoltageSet [correntVoltageVal], CurrentSet [correntCurrentVal] i PowerSet [correntPowerVal], and write down the system replies (the correct calibration constants for your very device)
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    System replies:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    So, write down that VREF = 15987.125000
    PREF = -683.023987
    IREF = 272302.687500
    Refresh the page:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    You can also recheck with resistor load:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Resistive load is good for doing double-check because you can easily calculate power for that (the cos phi is 1 while for inductive/capacitive load it is not).
    2023 UPDATE - THOSE VALUES ARE NOW AUTOMATICALLY SAVED, NO AUTOEXEC.CFG NEEDED. Just use VotlageSet, etc, and it will be remembered by device, saved in flash, kept after reboot.
    Anyway, without delving too much into theory, it's time to prepare the config commands set with the calculated calibration constants:
    
    startDriver BL0942
    VREF 15987.125000
    PREF -683.023987
    IREF 272302.687500
    

    Those commands are required to initialize BL0942 driver and set the calibration.
    Of course, it would be tedious to type them by hand on each device reboot.
    That is why we have a LittleFS file system and "autoexec.bat" system in OpenBK.
    So, on your PC, create a file called autoexec.bat and enter those commands.
    Then, take that file and drag over the file creation button on OpenBeken Web App Panel:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    This is how you save the file on LittleFS system of OpenBK.
    Then you can also use buttons to list the files, view them, etc.
    WARNING: Any OTA update will wipe the commands. This is because they occupy the same region as OTA. Always backup your autoexec.bat on your local machine.
    NOTE: The is also a short alternative to LittleFS autoexec.bat. You can use the "short startup command" field configured in options. Remember to enter commands there with "backlog" notation, like that:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    Also note that both autoexec.bat and short startup commands are not executed in "safe mode", i.e. when device fails to fully boot and run for a 30 seconds after booting for several times. The same method can be used to reset device - just power on and power off it three times and never let it run for more than 30 seconds. In safe mode, the device returns to Open Access Point mode and ignores its config (IO pins are disabled, etc).


    Configuration YAML foor Home Assistant
    Now it's time to send our measurement results to Home Assistant by MQTT.
    First, the MQTT needs to be configured in Config->MQTT, just like with any other device.
    Then, peek to Config->Generate Home Assistant Config to get short device name, something like obk0696FB33.
    You can also copy the configuration from there, but it will work only for relay mode.
    Extra manual configuration is required for power metering.
    Here is an example:
    
    sensor:
      - platform: mqtt
        name: "BL0942 Voltage"
        state_topic: "obk0696FB33/voltage/get"
        unit_of_measurement: "V"
      - platform: mqtt
        name: "BL0942 Current"
        state_topic: "obk0696FB33/current/get"
        unit_of_measurement: "A"
      - platform: mqtt
        name: "BL0942 Power"
        state_topic: "obk0696FB33/power/get"
        unit_of_measurement: "W"
     

    Replace my device short name with your device names.
    After changing configuration.yaml, restart the Home Assistant. Then you should already get measurement results visible on HA charts:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Let's play around a bit. This is power consumption by my notebook in normal power mode:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Will "Power saving mode" from Windows change power consumption?
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    As you can see, not much. What about "High performance" mode?
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Some more measurements, after a certain time:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Voltage:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    I have rechecked it with my Brymen BM857s and indeed, the voltage has changed over time.

    Summary
    This is how you pair Beken power metering socket with Home Assistant without replacing WB2S/CB2S chip. In future it might be even eaesier, because it might be also possible to flash the LSPA9 remotely with tuya-cloudcutter without even opening the case. The only issue would be that LSPA9 is made in different versions (CB2S + BL0942 or WB2S + BL0937), so it might be hard to determine which version is your socket.
    Still, I think the results are worth the effort. My LSPA9 is cloud-free now!
    Do not even try to skip the calibration step - the measurements are way off without it.
    Also, remember to save your BL0942 init and calibration constant setting commands in LittleFS or startup command - otherwise the BL0942 will forget calibration with next reboot!
    Do you like my work?
    Please support me at:
    https://www.paypal.com/paypalme/openshwprojects
    I really need to get more test devices and I plan to support BL0937 and other chips as well soon, so it's crucial to get funds.
    Also feel free to register here on Elektroda, I will do my best to help you setup OpenBeken.
    PS: I already have BL0937 socket donated to me by other user, so the work is already in progress!

    Cool? Ranking DIY
    About Author
    p.kaczmarek2
    Moderator Smart Home
    Offline 
    p.kaczmarek2 wrote 4859 posts with rating 5193, helped 236 times. Been with us since 2014 year.
  • #2
    khoam
    Level 42  
    p.kaczmarek2 wrote:
    Any OTA clears the filesystem - that's because the filesystem uses the same flash section as the OTA.

    I don't understand that. There are one or two partitions in flash for the OTA in ESP. For example, LittleFS can be placed in separate partitions. Updating after OTA has no right to destroy data stored in file systems.
  • #3
    p.kaczmarek2
    Moderator Smart Home
    LittleFS happens to be a contribution from one of the Github users, but the general idea is that we save Flash as much as we can. This allows us to have more than 512KB of file space and if someone wanted to, he could put html files or js there (they are not yet connected to the server, but it could).

    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/src/littlefs/our_lfs.c
  • #4
    karolc1996
    Level 12  
    A very nice solution ;)
  • #5
    p.kaczmarek2
    Moderator Smart Home
    A small update (I also put it in the first post).

    OpenBeken also supports "short startup command line", to be set in the options, that is, a field of 512 bytes for commands that are executed at startup. This OTA does not overwrite this. There, too, you can set the configuration of BL0942 and other things. There is a "backlog" to send multiple commands as in Tasmota.

    For example, for a socket from topic:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    I know that this is a weaker solution, but the main structure of the configuration does not take up much and on the sectors where I put it (and on Xr809 and on the beken) there is just space for 512 bytes additional.

    In addition, I optimized the code from the repository and now I only send an update after MQTT if the measurement changes by a given (target) value by the user. For example, it makes no sense to send updates every 2 seconds when the voltage changes by 0.1V ...
  • #6
    error105
    Level 14  
    p.kaczmarek2 wrote:
    In turn, the power supply itself (transformerless!) Is based on the BP2525. This is not the first time I encounter this chip in a smart device.

    Hey, do you know where to get these chips from us in the country?
    Or are there other ones to build a transformerless power supply that gives 3.3V?
  • #7
    p.kaczmarek2
    Moderator Smart Home
    Unfortunately, I was not even more interested in it, and I can see that Alie now has 10 BP2525 for PLN 50, which in my opinion is a very high price.
    I only have to point out - BP2525 does not give 3.3V there and I have not seen such a structure in IoT devices. There, first the power supply gives 5V or 12V, and then additionally there is AMS1117-3.3V or an equivalent.
  • #8
    khoam
    Level 42  
    p.kaczmarek2 wrote:
    Thanks to this, we can have more than 512KB of file space and if someone wanted, he could put html files or js there (they are not yet connected to the server, but he could).

    It follows that the user will have to restore the contents of the file system after an OTA update every time.

    Besides, you could consider sending only compressed delta of the new program version via OTA. An example of such a project for ESP32: Link
  • #9
    jony4t
    Level 5  
    @p.kaczmarek2 have you managed to configure BL0937.Thanks
  • #10
    p.kaczmarek2
    Moderator Smart Home
    Basic BL0937 implementation is working already, altough I will be improving it in the future.

    For BL0937 configuration, please set appropriate pins in the pins config. The driver should start automatically.

    For calibration, follow the BL0942 steps, the commands are the same.

    Remember that your pinout might be different.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
  • #11
    jony4t
    Level 5  
    Hi. for my wifi plug this is the configuration. thanks for your help. Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    p.kaczmarek2 wrote:
    Basic BL0937 implementation is working already, altough I will be improving it in the future.

    For BL0937 configuration, please set appropriate pins in the pins config. The driver should start automatically.

    For calibration, follow the BL0942 steps, the commands are the same.

    Remember that your pinout might be different.
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
  • #12
    p.kaczmarek2
    Moderator Smart Home
    Thank you, can you just tell us which exact plug model you have (name + photos) so other users can benefit from your config? Thanks.
  • #13
    skylineh44
    Level 4  
    Just thought I'd share my device details of an Australian single plug with power monitoring. The make/model is Brilliant Smart/20925 Series II
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 [img-1] Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    I've been replacing a bunch of newer devices with ESP based chips but came upon this project and decided to have a go. A fairly steep learning curve but I made it and now have the plug (with power monitoring) working in Home Assistant.

    The config is:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    I de-soldered the chip to program it and also to accurately trace to ensure which pins the BL0937 chip was connected to. It took a while and I cocked up my mirroring/tracing which too a couple of hours to untangle. Whoda thunk it would take so long to trace 3 lines - maybe because it was past midnight!! :not:

    After that I had difficulty setting the calibrations for the BL0937, I tried to use the "VoltageSet" command in the web interface but it did not work. It did work in the /app interface though.

    Anyway it's working so I'll say thanks to all who have contributed and all hail :please: to their computing prowess
  • #14
    jony4t
    Level 5  
    Has anyone had the problem with this type of socket with CB2S with BL0937 The socket stops working after 2-3 hours. In home assistant it says "stopped working". I try to search for the plug in the internal network and it does not appear either. I have to restart every time.. Thanks for your help.
  • #16
    TheAussieMaker
    Level 1  
    skylineh44 wrote:
    Just thought I'd share my device details of an Australian single plug with power monitoring. The make/model is Brilliant Smart/20925 Series II
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 [img-1] Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    I've been replacing a bunch of newer devices with ESP based chips but came upon this project and decided to have a go. A fairly steep learning curve but I made it and now have the plug (with power monitoring) working in Home Assistant.

    The config is:
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    I de-soldered the chip to program it and also to accurately trace to ensure which pins the BL0937 chip was connected to. It took a while and I cocked up my mirroring/tracing which too a couple of hours to untangle. Whoda thunk it would take so long to trace 3 lines - maybe because it was past midnight!! :not:

    After that I had difficulty setting the calibrations for the BL0937, I tried to use the "VoltageSet" command in the web interface but it did not work. It did work in the /app interface though.

    Anyway it's working so I'll say thanks to all who have contributed and all hail :please: to their computing prowess


    Arlec Grid Connect Smart Plug (PC191HA)

    Chip = WB2S
    Power Chip = BL0937

    Work well also, had to remove the WB2S to flash as the button is attached to the RX line.

    These work out cheaper in the 4 pack @ $65.00 and the button is better located on the top

    https://www.bunnings.com.au/arlec-grid-connec...g-in-socket-with-energy-meter-4-pack_p0273368

    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
  • #18
    maximoei
    Level 1  
    This project and thread are great! Thanks @p.kaczmarek2 !

    Adding some learnings on my version on the Tuya Elivco LSPA9 - As I had a bit of a different experience:
    1. Had to fully desolder the CB2S to be able to flash
    2. My LSPA9 is based on BL0937 instead of BL0942
    3. Pinout is different than most seen so far:
    - P6 - BL0937 CF1
    - P7 - BL0937 CF
    - P10 - Btn 1
    - P24 - BL0937 SEL
    - P26 - Rel 1

    Hope that's useful for someone else :) - I have provided a PR into the device database
  • #19
    p.kaczmarek2
    Moderator Smart Home
    I am happy that I helped.

    IMPORTANT UPDATE
    The new builds are automatically saving calibration data, so you don't have to put "VRef 123" etc etc in short startup command. Everything is saved automatically. Just calibrate once and forget. Data will remain after reboot.
  • #20
    nkuehnel86
    Level 3  
    @p.kaczmarek2 Thank you so much for this tutorial / guide. As well as for this hole project and contribution.
    I managed to flash a Aubess device based on several different tutorial and some Youtube videos with the "OpenBK7231N_QIO_1.14.119.bin".
    I couldn't find this device in your database (or I was to stupid) so I had to trial and error with a bit of measuring.
    The Device is called "AUBESS Tuya WiFi MiNi Smart Switch With Energy Monitor 16A 2-way control Timer Wireless Switch"
    So it has the BK7231N MCU (CB2S) and a BL0942 as energy meter IC.
    I figured out the on board LED is on Pin 8, the ToggleChangeOnToggle Pin is on 24 (that's my guess) and the relay is on PIN 26.
    I couldn't the test ToggleChangeOnToggle at PIN 24, I assumed it because "S2" (see picture) is at PIN 24.
    I was not (yet) able to find the Button PIN and S1.

    I had a bit trouble with calibrating. When I set "VoltageSet 225" or "CurrentSet 0.138" it happend to me that the device wasn't anymore reachable and disconnect itself from my WiFi. My guess is some trouble with parsing the command in the backend.
    So I tried a couple of times and it appeared to me the feedback "Command not found", but eventually it worked.

    I'm using ioBroker instead of Hass, but surprisingly it worked somehow with the Hass MQTT structure , except I hat to manually add a "set" datapoint in ioB MQTT Object-Path for the relay.

    So I hope this will help someone else. I'm looking forward to figure out the Button PIN and S1 PIN.


    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942 Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942



    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
  • #21
    DerThomas
    Level 2  
    @nkuehnel86 Thank you for your investigations concerning the Aubess Power Monitor Switch module!
    If you add the pin mapping 'Pin 23 -> Btn -> 1' you can also toggle the outlet via the on device button. Can you add this to the device template as well or does it need and admin to do it?

    I'm still unable to calibrate the power meter. I tried with OpenBK7231N_1.15.22 and OpenBK7231N_1.15.30 firmware. If I send 'VoltageSet 234, CurrentSet 0.266, PowerSet 62.8' or any of the individual commands it does not crash but it responds with 'Command not found'. Have you had any success with the power calibration jet?

    A more general question you or other may have a hint for me:
    Is there any way to change the S1/S2 switch behavior to work wit momentary switches?
    On tasmota devices I would need to execute the following command to achieve this behavior
    Backlog0 Interlock 0; SwitchMode 3
  • #22
    p.kaczmarek2
    Moderator Smart Home
    DerThomas wrote:

    I'm still unable to calibrate the power meter. I tried with OpenBK7231N_1.15.22 and OpenBK7231N_1.15.30 firmware. If I send 'VoltageSet 234, CurrentSet 0.266, PowerSet 62.8' or any of the individual commands it does not crash but it responds with 'Command not found'. Have you had any success with the power calibration jet?

    Have you started the driver? Is it BL0937 or BL0942?



    DerThomas wrote:

    Is there any way to change the S1/S2 switch behavior to work wit momentary switches?
    On tasmota devices I would need to execute the following command to achieve this behavior
    Backlog0 Interlock 0; SwitchMode 3

    We have a "Button" pin role and a "TglChannelOnTgl" role, which is a "button"/"switch" which toggles target channel when pressed.
  • #23
    DerThomas
    Level 2  
    @p.kaczmarek2 Thank you for your high speed rely!
    p.kaczmarek2 wrote:
    Have you started the driver? Is it BL0937 or BL0942?

    My Startup command is set to:
    startDriver BL0942
    This information i took from the post here from @nkuehnel86
    Do I need to change it?

    p.kaczmarek2 wrote:
    We have a "Button" pin role and a "TglChannelOnTgl" role, which is a "button"/"switch" which toggles target channel when pressed.

    This is an amazing information which solved my momentary switch setup problem. Thank you a lot!

    Is there a way to change the MQTT topic to something like this?:
    OpenBK7231/Aubess-Power-Monitor-Switch/Test1
    I have telegraf scripts which import the energy data into my InfluxDB and they grep template variables from the topic structure.

    Is there a way to protect the OpenBK7231T_App UI with a password? The App shows critical clear text passwords.

    Is there an option to set the MQTT update interval for updated energy readings to achieve more precise energy recordings in my InfluxDB? In mosquito this is set in Configuration → Configure
    Logging → Telemetry period
    Based on precise energy patterns I can write rules in OpenHAB which tell me (as an example) in which exact state my washing machine or dishwasher is.
  • #24
    nkuehnel86
    Level 3  
    Sorry for replying late, I wasn't online for the last few days.

    DerThomas wrote:
    @p.kaczmarek2 Thank you for your high speed rely!
    p.kaczmarek2 wrote:
    Have you started the driver? Is it BL0937 or BL0942?

    My Startup command is set to:
    startDriver BL0942
    This information i took from the post here from @nkuehnel86
    Do I need to change it?


    No as far as I understood the idea of OpenBeken, the Startup command is the right way to go. After flashing you should write this command in the command line, where you are wrote the calibration commands. The startup command therefor is just to execute this after a reboot.

    So after flashing, write "startDriver BL0942" in the command line, measure voltage, and current of a reliable consumer (like a 60 W light bulb). The command line told me as well "Command not found" but it does worked. When you go back to the main page the voltage is around the value it supposed to be. Same as current and power. I performed a restart (power off) of the device after the calibration to see if it was saved, and so it was.

    The second device I have, I even didn't had to unsolider the small PCB, just the TX and RX, because of the BL0942.

    Quote:

    p.kaczmarek2 wrote:
    We have a "Button" pin role and a "TglChannelOnTgl" role, which is a "button"/"switch" which toggles target channel when pressed.

    This is an amazing information which solved my momentary switch setup problem. Thank you a lot!

    Have a closer look my configuration, the "TglChanOnTgl" already set to PIN 24. And thanks allot for the information of Btn1 on PIN23. I can't or better I don't know how to change it in the template.

    Quote:

    Is there a way to change the MQTT topic to something like this?:
    OpenBK7231/Aubess-Power-Monitor-Switch/Test1

    Your could change the device name. Since I'm using ioBroker, I use the MQTT Broker adapter and my device looks like this: Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    Quote:

    I have telegraf scripts which import the energy data into my InfluxDB and they grep template variables from the topic structure.

    I'm using telegraf and Influx as well, but in a different context, since I'm going with ioBroker. So not sure how to help here.

    Quote:

    Is there a way to protect the OpenBK7231T_App UI with a password? The App shows critical clear text passwords.

    I couldn't found this either. Maby I overlooked it or it is not (yet) a feature.

    Quote:

    Is there an option to set the MQTT update interval for updated energy readings to achieve more precise energy recordings in my InfluxDB? In mosquito this is set in Configuration → Configure
    Logging → Telemetry period
    Based on precise energy patterns I can write rules in OpenHAB which tell me (as an example) in which exact state my washing machine or dishwasher is.

    I guess than you have to bake your own firmware with the a repo fork of the project and write you own implementation. I couldn't find exact where, cause the project is quit large.

    I hope I could help you.
  • #25
    DerThomas
    Level 2  
    @nkuehnel86 Thank you for your very detailed response!

    nkuehnel86 wrote:
    So after flashing, write "startDriver BL0942" in the command line, measure voltage, and current of a reliable consumer (like a 60 W light bulb). The command line told me as well "Command not found" but it does worked. When you go back to the main page the voltage is around the value it supposed to be. Same as current and power. I performed a restart (power off) of the device after the calibration to see if it was saved, and so it was.

    So maybe my device is already calibrated and I do not know because I just had eyes for the "Command not found" message :-)
    OK tested it again and you are abolutely right - it is executing the calibration and only sending the wrong reply to the screen
    Because of this post of @p.kaczmarek2 I just expected a different message:
    p.kaczmarek2 wrote:
    Now, in the command line, type commends: VoltageSet [correntVoltageVal], CurrentSet [correntCurrentVal] i PowerSet [correntPowerVal], and write down the system replies (the correct calibration constants for your very device)


    nkuehnel86 wrote:
    Your could change the device name. Since I'm using ioBroker, I use the MQTT Broker adapter and my device looks like this:

    Yes I saw that but the device 'Full Name' is not allowed to contain slashes.

    nkuehnel86 wrote:
    Have a closer look my configuration, the "TglChanOnTgl" already set to PIN 24. And thanks allot for the information of Btn1 on PIN23. I can't or better I don't know how to change it in the template.

    Yes your configuration contains 'TglChanOnTgl' - which is perfectly right if you have a classical light switch connected to it. In my case all light switches in the house are push buttons and as I have learned I have to change it to 'btn' instead of 'TglChanOnTgl' here.
    @p.kaczmarek2 Can you change the template for this device and add support for the on-device push button by adding a 'pin 23' mapping to role 'btn' at channel '1'?

    nkuehnel86 wrote:
    I guess than you have to bake your own firmware with the a repo fork of the project and write you own implementation. I couldn't find exact where, cause the project is quit large.

    I worried that this might be the solution. Thank you for trying to find it in the code! I'll check the code as soon as spare time comes and hits me ;-)

    Thank you very much for your support!
  • #26
    omelchuk890
    Level 10  
    Greetings to all forum members.
    Has anyone come up with a way ...
    to open the socket housing with minimal aesthetic losses?
    I carried out six "operations" - there is no stability, the amount of glue and the length of the filling are different in each case.
  • #27
    omelchuk890
    Level 10  
    Done, nothing happens.
    Where am I doing wrong or misunderstanding something?
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942

    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942
  • #28
    p.kaczmarek2
    Moderator Smart Home
    Some sockets are easier to disassemble than the others. Maybe you can try to choose wisely at the buying stage. Apart from that, you could use the tuya-cloudcutter, but it may not support certain sockets yet.

    Hmm if you want command to execute right now, please use the commands console in secondary (javascript) panel. The short startup command is only ran at startup. Futhermore, where are the command arguments?

    Our docs has them specified...
    Tuya LSPA9 smart socket - teardown, OpenBeken flashing guide for CB2S, BL0942