Sonoff Switchman M5 as a smart switch for smart lights

Hi, I would like to use my Sonoff Switchman M5 as a smart switch for the yeelight lamp and not as a power cutter. Installed esphome, configuration as below, I searched the entire forum and google, however, I did not find any relevant clues on this topic.

esphome:
  name: switchman-entrance

esp32:
  board: esp32dev
  framework:
    type: arduino

# Enable logging
logger:

# Enable Home Assistant API
api:
  encryption:
    key: ""

ota:
  password: ""

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Switchman-Entrance"
    password: ""

captive_portal:
    
output:
  - platform: ledc
    pin: 18
    frequency: 1000 Hz
    id: pwm_output
    
  - platform: gpio
    id: relay_1
    pin: 23
    
  - platform: gpio
    id: relay_2
    pin: 19
    
light:
  - platform: monochromatic
    output: pwm_output
    name: "LEDs"
  - platform: status_led
    name: "Swtich state"
    pin:
      number: 5
      inverted: true
    
  - platform: binary
    id: corridor_switch_1
    name: "Left Switch"
    output: relay_1
    
  - platform: binary
    id: corridor_switch_2
    name: "Right Switch"
    output: relay_2

    
binary_sensor:
  - platform: gpio
    id: left_button
    pin:
      number: 4
      mode: INPUT_PULLUP
    on_press:
      - light.toggle: corridor_switch_1
      
  - platform: gpio
    id: right_button
    pin:
      number: 15
      mode: INPUT_PULLUP
    on_press:
      - light.toggle: corridor_switch_2
      

What is your question?

I would guess how to detach buttons from leds, still be able to use buttons to trigger HA trigger for smart bulbs and ideally keep the led indicators for the on/off of the lights?

I think you can’t switch the leds separately. Flashing Tasmota on Sonoff SwitchMan - NotEnoughTech

This is an old topic but it deserves a correct answer.

Disconnecting the buttons from the relays is quite easy:

  • Remove the on_press: action frrom the binary sensor definition. That will disconnect the button from the relay. You can do it for any of the buttons or both, it’s completely your choice.
  • To make the button visible as an entity in Home Assistant, you need to add a name: attribute to the respective binary sensor definiton and give it some name.
  • The config file shown above already has correctly defined binary light entities so the relays are now controlled from the HA only.

I have created a config for the M5 with substitutions and conditions that suit my use case: esphome-configs/switchman-m5-1c.yaml at 775fcd83343ad97f4cfcca35a6431b007d533785 · velijv/esphome-configs · GitHub

substitutions:
  ...
  hass_device_1: light.ceiling

which is the virtual device from HA. And to check if API is connected, toggle this else toggle the relay:


binary_sensor:
  - platform: gpio
    name: Button
    id: ${device_name}_button
    pin:
      number: 0
      inverted: true
    on_click:
      then:
        if:
          condition:
            api.connected:
          then:
            - homeassistant.service:
                service: homeassistant.toggle
                data:
                  entity_id: $hass_device_1
            - light.toggle: ${device_name}_led_red
          else:
            - switch.toggle: ${device_name}_switch

Hi, I’m interested in the M5 and flashing it with ESPhome. Does this method give the ability to decouple the relay and reconnect to the relay manually? I would like to use the m5 with smart lights but have the backup option. Similar to what the Aqara switches do? Thanks.

yes, my code does this automatically - if wifi and api are connected, use the virtual device, if not, use the relay. you can create a template switch that you can manually toggle between the smartlights and relay.

Great, thank you. I’m new to smart switches, smart home etc. hope I can figure it out. I’ll confirm.

Hi Veli, I’m trying to apply this config but getting an invalid YAML Syntax. This is at light.toggle device_name led_red. Also, does this tell the red led to turn on and off with the light? What if I don’t want the red led on? Thanks.

It depends.
On M5 1-gang You can operate LED and Relay individually.
M5 2-gang: Left channel LED & Relay connected on motherboard, Right button - separately.
M5 3-gang: All channels LED’s & Relays wired together.

Pins etc. can check on https://devices.esphome.io/

3 Likes

ESPHome has had many updates, but I tried my old config on Github and it compiles for me with no error

Creating esp32 image...
Successfully created esp32 image.
esp32_create_combined_bin([".pioenvs/m5-1c/firmware.bin"], [".pioenvs/m5-1c/firmware.elf"])
Wrote 0x1a2650 bytes to file /config/.esphome/build/m5-1c/.pioenvs/m5-1c/firmware-factory.bin, ready to flash to offset 0x0

Also, does this tell the red led to turn on and off with the light

Yes, just remove the line if you don’t want that.