Skip to content

Controlling smart WiFi plug from Lan Controller

Smart WiFi Plugs

Requirements

  1. Smart plug (based on ESP8266, using Tuya firmware, eg Gosund SP111) with Tasmota firmware loaded.
  2. Lan Controller v3.5+.

Instruction

  1. On the HTTP Client page, enter in the field Server address 2 the text <PLUG IP ADDRESS>:80/cm?cmnd=Power %44, where in place %44 the output state out1 will be inserted, according to description under the form.

    LK3 setup 1

  2. On the Events page, add the event OUT1 = 1 => http2 and enable it.

    LK3 setup 2

In result, the output state out1 corresponds to the state of the plug - when the LK output state changes, the plug state will also be changed using the HTTP command.

You can use another field Server address and another output out, or you can link the state of the plug with another value from LK, e.g. with a temperature reading.

Preparation of the plug with Tasmota firmware

If the plug does not have Tasmota firmware installed, you will additionally need:

  1. Linux computer with a WiFi adapter (e.g. Raspberry Pi 3B/3B+/4B).
  2. WiFi device (e.g. smartphone).

The presented manual includes a description for Raspberry Pi 4B, Android smartphone, Gosund SP111 plug and Lan Controller v3.5+ (HW 3.7). Therefore, some steps may differ slightly when using other components.

Preparing a Linux computer

  1. Prepare an SD card with the system.
    1. Download the program for uploading the system image to the SD card, eg. balenaEtcher or Raspberry Pi Imager.
    2. Download a system image, eg. Raspberry Pi OS Lite from raspberrypi.org.
    3. After uploading the image, you can add a file called ssh (without extension) on the boot partition in order to start the SSH server.
  2. Prepare the Raspberry Pi software.

    1. Start the Raspberry Pi with the prepared card and Ethernet connection to the Internet.
    2. Connect to Raspberry Pi via ssh, default login is pi:raspbery.
    3. Enter the command sudo raspi-config, go to the Advanced Options section and select Expand Filesystem. Upon exiting raspi-config, you should be prompted to reboot, which should be performed.

      raspi-config

    4. Update the system and install the necessary packages by typing the following commands in the console (may require confirmation after each):

      sudo apt-get update
      sudo apt-get dist-upgrade
      sudo apt-get install network-manager
      sudo apt-get install git
      

Installation and use of tuya-convert

  1. Install the tuya-convert application to upload other firmware to the plug.

    git clone https://github.com/ct-Open-Source/tuya-convert
    cd tuya-convert
    ./install_prereq.sh
    
  2. (Optional) Download a newer Tasmota firmware (np.v8.5.1 tasmota-lite.bin).

    cd files
    wget https://github.com/arendst/Tasmota/releases/download/v8.5.1/tasmota-lite.bin
    mv tasmota.bin tasmota-included.bin
    mv tasmota-lite.bin tasmota.bin
    cd ..
    
  3. Launch the application and follow its instructions to upload new software.

    ./start_flash.sh
    

    First you need to accept with yes + enter. Later, there may be questions about freeing ports (eg 53 occupied by dnsmasq) to which you should answer y.

    Start Flash

    Then turn on the plug and connect the smartphone to the network indicated in the manual (in this case vtrust-flash). Confirm with enter, after a while select firmware Tasmota (in this case 3 tasmota.bin).

    Start Flash

Plug configuration with Tasmota firmware

  1. Connect to the tasmota_XXXX network, visit the address 192.168.4.1 in the browser, complete the WiFi connection form.
  2. Find the device address in the indicated WiFi network and visit it in the browser.

    Tasmota 1

  3. (Optional) The device can also be connected to the mqtt.ats.pl server as WR-01, so that it can be controlled from the ATS MQTT Client application. Information on how to link device with mqtt.ats.pl service can be found here.

    Info

    We no longer provide a modified version of the Tasmota firmware as we have added support for the standard version on the server side. In case of problems with connecting the device and/or collecting data, please contact me via the contact form at mqtt.ats.pl.

  4. Go to the Configuration section and then Configure Other.

    Tasmota 2

  5. Enter text below into Template field (first option is with red LED when plug is on, second option is blue LED) and select Activate:

    {"NAME":"SP111 v1.1","GPIO":[56,0,158,0,132,134,0,0,131,17,0,21,0],"FLAG":0,"BASE":45}
    
    {"NAME":"SP111 v1.1","GPIO":[158,0,56,0,132,134,0,0,131,17,0,21,0],"FLAG":0,"BASE":45}
    

    You can find templates for other devices here.

    Tasmota 3

  6. For more accurate energy consumption measurements calibration is required.

    Calibration consists in setting the three parameters CurrentCal, PowerCal and VolatageCal, and is precisely described here.

    Tasmota 4

    Tasmota 5