pdf-icon

SwitchC6 Home Assistant Integration

Introduction

SwitchC6 is an IoT single-live wire switch controller. It integrates the ESP32-C6-MINI-1 core controller and a magnetic latching relay, supports connecting to electrical load circuits of AC 100 ~ 230V, and helps quickly build IoT smart homes. The controller comes pre-installed with ESP-NOW control firmware, and provides related control protocols and SDKs, allowing users to wirelessly control it with any ESP32 device. The back adopts a rail clip design, making it easy to install on DIN rails, suitable for embedded smart home control, upgrading single-live wire lighting circuits, and other application scenarios.

Preparation

Tip
In this tutorial, the firmware is compiled and uploaded with ESPHome 2025.12.5. If you encounter compile/upload issues, consider switching ESPHome to this version.

Step 1. Create New Device

  • Click the green button in the lower right corner to create a device.

Step 2. Create Device Name

  • Click CONTINUE.

  • Click New Device Setup.

  • Enter the name of the device and click NEXT.

Step 3. Choose Device Type

Tip
Here we use Atom-Lite as the main controller to operate the SwitchC6 relay switch.
  • Click ESP32.

  • Click SKIP.

Step 4. Start Edit YAML File

  • Click EDIT. We can customize device functionality through YAML files.

Device Setup

The following is the core part of the code. Relevant references and explanations are provided below.

Globals Configuration

globals:
  - id: current_cmd
    type: std::string
    restore_value: no
    initial_value: '""'
  - id: response_received
    type: bool
    restore_value: no
    initial_value: 'false'

ESPNOW Configuration

espnow:
  id: espnow1
  auto_add_peer: true
  peers:
    - B4:3A:45:81:EC:70
  on_receive:
    - logger.log:
        format: "Received from: %s = '%s'  RSSI: %d"
        args:
          - format_mac_address_pretty(info.src_addr).c_str()
          - format_hex_pretty(data, size).c_str()
          - info.rx_ctrl->rssi
  on_broadcast:
    - lambda: |-
        std::string response((char*)data, size);
        if(response.find("142B-2F9F-8704") != std::string::npos) {
          ESP_LOGI("main", "Response received from device");
          id(response_received) = true;
        }
    - logger.log:
        format: "Broadcast from: %s = '%s'  RSSI: %d"
        args:
          - format_mac_address_pretty(info.src_addr).c_str()
          - format_hex_pretty(data, size).c_str()
          - info.rx_ctrl->rssi
  on_unknown_peer:
    - logger.log:
        format: "Unknown peer: %s = '%s'  RSSI: %d"
        args:
          - format_mac_address_pretty(info.src_addr).c_str()
          - format_hex_pretty(data, size).c_str()
          - info.rx_ctrl->rssi

Script Configuration

script:
  - id: send_switch_command
    mode: restart
    then:
      - globals.set:
          id: response_received
          value: 'false'
      - repeat:
          count: 40
          then:
            - lambda: |-
                if(id(response_received)) {
                  ESP_LOGI("main", "Stopping - response confirmed");
                  return;
                }
                
                int channel = id(espnow1)->get_wifi_channel();
                std::string cmd = id(current_cmd);
                char data[40];
                snprintf(data, sizeof(data), "B43A-4581-EC70=%s;ch=%d;", cmd.c_str(), channel);
                std::vector<uint8_t> payload(data, data + strlen(data));
                uint8_t addr[6] = {0xB4, 0x3A, 0x45, 0x81, 0xEC, 0x70};
                id(espnow1)->send(addr, payload, [](esp_err_t status) {
                  if(status == ESP_OK) {
                    ESP_LOGV("main", "ESPNow sent");
                  }
                });
            - delay: 100ms

Switch Configuration

switch:
  - platform: template
    name: "SwitchC6"
    optimistic: true
    turn_on_action:
      - globals.set:
          id: current_cmd
          value: '"1"'
      - script.execute: send_switch_command
    turn_off_action:
      - globals.set:
          id: current_cmd
          value: '"0"'
      - script.execute: send_switch_command

Firmware Build

  • Click INSTALL again to flash and wait for it to complete.

  • After making changes, click SAVE and INSTALL in the top-right corner, then choose Manual Download in the popup.

  • After the firmware compilation is complete, click Download and select Factory format(Previously Modern)

Tip
Click SwitchC6 to view the complete example configuration. The first build may take a while, depending on the performance of the Home Assistant host and network quality.

Firmware Upload

  • Connect the device to your host via a USB Type‑C cable. Open ESPHome Web and click CONNECT to connect to the device.

  • Locate the corresponding serial port number

  • Click INSTALL

  • Select the previously compiled firmware to upload.

Tip
Please note that after the download is completed, the device must be reset.

Home Assistant Integration

  • Click Settings -> Device & services to check the device.

  • We can find the corresponding device in the Discover section.

  • After adding the device, the data will be displayed correctly.

  • Finally, we add these entities to the Dashboard, and the following shows their display results.

On This Page