Sonoff S31 and ESPHome

I managed to flash the firmware so I can perform OTA updates. Does anyone have any yaml for setting this up to work with ESPHome and HA?

Explained here

1 Like

Here is my YAML for the Sonoff S31 running my Yard Lights. In addition to the Power Sensors, it is set to turn on the Lights at Sunset and off at 3 AM.

esphome:
  name: yardlights
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: 'Your SSID'
  password: 'Your Password'
  # Optional manual IP
  manual_ip:
    static_ip: 192.168.x.x
    gateway: 192.168.x.x
    subnet: 255.255.255.0

# Enable logging
logger:
  baud_rate: 0

uart:
  rx_pin: RX
  baud_rate: 4800

# Enable Home Assistant API
api:

ota:

time:
  - platform: homeassistant
    id: homeassistant_time
    on_time:
    # 3 AM Daily
    - hours: 3
      then:
        - switch.turn_off: relay
        - light.turn_off: led

sun:
  latitude: 34.327778
  longitude: -118.640644
  on_sunset:
    - then:
      - switch.turn_on: relay
      - light.turn_on: led

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Yard Button"
    on_press:
      - switch.toggle: fakebutton
  - platform: template
    name: "Yard Running"
    filters:
      - delayed_off: 15s
    lambda: |-
      if (isnan(id(power).state)) {
        return {};
      } else if (id(power).state > 4) {
        // Running
        return true;
      } else {
        // Not running
        return false;
      }

switch:
  - platform: template
    name: "Yard POW Relay"
    optimistic: true
    id: fakebutton
    turn_on_action:
    - switch.turn_on: relay
    - light.turn_on: led
    turn_off_action:
    - switch.turn_off: relay
    - light.turn_off: led
  - platform: gpio
    id: relay
    pin: GPIO12

output:
  - platform: esp8266_pwm
    id: pow_blue_led
    pin:
      number: GPIO13
      inverted: True

light:
  - platform: monochromatic
    name: "Yard Blue LED"
    output: pow_blue_led
    id: led

sensor:
  - platform: wifi_signal
    name: "Yard WiFi Signal"
    update_interval: 60s
  - platform: uptime
    name: "Yard Uptime"
  - platform: cse7766
    update_interval: 2s
    current:
      name: "Yard Current"
    voltage:
      name: "Yard Voltage"
    power:
      name: "Yard POW Power"
      id: power
      on_value_range:
        - above: 4.0
          then:
            - light.turn_on: led
        - below: 3.0
          then:
            - light.turn_off: led

text_sensor:
  - platform: version
    name: "Yard ESPHome Version"
  - platform: sun
    name: Sun Next Sunrise
    type: sunrise
    format: "%I:%M %p"
  - platform: sun
    name: Sun Next Sunset
    type: sunset
    format: "%I:%M %p"
3 Likes