ESPHome compatible 3-way light switches?

Does anybody know of any non-Tuya MCU based “3-way” light switches (US) that are compatible with ESPHome? I tried the generic Tuya based KS-602F 3-way, which I believe is the same as the Moes version I see mentioned elsewhere. But these use the Tuya MCU serial protocol and all you can do with them is turn it off and on. You don’t have access to the button, relay, or leds directly like on the normal Tuya or Sonoff switches. This prevents me from doing things like double-clicks, changing the led behavior, etc. Didn’t know if anybody else had run across a more traditional direct ESP controlled 3-way switch…

Why do you need a 3 way switch? Once your light is controlled by ha, your wall switch doesn’t even need to electrically connect to the lamp.

1 Like

I prefer autonomous local control of the switch(es) in case my HA server isn’t running. While not hard to do what you are suggesting, I would prefer a drop in replacement for the existing 3-way switch instead of rewiring the power feed, abandoning one of the traveler wires, and generally creating a system that someone who comes behind me would have a difficult time figuring out.

For non critical fictions HA is amazing (turn on the light when motion is sensed been 5:00 and sunrise). But the core, non-smart, functionality (I flip on a light switch and the light turns on) it needs to work without a hub or internet connection.

3 Likes

All my 3way (2 switches - 1 (group of) light(s)) and 4way (3 switches - 1 light) use a shelly1. I use them with Tasmota, but I’m sure they can be used with esphome too.

That’s a possibility. I looked up the Shelly 1 and it could work for basic on/off functionality, but I don’t get my double-click function at the light switch without rewiring the switches and modifying them to be momentary, which introduces the non-standard wiring I’m trying to avoid.

What I’m trying to do, and maybe there is another way to accomplish this, is keep all the light circuits wired according to normal US electrical standards and their local, walk up, functionality as they were originally (I press the light switch and it toggles that light circuit) without any internet or HA server availability.

But I want to add additional smart functionality at the local switch. So, for example, I can double-click or long-press the switch at the top of the stairs and all the basement lights turn off. This would require HA to actually be running and I’m fine with the additional functionality being dependant on additional services.

I think user interface is incredibly important and needs to fit into the normal workflow if how the intended user will operate the technology. There is a place for, say using a smartphone app to do what I want, like when I’m in another room or not at home, but I need my kids or guests, who don’t have access to an app to be able to take advantage of the smart functionality through easy to access and operate means.

All that to say, replacing my 3-way switch with a smart one would give me that ability while meeting my other goals and would be a simple, elegant solution. But I’m open to alternate suggestions too. I have thought about a separate standalone switch just for the “smart” functionality, but I’m also trying to avoid battery-operated devices (:stuck_out_tongue_closed_eyes:) and cutting new holes in the wall to install dummy wired switches. Shoot, maybe I just need to loosen up on my requirements… :wink:

Has anyone tried the Martin Jerry 3-way switch? Does it use the Tuya MCU communication protocol? And now I’m wondering at my assumption that the Moes 3-way switch uses the Tuya MCU as well. Can anyone confirm if either of these switches use that protocol?

1 Like

Good find! I looked up the Moes one on that site and it looks similar. I’ll have to try one of those! Thanks!

1 Like

I have tried several 3 way Tuya switches with Tasmota and can say without a doubt that the Martin Jerry ST01 is the way to go. It is a drop in replacement and works without any crazy configs with Tasmota.

Most of the others require a bunch of complicated rules and they get “confused” about whether the light is on or off. In fact, I have 5 other 3 ways that I plan to trash because the Martin Jerry’s work that much better.

If you have any more questions I would be happy to answer what I can. You should also check out the video “Martin Jerry 3 Way Smart Switch - The Smarter 3 Way - Martin Jerry ST01” on youtube by digiblur.

Here are the configurations/rules that I use if you want to use them:
Template - {“NAME”:“MJ 3Way Switch”,“GPIO”:[255,255,255,255,52,53,0,0,21,9,157,255,0],“FLAG”:0,“BASE”:18}

switchmode1 5

rule1 on power1#state=0 do backlog ledpower1 0; ledpower2 1 endon on power1#state=1 do backlog ledpower1 1; ledpower2 0 endon

rule1 1

1 Like

Sorry, I just noticed that this was in the ESPHome section, so you may not be running tasmota, but I still stand by my comments since I think everything should map over to ESPHome easily.

@Aaron_Bone No problem! The Tasmota configs are very helpful when translating it to ESPHome. Thanks for sharing and confirming the Martin Jerry is a good switch to try!

1 Like

Did you ever try the MJ ST01? Based on the wiring diagram from the MJ webpage, I don’t see how it could determine state if the dumb switch is ever used.

