Sonoff Basic (Light)

Sonoff Basic (Light)

ESPhome firmware for Sonoff Basic to act as a light switch.

  • Binary Sensor: Button
  • Binary Sensor: Status
  • Light
  • Sensor: WiFi Signal
  • Sensor: Uptime
  • Output: IP Address
esphome:
  name: Light_Sonoff_Basic
  platform: ESP8266
  board: esp01_1m

wifi:
  networks:
  - ssid: "YOUR_SSID"
    password: "yourpassword"
    priority: 1
  - ssid: "YOUR_SSID_backup"
    password: "yourpassword"  
    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
    name: Light Sonoff Basic Button
    on_press:
      then:
        - light.toggle: light_1
  - platform: status
    name: "Light Sonoff Basic Status"
    
output:
  - platform: gpio
    pin: GPIO12
    id: relay_1
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

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

interval:
  - interval: 1s
    then:
      - if:
          condition:
            switch.is_on: relay
          then:
            light.turn_on: led
          else:
            light.turn_off: led

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()};'

Leave a Reply

Your email address will not be published.