Home Assistant Community

EspHome sonoff 2 way switch functionality (3 way US) automation

sonoff
automation
esp8266
Tags: #<Tag:0x00007fcf4b781d70> #<Tag:0x00007fcf4b780fd8> #<Tag:0x00007fcf4b7806c8>
#1

Ok,
so I thought I would add a quick post, to possibly help someone trying to create a 2 way (i.e 2 switches 1 light ) (or 3 way) depending on which side of the pond you are, using Sonoff T1’s and EspHome . I did ask the question in this thread here and I got a great answer from @Petrica on using home assistant to automate the 2 way switch .

Through a little trial and error I managed to incorporate this automation in the Sonoff configs and utilise the homeassitant service call to do the switching for me.

esphome:
  name: hallway
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: '*************'
  password: '*************'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff Hallway Touchpad 1"
    on_press:
      - switch.toggle: relay_1
  - platform: gpio
    pin:
      number: GPIO9
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff Hallway Touchpad 2"
    on_press:
      then:
        - homeassistant.service:
            service: switch.toggle
            data: {"entity_id": "switch.sonoff_landing_relay"}
          
  - platform: status
    name: "Sonoff Hallway Status"

switch:
  - platform: gpio
    name: "Sonoff Hallway Relay 1"
    pin: GPIO12
    id: relay_1
  - platform: gpio
    name: "Sonoff Hallway Relay 2"
    pin: GPIO5
    id: relay_2

output:
  # Register the blue LED as a dimmable output ....
  - platform: esp8266_pwm
    id: blue_led
    pin: GPIO13
    inverted: True

light:
  # ... and then make a light out of it.
  - platform: monochromatic
    name: "Sonoff Hallway Blue LED"
    output: blue_led
    internal: true
    id: blue_led_light

this uses the second gang touchpad of the 2 gang switch in the hallway to utilise the homeassistant service call and toggle the landing light relay.

esphome:
  name: landing
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: '****************'
  password: '***************'

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:

binary_sensor:
  - platform: gpio
    pin:
      number: GPIO0
      mode: INPUT_PULLUP
      inverted: True
    name: "Sonoff Landing Touchpad"
    on_press:
      - switch.toggle: relay_1
  - platform: status
    name: "Sonoff Landing State"
  - platform: gpio
    pin:
      number: GPIO12
    name: "Sonoff Automation toggle"
    on_state:
      then: 
        - homeassistant.service:
            service: switch.toggle
            data: {"entity_id": "switch.sonoff_hallway_relay_2"}

switch:
  - platform: gpio
    name: "Sonoff Landing Relay"
    pin: GPIO12
    id: relay_1

output:
  # Register the blue LED as a dimmable output ....
  - platform: esp8266_pwm
    id: blue_led
    pin: GPIO13
    inverted: True
    
light:
  # ... and then make a light out of it.
  - platform: monochromatic
    name: "Sonoff Landing Blue LED"
    output: blue_led
    internal: true
    id: blue_led_light

this then uses the state change of the gpio that the relay on landing uses and toggles the switch in the hallway this is essential so that they are both in sync.

I hope this helps someone

@Ottowinter I don’t know if this is something that you would add to your site if you find it useful .