ESPHome compatible 3-way light switches?

I may not sure if I have them on the live side or load side to be honest. I just took out the old switch and hooked into live and neutral then hooked into the travelers the same way the last switch was hooked up. Mine are all running the latest tasmota. I pulled the config from one of the guides that digiblur had posted, I think it was in the video that I mentioned earlier.

I am not familiar with the 3 wire cut you mentioned, I didn’t do anything like that though.

If you haven’t watched it yet, I would check the video I mentioned from @digiblur . He goes into a lot of detail and he’s responsive if you comment on YouTube as well.

I’ve deployed a few of them but I’ve also run into issues in some cases as every location is different. I will say the best deployment is with the smart switch as the first switch in the line then the dumb switch as the second.

Any thoughts on why it loses track of whether the load is on when you use the dumb switch? Is there something trivial that I am missing?

Is it the first switch in the chain? Is the load too low? What software are you using?

You and I have discussed this on discord (it must all blur together). I put an incandescent on the load to increase the resistance, but there are 5 other LEDs on there. I did the 3 wire cutting from the link you provided (some google page). Using TASMOTA, the LED light rule, using as a light rather than a button, and hassio discovery. Everything works great if I just use the smart switch, but state is not reported correctly if I use the downstream dumb switch. Can you confirm that you get correct state reporting in HASSIO?

OK, I finally hooked up 2 more 3 ways this afternoon as a confirmation/test. I setup a Martin Jerry ST01 on each end of a 3 way circuit to make sure that they stay in sync between both the live and load end. There is no integration between them, so as far as each one knows, it is a dumb switch on the other end.

Everything is hooked up according to the diagram below (travelers tied together, live/hot connected on one switch and switched/light on the other). I have 6 LED bulbs on this circuit. I am not sure of the wattage, but I would assume that it would be in the ballpark of 40 watts total.

Both switches were flashed via Tuya Convert and have never been opened or had any hardware modifications of any kind done. Firmware is stock tasmota and the only configuration done was the device template and rule below.

As far as I can tell, everything is working perfectly for now. I can use either switch and the other is updated. I can control either switch via the web interface of the switch or Home Assistant and they stay in sync. I haven’t found a way yet to get them to get out of sync.

Firmware: 8.1.0(tasmota)
Device Template: {“NAME”:“MJ 3 Way”,“GPIO”:[0,0,0,0,52,53,0,0,21,9,157,0,0],“FLAG”:0,“BASE”:18}
Rule1: on power1#state=0 do backlog ledpower1 0; ledpower2 1 endon on power1#state=1 do backlog ledpower1 1; ledpower2 0 endon
Home Assistant YAML:

light:
  - platform: mqtt
    name: Basement 3way 1
    state_topic: "stat/basement3way1/POWER"
    command_topic: "cmnd/basement3way1/POWER"
    availability_topic: "tele/basement3way1/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false
    
  - platform: mqtt
    name: Basement 3way 2
    state_topic: "stat/basement3way2/POWER"
    command_topic: "cmnd/basement3way2/POWER"
    availability_topic: "tele/basement3way2/LWT"
    qos: 1
    payload_on: "ON"
    payload_off: "OFF"
    payload_available: "Online"
    payload_not_available: "Offline"
    retain: false

I will keep them both connected like this for a couple weeks to make sure that things keep working. Eventually I am going to replace one of them with a dumb switch though so I can use the smart switch elsewhere in the house.

Let me know if there is anything else that I can test for you!

1 Like

@coderanger I am using this esphome code of yours. My issue is …on lovelace, I always see this switch ON even they are OFF. did you had this issue?
I am using one smart swich and one dumb.

@TerroBladeZ No, I don’t have that issue. HA correctly reports the state of the light no matter if you use the smart switch, the dumb switch, or HA to turn it off or on.

The magic happens with the power_sensor and the associated template switch (excerpt from my code below). The template switch lambda: section is what reports back to HA the state of the light (vs. the state of the relay).

Sometimes the manufacturers switch things up, so you might need to do a GPIO investigation and make sure that is still the right pin for the power sensor. Flash Tasmota on it temporarily (use an old 7.0 version you can flash away from or be aware of the special parameter you have to change to load something other than Tasmota on it in newer versions). This video is a good tutorial on how to discover the GOIP pins: https://youtu.be/m_O24tTzv8g

binary_sensor:
  - platform: gpio
    # https://esphome.io/components/binary_sensor/gpio.html
    id: power_sensor
    pin:
      number: GPIO14
      inverted: True
    filters:
      - delayed_off: 50ms
    on_press:
      - switch.turn_on: red_led
    on_release:
      - switch.turn_off: red_led

switch:
  # present the state of the switch in HA based on the sensor
  - platform: template
    # https://esphome.io/components/switch/template.html
    name: ${friendly_name}
    id: ${device_name}
    icon: ${icon}
    lambda: |-
      if (id(power_sensor).state) {
        return true;
      } else {
        return false;
      }
    # https://esphome.io/guides/automations.html#if-action
    turn_on_action:
        - if:
            condition:
              binary_sensor.is_off: power_sensor
            then:
              - switch.toggle: relay
    turn_off_action:
        - if:
            condition:
              binary_sensor.is_on: power_sensor
            then:
              - switch.toggle: relay

