Sonoff T1/T2/T3 UK

Please make sure you have read up about the Sonoff T1 / T2 / T3 and how to flash it with ESPHome.

So lets get straight on with the code

T1

esphome:
  name: my_t1
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: xxx.xxx.xxx.xxx

logger:

api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_1

  - platform: status
    name: "T1 Status"

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

light:
  - platform: binary
    name: "T1"
    id: light_1
    output: relay_1

status_led:
  pin:
    number: GPIO13
    inverted: yes

In the above code block, there is a secrets.yaml file so that you have just one place to change wifi details for all your devices.

The use_address is required because the sonoff T series don’t work with mDNS properly. This means that it will show as off line in the dashboard, and you will need to use the ip address to view the logs or upload new versions of the firmware. You will also need to manually add the device in integrations by IP address. You will need to assign a fixed IP in the above configuratino, or use a fixed IP assigned fro your DHCP server.

See issue #810 for further details.

T2

esphome:
  name: my_t2
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: xxx.xxx.xxx.xxx

logger:

api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_1

  - platform: gpio
    pin:
      number: GPIO9
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_2

  - platform: status
    name: "T2 Status"

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

  - platform: gpio
    pin: GPIO5
    id: relay_2

light:
  - platform: binary
    name: "T2 L1"
    id: light_1
    output: relay_1

  - platform: binary
    name: "T2 L2"
    id: light_2
    output: relay_2

status_led:
  pin:
    number: GPIO13
    inverted: yes

T3

esphome:
  name: my_t3
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  use_address: xxx.xxx.xxx.xxx

logger:

api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_1

  - platform: gpio
    pin:
      number: GPIO9
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_2

  - platform: gpio
    pin:
      number: GPIO10
      mode: INPUT_PULLUP
      inverted: True
    id: button
    on_press:
      then:
        - light.toggle: light_3

  - platform: status
    name: "T3 Status"

output:
  - platform: gpio
    pin: GPIO12
    id: relay_1

  - platform: gpio
    pin: GPIO5
    id: relay_2

  - platform: gpio
    pin: GPIO4
    id: relay_3

light:
  - platform: binary
    name: "T3 L1"
    id: light_1
    output: relay_1

  - platform: binary
    name: "T3 L2"
    id: light_2
    output: relay_2

  - platform: binary
    name: "T3 L3"
    id: light_3
    output: relay_3

status_led:
  pin:
    number: GPIO13
    inverted: yes