Sonoff Basic

Sonoff Basic

The sonoff basic is a relay that you can wirelessly control via WiFi and drive a light, a fan, an electric heater or anything else that works with 220V.

The Sonoff Basic accepts 220V input and as an output a device that operates at 220V, in essence depending on how you connect the phase and the neutral, one goes directly from the input to the output and the other cable goes through the relay. You can’t use Sonoff Basic for a 12v device, for example. If you need to control a low voltage device then you can choose Sonoff SV or Shelly 1.

Sonoff can run independently of the Home Assistant, with its own firmware already installed, ewelink. With this firmware you can also connect it to the Home Assistant via the sonoff plugin. First you create an account in ewelink and connect your Sonoff following the instructions of the application. Then you need to add the following code to configuration.yaml.

sonoff:
  username: !secret sonoff_user
  password: !secret sonoff_password
  scan_interval: 60 
  grace_period: 600 
  api_region: 'eu' 
  entity_prefix: True 
  debug: False

Personally, I don’t prefer ewelink, I flash to Sonoff instead of ewelink, my own firmware based on esphome or Tasmota.

To do this you will need a soldering iron, solder paste, male pins and USB to Serial Module. You will need to solder the 5 pins, they may differ from version to version.

When you solder the pins and flash the new software, be careful not to connect to the 220v power supply.

The usb to serial should be with operating voltage and RX / TX voltage at 3.3v

Connect the module to the pins you stuck to Sonoff carefully, TX / RX will go backwards.

  • Sonoff / USB Module
  • VCC / Vcc
  • Ground / Ground
  • RX / TX
  • TX / RX

You can buy it from here

Now you need to prepare your own firmware, install ESP Home on Home Asssitant. You will find it from the menu on the Supervisor tab. See here for detailed instructions.

This is an example for Sonoff Basic to work as light.

esphome:
  name: light_sonoff_basic
  platform: ESP8266
  board: esp01_1m

wifi:
  networks:
  - ssid: "YOUR_SSID"
    password: "your_password"
    priority: 1
  - ssid: "YOUR_SSID_BACKUP"
    password: "your_password"  
    priority: 0

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Light Sonoff Basic"
    password: "0kNuXz4DpNsC"

web_server:
  port: 80
  
captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO14
      mode: INPUT_PULLUP
      inverted: True
    id: button_1
    on_press:
      then:
        - light.toggle: light_1
  - platform: status
    name: "Light Sonoff Basic Status"
    
output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

light:
  - platform: binary
    name: "Light Sonoff Basic"
    id: light_1
    output: relay_1

status_led:
  pin:
    number: GPIO13
    inverted: yes
    
sensor:
  - platform: wifi_signal
    name: "Light Sonoff Basic WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "Light Sonoff Basic Uptime"
    filters:
      - lambda: return x / 3600.0 /24;
    unit_of_measurement: "days"
    accuracy_decimals: 0
    
text_sensor:
  - platform: template
    name: "Light Sonoff Basic IP"
    lambda: 'return {WiFi.localIP().toString().c_str()};'

Then you need to compile and download the file through ESPhome.

Finally, you need to upload the file you just downloaded to Sonoff, use the espflasher, you will find it here.

After the flash is complete, the home assistant will automatically find the new device.

Leave a Reply

Your email address will not be published.