Has anyone got a Sonoff Mini Code that you could share?

I think I’ve sorted this now. Great device, really cheap, initial update OTA via Sonoff DIY mode. Easy as.

Here’s the code:

esphome:
  name: sonoff_mini
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_SSID
  password: !secret wifi_password

# Enable logging
logger:

substitutions:
  hostname: "sonoff_mini"

# Enable Home Assistant API
api:
  password: !secret default_password

ota:
  password: !secret default_password

# used just for testing, otherwise no need for it
#web_server:
#  port: 80

# tasmota template: {"NAME":"Sonoff Mini","GPIO":[17,0,0,0,9,0,0,0,21,56,0,0,255],"FLAG":0,"BASE":1}

# template decoded: GPIO: GPIO00 17 Button1, GPIO04 9 Switch1, GPIO12 21 Relay1, GPIO13 56 Led1i, GPIO16 255 userdef; BASE: Sonoff Basic

status_led:
  pin:
    number: GPIO13
    inverted: true

binary_sensor:
  - platform: gpio
    pin: GPIO00
    id: reset
    internal: true
    filters:
      - invert:
      - delayed_off: 10ms
    on_press:
      - switch.toggle: 
          id: relay_1

  - platform: gpio
    name: "$hostname switch"
    pin: GPIO04
    id: switch_1
    on_press:
      then:
        - switch.turn_on:
            id: relay_1
    on_release:
      then:
        - switch.turn_off:
            id: relay_1

switch:
  - platform: gpio
    name: "$hostname relay"
    icon: "mdi: lightbulb_outline"
    pin: GPIO12
    id: relay_1
    restore_mode: restore_default_off
6 Likes