logo elektroda
logo elektroda
X
logo elektroda

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

p.kaczmarek2 90537 372
ADVERTISEMENT
Treść została przetłumaczona polish » english Zobacz oryginalną wersję tematu
  • #301 21111858
    carlig833
    Level 7  
    I have a tuya smart-plug based on CB2S and BL0937. I am pretty happy with the OpenBaken firmware.

    The only little problem is that I find the smartplug is a bit too "chatty" over MQTT.
    It sends almost a message a second despite it is turned off. Would it be possible to reduce and filter that?

    
    domoticz/obk0D722ACA_sp1/power_reactive/get 0.00
    domoticz/obk0D722ACA_sp1/power_factor/get 1.00
    domoticz/obk0D722ACA_sp1/voltage/get 236.4
    domoticz/obk0D722ACA_sp1/current/get 0.011
    domoticz/obk0D722ACA_sp1/power_apparent/get 2.80
    domoticz/obk0D722ACA_sp1/power_reactive/get 2.80
    domoticz/obk0D722ACA_sp1/power_factor/get 0.00
    domoticz/obk0D722ACA_sp1/voltage/get 237.4
    domoticz/obk0D722ACA_sp1/energycounter/get 81.194
    domoticz/obk0D722ACA_sp1/energycounter_today/get 81.194
    domoticz/obk0D722ACA_sp1/current/get 0.000
    domoticz/obk0D722ACA_sp1/power_apparent/get 0.00
    domoticz/obk0D722ACA_sp1/power_reactive/get 0.00
    domoticz/obk0D722ACA_sp1/power_factor/get 1.00
    domoticz/obk0D722ACA_sp1/voltage/get 234.5
    domoticz/obk0D722ACA_sp1/current/get 0.011
    domoticz/obk0D722ACA_sp1/power_apparent/get 2.79
    domoticz/obk0D722ACA_sp1/power_reactive/get 2.79
    domoticz/obk0D722ACA_sp1/power_factor/get 0.00
    domoticz/obk0D722ACA_sp1/voltage/get 235.2
    


    For example, I would like to get an update when the measure changes at least +/- 10% of their value.
    I also completely not interested in voltage, power_reactive, power_factor and so on.
    What are the options to influence this?[/code]
  • ADVERTISEMENT
  • #302 21111874
    p.kaczmarek2
    Moderator Smart Home
    Helpful post? Buy me a coffee.
  • #303 21258802
    baramuse
    Level 2  
    >>20928892
    Hi, I have opened up exact same models, could you tell me where did you get the 3.3v and gnd ?
    I guess TX the upper pin (3rd from top) on your photo and RX the lower one ?

    I can't find anywhere a detailed photo/pins of that CUCO Z6N...

    Cheers
  • #305 21258871
    divadiow
    Level 34  
    baramuse wrote:
    I can't find anywhere a detailed photo/pins of that CUCO Z6N

    Please post detailed photos of your module/device if you can
  • #307 21260269
    divadiow
    Level 34  
    As a demonstration I've probably got too much time on my hands, here's a re-labelled version of both sides alongside photos of the actual module.

    I can't quite make out some of the text on the green side. If anyone has a module and can check my working and fancies filling in the blanks, please do.

    Image shows an electronic module with visible components and its schematic. Image of an actual module and its circuit schematic.
  • #308 21262396
    krzakx
    Level 11  
    >>20266899
    Hey!
    How I might add on top of basis functionality TglChanOnTgl 1 or better Btn 1 - for monostable wall switches add addEventHandler for MQTT to publish double, triple clicks ?
    The goal for me would be to extend basis functionality (keep it in device firmware) and do some more actions in HomeAssistant based on received mqtt topics (double, triple clicks) from device.

    Regards!
  • ADVERTISEMENT
  • #309 21262397
    baramuse
    Level 2  
    >>21260269
    That is awesome thanks a lot @divadiow and @dwmw2, there is all the info needed.
    I'll try with SOIC probles on the BL0942 and then with the pads if I can't get them all !

    Cheers
  • ADVERTISEMENT
  • #310 21262667
    p.kaczmarek2
    Moderator Smart Home
    krzakx wrote:
    >>20266899
    Hey!
    How I might add on top of basis functionality TglChanOnTgl 1 or better Btn 1 - for monostable wall switches add addEventHandler for MQTT to publish double, triple clicks ?
    The goal for me would be to extend basis functionality (keep it in device firmware) and do some more actions in HomeAssistant based on received mqtt topics (double, triple clicks) from device.

    In case of a Button (momentary press), the preferred method is to use Btn_ScriptOnly and then look up the script code in our autoexec.bat samples:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/autoexecExamples.md
    Search for "OnClick".

    Or are you asking about extra events with TglChanOnTgl ? Well, this may be a bit more problematic, because currently the TglChanOnTgl will toggle channel on toggle by design, so it has no click/double click/etc events...
    Helpful post? Buy me a coffee.
  • #311 21263907
    krzakx
    Level 11  
    >>21262667 .
    hey.
    So let's stay with Btn_ScriptOnly

    I don't see in the example scripts, the possibility of chaining for addEventHandler OnClick two actions ie.
    First action: POWER TOGGLE Second (consequent) action to publish this event on MQTT - well, unless the Power Toggle command ensures that this action is published on MQTT - please explain here.

    As I wrote earlier, my goal is to leave (in the device software) the functionality of switching the relay after a button click (monostable) but to extend the automation on the basis of received double, triple clicks in HomeAssistant automations/helpers
  • #312 21263925
    p.kaczmarek2
    Moderator Smart Home
    You will perform several actions using the backlog. In order to increase readability, it is a good idea to use this with an alias. For example:
    
    alias day_lights backlog led_temperature 200; led_dimmer 100; echo lights_day
    alias night_lights backlog led_temperature 500; led_dimmer 50; echo lights_night
    
    addEventHandler OnClick 26 day_lights 
    addEventHandler OnDblClick 26 night_lights 
    
    .
    In your case you will use POWER TOGGLE (Tasmota style) or toggleChannel 1 (OBK style) and publish.
    Helpful post? Buy me a coffee.
  • #313 21266971
    krzakx
    Level 11  
    One other thing is bothering me.
    How is it that despite the following configuration (containing only the switch ) in the Home Assistant Cfg Discovery section
    mqtt:
      switch:
      - unique_id: "OpenBK7231N_FFCE844C_relay_1"
        name: 1
        state_topic: "beken_lampa/1/get"
        command_topic: "beken_lampa/1/set"
        qos: 1
        payload_on: 1
        payload_off: 0
        retain: true
        availability:
          - topic: "beken_lampa/connected"
    .
    Realistically, the Mosquitto broker also sees many other parameters like:
    * Apparent Power
    * Current
    * Energy Last Hour
    * Energy Total
    * Power
    * Power Factor
    * Reactive Power
    * Voltage
    Is the above happening due to the driver startDriver BL0942 .
  • #314 21267143
    p.kaczmarek2
    Moderator Smart Home
    The Yaml code displayed by OpenBeken in Home Assistant Discovery is an undeveloped feature and will probably be removed. There used to be no automatic Discovery and this code was for the user to manually copy into configuration.yaml. Currently, Home Assistant Discovery works slightly differently and publishes much more developed code that is not visible in the preview. If you want to see what HASS Discovery is actually sending in OBK, then in Home Assistant, in MQTT, enable listening on the homeassistant + wildcard multilevel topic (or similar, I'm writing from memory) and then in OBK enable Discovery, then you will see what is published.

    Whereas Discovery itself actually checks what drivers have been enabled via "startDriver" and adds things based on that, so it's important to configure everything first (enable drivers) and then do Discovery.
    Helpful post? Buy me a coffee.
  • #315 21267230
    krzakx
    Level 11  
    Thank you for the clarification.

    I can already see what HASS Discovery sends in OBK, should have done a listen to homeassistant topic + #
    https://www.home-assistant.io/integrations/mqtt/#testing-your-setup

    OK, now a question for Openbk:
    * is it possible to customise HASS Discovery in OBK ? - > I have configured myself pin 24 of Btn_ScriptOnly as follows:
    alias doOnClickActions backlog ToggleChannel 1; publish button click
    alias doOnDblClickActions backlog publish button Dblclick
    alias doOnHoldStartActions publish button holdstart
    alias doOnReleaseActions publish button released
    
    addEventHandler OnClick 24 doOnClickActions
    addEventHandler OnDblClick 24 doOnDblClickActions 
    addEventHandler OnHold 24 doOnHoldStartActions 
    addEventHandler OnRelease 24 doOnReleaseActions
    .
    and I would now like to see these additional actions like double-click in HomeAssistant so that I can perform automations with their help.
  • #316 21270107
    p.kaczmarek2
    Moderator Smart Home
    You can add your own stuff to Home Assistant Discovery via the publishFile command - you simply put your yaml in a file (following the HA standard) and then use publishFile under the relevant topic so as to 'simulate' Discovery.

    If, on the other hand, you want to catch an event of e.g. "released" in Home Assistant, then based on the fact that you are already executing the "publish button released" in your code, you have to listen in HA on the corresponding topic and plug in the automation there when the string "released" appears on that topic.

    Unless you want to do it the other way round - call it from Home Assistant. Then you can from HA send e.g. "toOnClickActions " as a command and OBK will execute it. E.g. via a button: Home Assistant - how to create an event trigger button, MQTT, dashboard .
    Helpful post? Buy me a coffee.
  • #317 21279316
    hjhadenfeldt
    Level 1  
    >>20959216 I have successfully used a Gosund EP2 10A plug with OpenBK Flash. However, the LEDs do not work as usual. The WLAN LED should light up blue and the status LED should indicate the switching status. With the specified json file, both LEDs are dark, both when the relay is switched on and when the WLAN is working. How can I change this, does anyone have any experience?
  • #318 21311271
    donatasr
    Level 2  
    Dark Man wrote:
    Today I flashed another 3 sockets with BK7232N, of which 2 are noname and 1 is Aubess (there was about a dollar and a half yeast from these nonames - I bought them at a different time than these nonames in the Choice option on AliExpress).
    In appearance, the housing looks identical. On the other hand, on the Aubess socket there are prints about the current, although it is false because it is supposed to be 20A max and inside there is a 16A relay. There are larger 20A relays in noname sockets.
    Who was copying whom? 😂
    Some comparison photos below.
    Two Aubess smart sockets with blue PCBs mounted on a clamp. Two Aubess smart sockets with blue PCBs and relays on a workbench. Two PCBs of different colors attached to a device. Two blue Aubess smart socket PCBs.

    The Aubess socket has only one LED (nonames have 2 blue ones, although sometimes older sockets used to have one red).
    How can it be used to show the status of wifi connectivity and the state of the relay after connecting to WiFi?

    Where did the Tools tab in the Web App Gui go? It has not been there for at least a dozen or so versions, and there was a nice menu for current calibration :(
    Now I had to do the same commands :/
    Also from at least a dozen or so versions, the preview of logs on the phone is terribly broken - i.e. buttons and squares for birds with descriptions enter the log window instead of being underneath.


    I have got blue one PCB Aubess smart socket. Did not flashed with opensource custom firmware yet . But one of my smart sockets failed. Relay clicks in 2-3 minutes interval and led lights for a second while powering on. Opened it, checked for voltages, 5V and 3.3V are present. Maybe CB2S chip failed. Is it possible to re flash it with factory firmware, as you have same blue PCB as mine, are you able to share archive of orginal firmware?
  • #319 21311471
    p.kaczmarek2
    Moderator Smart Home
    >>21311271 I'd still suggest checking the capacitor. It's usually the capacitor. See related topic:
    https://www.elektroda.com/rtvforum/topic3898805.html
    NOTE: It has to be replaced with low ESR one.

    EDIT: You can also try disconnecting the socket from mains and powering it's 5V (or 12V, depends on model) lane from power supply and observing if the problem still occurs.
    Helpful post? Buy me a coffee.
  • #320 21312490
    donatasr
    Level 2  
    >>21311471
    Applied 5V to capacitor, and received same issues. Led lit at power on, relay switched on, and bouncing with 2-3 minutes interval. Is there a method of checking CB2S chip.
  • #321 21312626
    p.kaczmarek2
    Moderator Smart Home
    Desolder CB2S, make 2MB flash backup, and flash OBK and see if OBK works. You can always restore Tuya from backup if you want.
    Related tutorial:


    Helpful post? Buy me a coffee.
  • #322 21353799
    mrsergio07
    Level 4  
    Hi, finally I have successfully flashed my LSPA9 with OpenBeken and configured it in home assistant. But I want to reduce the sampling rate at which it is sent by MQTT, as currently, the voltage for example, is being written every 15seconds and therefore taking up space in the database

    Thanks
  • ADVERTISEMENT
  • #323 21355633
    p.kaczmarek2
    Moderator Smart Home
    Helpful post? Buy me a coffee.
  • #324 21359804
    mrsergio07
    Level 4  
    Thanks, now it works better with VCPPublishIntervals

    Could you publish recommended autoexec.bat and flags for this device?
  • #325 21360768
    p.kaczmarek2
    Moderator Smart Home
    This device seems to be very simple, so whatever works for you should be good. Well... maybe except the powersave. I can recommend using PowerSave 1 in autoexec.bat to prolong device life. PowerSave 1 may break BL0937 precision, but if your plug is using BL0942, then powerSave 1 is good. Make sure to use it on your devices.
    Helpful post? Buy me a coffee.
  • #326 21361312
    mrsergio07
    Level 4  
    p.kaczmarek2 wrote:
    This device seems to be very simple, so whatever works for you should be good. Well... maybe except the powersave. I can recommend using PowerSave 1 in autoexec.bat to prolong device life. PowerSave 1 may break BL0937 precision, but if your plug is using BL0942, then powerSave 1 is good. Make sure to use it on your devices.


    My devices use BL0937. In the doc I read that PowerSave is 1 by default so it should be already enabled, thanks!
  • #327 21372270
    minusync
    Level 9  
    p.kaczmarek2 wrote:
    This device seems to be very simple,

    How were you able to flash it?
    I have similar CB2S with BL0937 and whatever I do I can not get bus read. I have tried with cen and power interrupt . Nothing works.
    I have standard setup with connected to chip rx, tx, 3V and gnd.
    I looked at your pictures in first page and noticed awful lot of wires - certainly more then in my setup. I can see there birds nest of wires but no actual explanation if 4 standard connections to chip are not enough - how it actually should go.

    edit
    Eventually I did desolder it from board and was able to flash it. I always consider that approach as last solution - it is always high risk to destroy something. I don't have hot air soldering equipment.

    Now I have another problem. I did use wifi setup with OBKConfig and flash seems to go successfully but socket refuses to connect. Blue led just keeps flashing. I am sure that password I entered was correct - I am using it same way as copy paste with all my devices.
    Is there possibility to somehow turn on safe mode so I could connect and check what is wrong?
  • #328 21374330
    p.kaczmarek2
    Moderator Smart Home
    Desoldering WiFi module is sometimes required for successfull flashing.

    4 standard wires (3.3V, GND, RX and TX) should be enough.

    There is safe mode possible:
    https://github.com/openshwprojects/OpenBK7231T_App/blob/main/docs/faq.md
    Quote:

    Question: I entered wrong SSID and my device is not accessible. How to recover?
    A: Do five short power on/power off cycles (but not too short, because device might have capacitors and they need to discharge every time). Device will go back to AP mode (aka Safe Mode). Remember that in Safe Mode, pins are disabled, drivers are also not run, so don't worry if you see your device seemingly not responding to buttons, etc, etc.
    Helpful post? Buy me a coffee.
  • #329 21374777
    minusync
    Level 9  
    p.kaczmarek2 wrote:
    There is safe mode possible:


    I can connect to it in safe mode
    I have correct wifi credentials, checked several times (not exactly bcs I can not see actual pswrd, only dots, but I do copy paste)
    It still refuses to connect to my local network
  • #330 21374802
    p.kaczmarek2
    Moderator Smart Home
    Is it your first OpenBeken device? Is your network 2.4GHz?
    Helpful post? Buy me a coffee.

Topic summary

The discussion revolves around the Tuya LSPA9 smart socket, focusing on its teardown, flashing OpenBeken firmware, and configuring the BL0942 energy metering chip. Users share their experiences with various versions of the LSPA9, including issues with calibration, communication protocols (UART vs. SPI), and the stability of energy readings. Solutions include using specific commands for calibration, adjusting baud rates, and troubleshooting connectivity issues. The conversation also touches on the integration of these devices with Home Assistant and the challenges faced in ensuring accurate power measurements and MQTT communication.
Summary generated by the language model.
ADVERTISEMENT