Sonoff Basic (Switch with use of IO2)

Sonoff Basic (Switch with use of IO2)

ESPhome firmware for Sonoff Basic to act as a switch with extra binary sensor.

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

wifi:
  ssid: "YOUR_SSID"
  password: "yourpassword"

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

captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

web_server:
  port: 80
  
binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Switch Sonoff Basic Button"
    id: switch_1
    on_press:
      - switch.toggle: relay
   - platform: gpio
    pin: 
      number: GPIO2 #IO2 Sonoff Basic R2 // GPIO14 Sonoff Basic R1
      mode: INPUT_PULLUP
      inverted: True
    name: "Switch Sonoff Basic Sensor"
    id: switch_2
   
  - platform: status
    name: "Switch Sonoff Basic Status"
          
switch:
  - platform: gpio
    name: "Switch Sonoff Basic"
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes
    
sensor:
  - platform: wifi_signal
    name: "Switch Sonoff Basic WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "Switch Sonoff Basic Uptime"
    filters:
      - lambda: return x / 3600.0 /24;
    unit_of_measurement: "days"
    accuracy_decimals: 0
    

          
text_sensor:
  - platform: template
    name: "Switch Sonoff Basic IP"
    lambda: 'return {WiFi.localIP().toString().c_str()};'
    
interval:
  - interval: 1s
    then:
      - if:
          condition:
            switch.is_on: relay
          then:
            light.turn_on: led
          else:
            light.turn_off: led
            
output:
  - platform: esp8266_pwm
    id: basic_green_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    output: basic_green_led
    id: led            

Leave a Reply

Your email address will not be published.