SmartKnight ML Accessories Ltd - Smart Plug

Just bought them myself… would be curious too.

I actually just figured it out with some research… it’s Tuya in the background.
I had to download the “Tuya Smart” App and add the smart plug there. It’s exactly the same like in SmartKnight.
Then just followed the advice on integrating Tuya into Home Assistant and the Smart Plug showed up in Home Assistant.

1 Like

I bought a SmartKnight / Knightsbridge outdoor double socket and I’m trying to figure out how to connect it (locally) with HA.

I’ve scanned the open ports looking for some web interface or an API and noticed it has 6668 open - Internet Relay Chat. And ended up discovering that it is quite common for Tuya devices (as you said).

I don’t want to register this device via the cloud service so I kept digging. Since, I think, all Tuya devices are based on ESP chips I was thinking that the best would be to flash it with ESPHome.

I have opened it and it turned out that indeed there is a WiFi module attached to it. Although there is no name on it :frowning: The good thing is that it has service pins (Tx,Rx,??,3.3v,GND) which potentially I could use for flashing.

The problem is that I think I need to know the exact board name to flash it with ESPHome and I guess I would need to figure out how exactly I could expose two entities for two sockets.

Any advices/suggestions are really appreciated :slight_smile:

Edit: looks like there is a Tasmota config for this model Knightsbridge Dual Waterproof Wall Outlet (OP9KW) Configuration for Tasmota

Ok I’ve made it. I have flashed Tasmota on it!

My socket model: Knightsbridge OP9KW

I believe that SN9KW is exactly the same but just without the additional outdoor case.

Step by step instruction:

What is needed:

  • USB to TTL adapter - required for flashing
  • Tasmotizer - flashing software

There is a way to flash Tuya devices via WiFi but I haven’t tried it.

  1. Remove the metal bracket with a screwdriver - gently squeeze in a screwdriver between the metal part and the plastic and try to push the metal part up, do it around the end of the bracket.

  2. Gently take off the WiFi module (ESP8266)


    It is connected on the both sides - left and right with that kind of pins
    image

  3. Connect your usb to ttl in the following way (do not connect adapter to your PC yet!)


    Please note that I’m not sure whether the pin in the middle is actually a Gpio0 but I have used it as one and it worked.
    I didn’t want to solder the wires so I have put the pins inside these holes and used the holding tool to apply little bit tension to be sure there is a connection

  4. Setting ESP into flashing mode
    This is little bit tricky. You need to connect GND with the Gpio0 and plug-in the USBtoTTL adapter to your PC in the same time. Hold the connection for about 5 seconds and then disconnect it.

  5. Flashing
    Launch Tasmotizer, it should detect your device (you may need to adjust the serial port). Set everything as it is shown below

    • Save original firmware
    • Erase before flashing
    • Release (radio button)


    Once the backup is done you need to disconnect and connect the usb adapter the same way as previously (TBH maybe putting GND to gpio0 is not necessary for the backup - but this is the way how I did it, here in this step is necessary for sure)

  6. Once flashing is done re-connect the usb adapter. Tasmota should be up and running. After couple of seconds you should be able to see a new WiFi SSID available.

  7. Setting config via Tasmotizer.
    You can skip this step if you prefer to connect to the tasmota wifi and configure it from there.
    Click “send configuration”, in the new window put your home WiFi connection details and paste the template copied from here
    image
    Click save and you are done!!!

I’m pretty sure you can do similar stuff with other Knightsbridge devices.

I hope the above will help someone. Good luck!!!

do you happen to have a link pointing at the way of flashing tuya ones wirelessly?

Search for tuya-convert

2 Likes

Here is a sample of adding Tasmota device to HA without MQTT

Note: I’m controlling here the second socket thus I have everywhere “Power2”. If you want to control the first one just replace 2 with 1 (or just remove it as 1 is the default one)

switch:
  - platform: command_line
    switches:
      garden_lights_2:
        command_on: >
          curl -s -m 5 -X POST 'http://192.168.4.254/cm?cmnd=Power2%20On'
        command_off: >
          curl -s -m 5 -X POST 'http://192.168.4.254/cm?cmnd=Power2%20Off'
        command_state: >
          curl -s -m 5 -X GET 'http://192.168.4.254/cm?cmnd=Power2' || echo -n {"POWER2":"OFF"}
        value_template: >
          {{value_json.POWER2 == "ON" }}
        friendly_name: "Garden lights"

not that Im gonna go that way just yet, but does Tasmota happen to open up a sensor that shows power draw for each socket…or is it still for the whole socket there as well

If it doesn’t give me any more control over localtuya, not a lot of point of me opening up the socket itself

Max, Awesome work. I have just followed your thread and got mine working too. I only levered off one of the two rivets and swung the unit apart on the other rivet. It was a pain to get the springs back in place though. The default code on Knightsbridge Dual Waterproof Wall Outlet (OP9KW) Configuration for Tasmota doesn’t include the current monitoring. I updated the settings to:

and now have full functionality.

1 Like

Thank you @SPB it worked! I have updated the template in the repo I have linked above.

Today I have managed to flash it with ESPHome!

Here is a short how-to but I’m not sharing the yaml as I want to finish it (add power monitoring, currently I have control over relays only)

