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

Thanks Tom

I got it working 80% with your suggestions.

The sonoff mini works as a switch, I just need to work out the code to have it toggle rather than switch on/off

[18:28:28][C][api:104]:   Address: sonoff_mini.local:6053
[18:28:34][D][binary_sensor:033]: 'Sonoff Mini Switch': Sending state ON
[18:28:34][D][switch:029]: 'Sonoff Mini relay' Toggling OFF.
[18:28:34][D][switch:045]: 'Sonoff Mini relay': Sending state OFF
[18:28:42][D][binary_sensor:033]: 'Sonoff Mini Switch': Sending state OFF
[18:28:44][D][binary_sensor:033]: 'Sonoff Mini Switch': Sending state ON
[18:28:44][D][switch:029]: 'Sonoff Mini relay' Toggling ON.
[18:28:44][D][switch:045]: 'Sonoff Mini relay': Sending state ON
[18:28:49][D][binary_sensor:033]: 'Sonoff Mini Switch': Sending state OFF
1 Like

Share the… code

2 Likes

toggle is a standard home assistant function.

After update the firmaware with esphome the 3-function still working? Thanks

Can you share the code you have?

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

Btw. the sonoff mini uses a esp8285…

So the start would be:

esphome:
  name: sonoff_mini
  platform: esp8266
  board: esp8285
1 Like

Hi,
Very informative thank you. Can anyone advise what GPIO connections are tied to the S1 and S2 connecting points on the Sonoff Mini. I’m writing my own firmware and want to encompass the external switch option. TIA Paul

Switch input is GPIO04 and Ground

1 Like

Is the button in parallel with S1 and S2 though, or are S1 and S2 separate GPIO inputs?

Switch input is GPIO04 and Ground

orange-assistant Thank you, that worked well. tom_l The button is on GPIO0 and the S1/S2 is as orange-assistant says:- GPIO4 and Ground.

1 Like

Hi, can I just ask, is your yaml the same as above? If different, can you please post. Thanks

To be totally correct:

Sonoff Mini S1 Input is Ground
Sonoff Mini S2 Input is GPIO4

This can be important if you plan a shared ground!

How do you get the sonoff mini in diy mode for initial ota flashing?

FYI this is from Drzzs youtube example:

esphome:
  name: main_bathroom_shower
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi
  password: !secret wifi_pw

# Enable logging
logger:
# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Main Bathroom Button"
    on_press:
      - switch.toggle: relay
  - platform: gpio
    pin:
      number: GPIO4
      mode: INPUT_PULLUP
      inverted: True
    name: "Main Bathroom Switch"
    on_press:
      - switch.toggle: relay   
switch:
  - platform: gpio
    name: "Main Bathroom Relay"
    pin: GPIO12
    id: relay

status_led:
  pin:
    number: GPIO13
    inverted: yes
2 Likes

Hi Immo,

I used the procedure documented at https://github.com/arendst/Sonoff-Tasmota/wiki/Sonoff-DIY . So got Tasmota Basic on it, then used that web interface to upload compiled ESPHome code.

Apologies to ask a potentially stupid question, but perhaps someone in this thread can help me - is it possible to use the sonoff mini S1/S2 input to read the state of an up / down switch for my roller shutters? I kind of understand that it’s only one GPIO so probably not possible, just wanted to check :slight_smile:

You don’t need to pass by Tasmota, you can prepare a esphome bin, compile, download binary and upload it through the DIY interface. I did it for my 12 sonoff mini in my home :slight_smile:

1 Like

I used the same method created a mini bin file with only wifi, uploaded that in DYI mode, then OTA for the rest.