@coderanger I am using MOES SS01 3-Way Light Switch. I believe your code is for the same switch so pinouts should be the same.

With the ss01 switch has anyone else had issues flashing it with Tuya convert? I’ve been able to flash all other switches but this one is giving me issues.

If it has the latest firmware, tuya-convert works once again not anymore :frowning: Tuya closed the hole again.

I’m trying using a TreatLife ss02 which I’ve confirmed uses the same GPIO pins as the Moes config shared by @coderanger and @mjoshd. (I enabled the local API, and commented out internal: True so each would appear in the local web interface)

I checked all of the defined GPIOs (per the GPIOs in the Tasmota template and the functions you both show they map to for espHome) except the sensor (I exposed it so I could see it’s state via the API, but I don’t think it would be valid to test in this way), but it’s the only one that’s left, so confident it’s the same.

I don’t have it installed, just mocked up partially, with a power cable. With the hot lead connected to a live feed (via the power cable) and the Travelers disconnected… I’m getting the same symptom TerroBladeZ mentioned. The sensor always shows the power state to be ON. So HA always shows the state as ON regardless of how it’s toggled.

There is no dumb switch in the mix, but the travelers are not connected, so I expected power state to toggle.

If anyone has any ideas lmk

I know you know, and everyone else knows, but I’m going to say it anyway. Electricity is dangerous. Be very careful!

Having said that…

I am not an electrician by any means but I I’m fairly certain you need to mock up the full circuit, including traveler wires, for the power sensor to actually work and show state changes. On that note, be aware that there are multiple ways to wire up a three-way switch so you’ll want to ensure your mock-up is done the same way as what is in your walls.

Also, it might help to actually put it into HA temporarily via the integration (after you’re done testing you can remove it, un-comment internal: true, and re-add it to clean up the extra entities that were exposed). I find that the local web interface is very slow to show state changes, if at all, and viewing states in HA is nearly instantaneous.

Best of luck!

Yeah, I actually put a meter on the travelers after I made the post, and they were hot.

One of them was essentially the same as “Line” the other was a few volts below. So mocking up a full circuit is on my near term to-do list.

I do have it integrated into HA, I just exposed the local API so I could temporarily verify GPIOs (could have done this in HA as well, this was just more convenient)

Thanks

1 Like

Just to button this up…

I did get these to work. I mocked up a full 3 way real quick and the Treatlife SS02 switches worked with the templates provided by others previously in this post. Testing with Travelers open (not connected to anything) isn’t valid, The sensor would always show on, but with a real circuit built out they worked as expected, both in the mock-up and installed.

1 Like

I ended up using Jasco’s on all my 3ways, and shellies (w/ esphome) on my singles.

I have a SS02 and have been fighting this for a while now. Did you do this via ESPHome or via tasmota? Could you share how you got yours working? I used tasmota and it’s showing up as 2 toggles. The traveler shows as toggle 1 and the actual 3 way switch is toggle 2. They don’t sync up when the traveler switch is turned on or off and the whole thing is a mess.

Would love to get this working the way it should.

I have the SS01 Treatlife 3-way switching working with ESPHome. It should be pretty much the same as SS02 other than the white LED being rectangle. Here is the excerpt of the yaml (I only include the parts that are specific to the switch).

Note that this yaml also exposes the button as a binary sensor for the HA/NodeRED to handle long-press actions.

substitutions:
  device_name: sw_2f_stair
  friendly_name: Stair 2 Light
  icon: "mdi:lightbulb"

# Insert all the usual config here
# esphome:
# wifi:
# api:
# ota:

# Begin SS01 3-way config
status_led:
  pin:
    number: GPIO5  # Red LED
    inverted: True

binary_sensor:
  - platform: gpio
    id: button
    name: ${friendly_name} Button
    pin:
      number: GPIO13
      mode: INPUT_PULLUP
      inverted: True
    on_multi_click:
      # Single press, allow long press action to be handled by the server
      - timing:
        - ON for at most 1s
        - OFF for at least 0.1s
        then:
          - switch.toggle: relay
  - platform: gpio
    id: power_sensor
    pin:
      number: GPIO14
      inverted: True
    filters:
      - delayed_off: 50ms
    on_press:
      - light.turn_off: white_led
    on_release:
      - light.turn_on: white_led

output:
  - platform: gpio
    id: white_led_output
    pin:
      number: GPIO4
      inverted: True

light:
  - platform: binary
    id: white_led
    output: white_led_output
    restore_mode: RESTORE_DEFAULT_ON