My Tasmota version was 12.3.1. I was quite scared that something will explode as I have read couple of posts were people were struggling to do it. It turned out that in v8 they have introduced a safety feature which was meant to be preventing from downgrading (and in the same time blocked uploading other firmware) but this was solved by using undocumented command (look at first step below). In v12 they have added a Safetyboot partition which some people were saying might be a big blocker flashing it with other firmware via OTA. But looks like it still works!

  • Tasmota console: SetOption78 1
  • Build as small ESPHome bin as possible (just a single basic switch.gpio). This resulted in quite big file 498kB
  • I have gzipped it with 7-zip and the result file was 345kB (I thought it will fail to upload as well but it didn’t!)

Just in case anyone else if following they are Tuya based, you need to use the Tuya App but once thats done it works fine.

Yeah that is probably true. I have, kind of, stolen your thread here (I hope you don’t mind)… I was searching for solutions on how to make it working fully locally without any cloud so decided to continue the discussion here just in case someone else is interested in making it working the other way.

BTW So far I have the following:

  • Entities for controlling the sockets are exposed to HA
  • There are two entities one in the light and second in switch domain
  • Buttons are working as they were in the original software
  • Leds are showing the state of the relay
  • Power, current and voltage is showing up (although some of the values appear after some time)

My config is available here:

No problem carry on, all info is good info.

Also take a look at GitHub - rospogrigio/localtuya: local handling for Tuya devices

Managed to flash Tasmota onto my SmartKnight plug socket this weekend thanks to the help from @maxwroc post above. Cant say it was a breeze…all went well until my attempts to put it in bootloader mode by grounding the GPIO0 pin while plugging in the USB adapter…spent about 3 hours trying to get it right to no avail before giving up…my next attempt was to try Tuya convert (after re-assembling the plug components) which then gave me the message that the installed firmware was"too new" and was no longer able to use the Tuya convert “trick”…anyway back to the disassembly and then more attempts at flashing via USB to TTL…finally managed to get the grounding right by using some spare headers and an elastic band to hold all the pins in place…success!!!

Have it fully working now in Home Assistant including the power monitoring thanks to @maxwroc template which works a treat.

1 Like

I successfully flashed a Knightsbridge CU9KW (the curved-front version) with an esphome binary, without tasmota (I’m not really familiar with tasmota and only use esphome with HA). The socket is installed in a BG Storm IP66 exterior socket enclosure (the new version/shape).

I first used esptool read_flash to take a dump of the stock firmware.

Then I compiled my esphome YAML with docker run esphome/esphome. The YAML is based on @maxwroc garden-sockets.yaml github linked above, with my own minor/local mods.

I then used esptool write_flash to write the compiled firmware binary (.bin).

In terms of UART hardware, I used my trusty old Bus Pirate in UART pass-through mode (with USB-side and ESP-side baud rate set to 74880 (Bus Pirate BRG set to 52).

With a small 10W pond pump/fountain connected, I can control it OK, but somtimes when the pump is switched off, I notice that the ESP8266 in the CU9KW disconnects from HA (WiFi?) and then reconnects 10-15 seconds later. If I repeatedly switch on/off an unloaded socket (nothing plugged in), then I don’t see any HA disconnects.

I’m wondering if the ESP8266 WiFi in this thing is being upset by mains transients from the (inductive?) pond pump motor being switched off.

Once it’s been running for a few weeks, I’ll report back on any issues/learnings. Also, I’ll have a crack at calibrating the voltage/current/power measurements.

edit: When I tried using tuya-convert (running on an RPi) to update the CU9KW it errored out with Timed out while waiting for the device to (re)connect...Attempting to diagnose the issue...Your device's firmware is too new. Tuya patched the PSK vulnerability that we use to establish a connection... , and then printed a link to their github wiki Collaboration document for PSK Identity 02 . This is why I also went for the serial-flash method.

edit 2: I also forgot to mention that I pulled the eps8266 board from the mainboard for flashing. Once the flash had completed and device reset/power-cycled, I couldn’t see the device come up and attach to WiFi until it was reconnected to the mainboard.

I’ve just used these instructions to flash ESPHome to a CU9KW variant and it worked fine. The ESPHome template needs some work but both relays work fine.

Disassembling the plug was easy but I must call out that you need to be careful with the rivets which need to be pried open to do this mod. As well as electrically connecting the screws to earth they also hold the entire earth assembly in place so when the socket is reassembled it’s really important to ensure you “crush” the rivet back against the inside of the socket or when you push a plug in next time it will force the earth assembly apart.

Config in my GitHub repo here. It still needs tweaking for accuracy of the power monitoring chip as it’s wildly off right now.

Did you get anywhere with the energy monitoring? By default the values seem wildly off (like for example the voltage is reading 280v for me right now).

Maxwroc, thanks for figuring this out. I successfully flashed the CU9KW this evening. The Tasmota site has some useful tricks which made this much easier and I’ll share for others who might be trying this.

  1. have an independent 3.3v power supply attached to the ESP8266 instead of VCC from the usb adapter.
  2. the ground can be permanently connected to GPIO0 during the process.
    This means you can set the whole thing up and after connecting the usb you turn on the independent power and it’s read to flash,

I just want to say a huge thanks to @maxwroc. I managed to flash four of these (indoor sockets) today in about two hours (start to finish) and they all seem to be working under basic testing (not installed them all yet but put a couple of loads on them and switch on and off repeatedly.)

My only disappointment is that the energy isn’t monitored on a per-socket basis.

as for the question above by @DJBenson you will need to calibrate the sockets, grab yourself a cheap energy monitor from somewhere like amazon and ideally try and use a fixed load (like an incandescent light in a lamp) and then follow the instcutions

1 Like

@karldonteljames I don’t suppose you’d be willing to sell and exchange? I just don’t have the knowledge to be able to do this, but would really like to do it.