Aaron,
I had to do the 3 wire cut to stabilize load detection. Unfortunately, based on the wiring diagram, I don’t think that the ST01 (I have 2) looks like it would be able to monitor state. The load is on the dumb switch, so there is no monitoring those changes. Is this consistent with your experience?
Thanks!

I know it’s a little late (just saw this post) but I have been using the Moes 3-way switches with ESPHome for a while now and they work great! If anyone is interested, here is the .yaml

1 Like

I ended up grabbing a Moes 3-way switch instead of the MJ. It actually has a current sensor built into the unit that senses when the light is on (it’s a binary sensor, it doesn’t actually report current used, just off/on).

So, the reported state of the light will change regardless if you use an external dumb switch in the circuit or the internal relay toggles. There is a slight (<1s) delay I have noticed when detecting a state change when using an external dumb switch. Not a big deal, but just an observation.

This is probably more complicated than you need (I have some multi-click stuff going on), but here is the code I ended up using on my switch.

The binary_sensor: / id: power_sensor is the current sensor and it sets the LED state based on if the light is actually on or not (vs if the relay is on or not). The rest of the magic happens in the template switch. The lambda section uses the power sensor to report to HA if the light is on or not. The if code in the turn_on/off_action sections are to allow HA to actually turn the light on or off vs just flipping the relay without respect to if the light is actually on or not.

Your GPIO pins might be different with the MJ, but the concepts will be the same.

I grabbed most of this code from a random google search, which I didn’t save, so I can’t reference the original source. But thanks to whoever I grabbed it from!

Full YAML:

substitutions:
  # https://esphome.io/guides/configuration-types.html#substitutions
  device_name: kitchencounterlights        # hostname & entity_id
  friendly_name: Kitchen Counter Lights    # Displayed in HA frontend
  icon: mdi:ceiling-light

<<: !include .common.yaml # defines standard wifi, api, logging, etc.

esphome:
  # https://esphome.io/components/esphome
  name: ${device_name}
  platform: ESP8266
  board: esp01_1m

sensor:
  # Uptime sensor
  - platform: uptime
    name: "${friendly_name} Uptime"

binary_sensor:
  - platform: status
    name: "${friendly_name} Connectivity"
    
  - platform: gpio
    pin:
      number: GPIO13
      inverted: True
    id: button_id
    on_multi_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: dbl_click
    # Long Click:
    - timing:
      - ON for 1s to 2s
      - OFF for at least 0.3s #0.5s
      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
    - timing:
      - ON for at most 1s
      - OFF for at least 0.3s #0.5s
      then:
        - switch.toggle: relay
        - logger.log: "Single Short Clicked"
        - homeassistant.event:
            event: esphome.${device_name}
            data:
              title: single_click


  - 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:
  - platform: gpio
    id: red_led
    pin:
      number: GPIO5
      inverted: True

  - platform: gpio
    pin: GPIO12
    id: relay
    restore_mode: RESTORE_DEFAULT_OFF

  # 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

status_led:
  # https://esphome.io/components/status_led
  pin:
    number: GPIO4   # White LED
    inverted: True


# ##################################
# MOES SS01 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)
# ##################################

2 Likes

given the enthusiasm here, I would go forward with the Moes. I would like to salvage the ST01 if I can, but that might depend on Aaron checking back in here.

I just looked up the MJ ST01 3-Way pinouts on the Tasmota template linked above and the match up exactly with the Moes ones I am using. (They just have the power/current sensor labeled LedLink for some reason and are using a switch instead of a button.) So, you could use the YAML I posted earlier with your MJ and it should just work. Make sure you include the stuff I have in my .common.yaml include file, like api:, wifi:, and such.

Hey, sorry I’m late to the party. The MJ ST01 also has a current sensor and has detected state in every configuration that I have put it in.

It goes through a detection sequence when initially turned on to detect current state, I have never had an invalid state. The traveler wires should flip when the other dumb switch is used, so it should be able to get the state changes there too.

On the Moe’s that I used, it would get confused all them time. I actually ended up setting up a long press action to reverse the state without toggling the relay because.it was out of sync so often.

Let me know if there are any specific questions you all have, happy to help!

Great that you had time to reply. You might be the only person that I have found that has successfully deployed the ST01. Some questions:

  1. Do you have the ST01 on the live side? Traditional 3way on the load side?
  2. Did you tasmotize the switch?
  3. Did you do the 3 cuts described elsewhere on the ST01 electronics?

So I have done all of the above. Used the Blackadder template. Everything works fine and light shows up in lovelace using discovery if I only use the ST01. If I use the downstream manual switch it has no clue. I traced. I am confident that the ST01 is on the live side (I transfered it there, as live and load previously were in the same box). I am also confident in the load (I live wire tested it). Any ideas? Maybe you could detail your experience further so I can figure out what I am doing wrong. I have to be close!