switch:
  - platform: gpio
    id: relay
    pin: GPIO12
  - platform: template
    id: the_switch
    name: ${friendly_name}
    icon: ${icon}
    lambda: |-
      if (id(power_sensor).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
      - if:
          condition:
            binary_sensor.is_off: power_sensor
          then:
            - switch.toggle: relay
    turn_off_action:
      - if:
          condition:
            binary_sensor.is_on: power_sensor
          then:
            - switch.toggle: relay
3 Likes

Oh man, it works! Thank you so so much. This is a huge help.

1 Like

With all of the posts on here already, figured why not.

Below is my esphome Treatlife 3-way switch, copy and paste yaml. It gives event triggers to use in home assistant (Automation added at the bottom).

As for the wiring of the Treatlife. I have found it better to connect the hot wire to the far left red traveler wire, light/load to the black load wire and, the 3 way traveler wire to the red traveler wire in the middle of the switch. When uploading new code to does not cycle the relay.

Edit: Updated the code, do to an incident that triggered the white led to come on when the light was on. Now the white led will only come on when the switch is off. And added the home assistant switch to light yaml.

# ##################################
# Treatlife 3-Way Light Switch
# ##################################
# D2 GPIO04: white led (inverted)
# D1 GPIO05: red led (inverted)
# D6 GPIO12: relay
# D7 GPIO13: button (inverted)
# D5 GPIO14: power/usage sensor (inverted)
# ##################################


substitutions:
  # https://esphome.io/guides/configuration-types.html#substitutions
  device_name: treatlife_3_way_light_switch
  friendly_name: Treatlife 3 Way Light Switch
  icon: "mdi:light-switch"
  
esphome:
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  
  ap:
    ssid: ${device_name}
    password: !secret esphome_ap_password
  
captive_portal:

# Enable logging
logger:

# Enable Home Assistant API
api:
  password: !secret esphome_api_password
  
ota:
  password: !secret esphome_ota_password

status_led:
  # https://esphome.io/components/status_led
  pin:
    number: GPIO5   # Red LED
    inverted: True

binary_sensor:
  - platform: gpio
    id: power_sensor
    pin:
      number: GPIO14
      inverted: True
    filters:
      - delayed_off: 50ms
    on_press:
      - light.turn_off: white_led
    on_release:
      - light.turn_on: white_led
    internal: True

  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    id: button
    on_multi_click:
   # Single Click:
    - timing:
      - ON for at most 1s
      - OFF for at least 0.3s
      then:
        - switch.toggle: ${device_name}
        - logger.log: "Single Short Clicked"
        - homeassistant.event:
            event: esphome.${device_name}
            data:
              title: single_click 
   # Double Click:
    - timing:
      - ON for at most 1s
      - OFF for at most 1s
      - ON for at most 1s
      - OFF for at least 0.2s
      then:
        - logger.log: "Double Clicked"
        - homeassistant.event:
            event: esphome.${device_name}
            data:
              title: double_click
    # Long Click:
    - timing:
      - ON for 1s to 2s
      - OFF for at least 0.3s
      then:
        - logger.log: "Single Long Clicked"
        - homeassistant.event:
            event: esphome.${device_name}
            data:
              title: long_click
    - timing:
      - ON for at least 2.2s
      then:
        - logger.log: "Click and Hold"
        - homeassistant.event:
            event: esphome.${device_name}
            data:
              title: hold
    internal: True
    
light:
  - platform: binary
    id: white_led
    output: led_1
    restore_mode: RESTORE_DEFAULT_ON
    internal: True
    
output:
  - platform: gpio
    id: led_1
    pin:
      number: GPIO4
      inverted: True

switch:
  - platform: gpio
    id: red_led
    pin:
      number: GPIO5
      inverted: True
    internal: True
    
  - platform: gpio
    pin: GPIO12
    id: relay
    restore_mode: RESTORE_DEFAULT_OFF
    internal: True
  
  - platform: template
    name: ${friendly_name}
    id: ${device_name}
    icon: ${icon}
    lambda: |-
      if (id(power_sensor).state) {
        return true;
      } else {
        return false;
      }
    turn_on_action:
        - if:
            condition:
              binary_sensor.is_off: power_sensor
            then:
              - switch.toggle: relay
    turn_off_action:
        - if:
            condition:
              binary_sensor.is_on: power_sensor
            then:
              - switch.toggle: relay

Convert it from a basic switch to a light in Home Assistant

light:
  - platform: switch
    name: Treatlife Light Switch
    entity_id: switch.treatlife_3_way_light_switch

Automation that uses the triggered events

automation:
- alias: treatlife_long_press_on
  trigger:
  - event_data:
      title: long_click
    event_type: esphome.treatlife_3_way_light_switch
    platform: event
  condition: []
  action:
  - entity_id: group.all_lights
    service: light.turn_on
  mode: single

- alias: treatlife_double_click_off
  trigger:
  - event_data:
      title: double_click
    event_type: esphome.treatlife_3_way_light_switch
    platform: event
  condition: []
  action:
  - entity_id: group.all_lights
    service: light.turn_off
  mode: single
1 Like