Guide: Tasmota Switches

← Back to Projects

Unlocking Switches with Tasmota for Multi-Click Actions

This guide outlines how to flash custom Tasmota firmware onto a commercial smart switch (like those from Merkury/Walmart) to gain local control and create powerful multi-click automations in Home Assistant.

Disclaimer: This process involves opening electronic devices and overwriting their factory firmware. There is a risk of damaging your device. Proceed at your own risk and always disconnect the device from mains power before opening it.

Part 1: Flashing Tasmota

The flashing process can vary greatly between devices. Before purchasing or attempting to flash any device, it is crucial to verify its compatibility. The Blakadder Tasmota Device Repository is the definitive community-run database for this.

Once you have confirmed your device is compatible, you can proceed. The most common method for Tuya devices is using a tool like Tasmotizer. This typically involves soldering temporary wires to the ESP8266 chip's serial pins inside the switch to connect your USB-to-serial adapter.

[Diagrama de pines del ESP8266 para flasheo]

Part 2: Configuring Multi-Press Actions in Tasmota

Once Tasmota is installed, connect it to your Wi-Fi and access its web interface. To enable multi-press functionality, you need to use Tasmota's powerful `Rules` feature. First, access the Tasmota Console.

  1. Decouple the button from the relay: This prevents a single click from always toggling the physical relay, giving Home Assistant full control.
    SetOption73 1
  2. Create the rules: We will create rules that publish a specific MQTT message for each type of click.
    Rule1 ON Button1#State=10 DO Backlog publish stat/tasmota_switch/BUTTON1 SINGLE ENDON ON Button1#State=11 DO Backlog publish stat/tasmota_switch/BUTTON1 DOUBLE ENDON ON Button1#State=12 DO Backlog publish stat/tasmota_switch/BUTTON1 TRIPLE ENDON ON Button1#State=3 DO Backlog publish stat/tasmota_switch/BUTTON1 HOLD ENDON
  3. Enable the rule:
    Rule1 1

This rule tells the switch to send `SINGLE`, `DOUBLE`, `TRIPLE`, or `HOLD` to the MQTT topic `stat/tasmota_switch/BUTTON1` depending on how the button is pressed.

Part 3: Home Assistant Automation

Now, we'll create an automation in Home Assistant to listen to these MQTT messages and perform different actions.

[Captura de pantalla de la automatización en la GUI de HA]

YAML Configuration

Go to Settings > Automations & Scenes and create a new automation. You can build it in the GUI or paste the following YAML code by clicking the 3-dot menu and selecting "Edit in YAML".


# automations.yaml

- alias: "Control de Oficina con Interruptor Multi-Clic"
  id: office_control_multi_click_switch
  trigger:
    - platform: mqtt
      topic: "stat/tasmota_switch/BUTTON1"
  action:
    - choose:
        # Acción para 1 Clic: Alternar la luz principal
        - conditions:
            - condition: trigger
              payload: "SINGLE"
          sequence:
            - service: light.toggle
              target:
                entity_id: light.luz_principal_oficina

        # Acción para Mantener Presionado: Encender el ventilador
        - conditions:
            - condition: trigger
              payload: "HOLD"
          sequence:
            - service: switch.turn_on
              target:
                entity_id: switch.ventilador_oficina

        # Acción para 3 Clics: Activar Escena "Modo Trabajo"
        - conditions:
            - condition: trigger
              payload: "TRIPLE"
          sequence:
            # 1. Encender la PC vía Wake-on-LAN
            - service: wake_on_lan.send_magic_packet
              data:
                mac: "AA:BB:CC:DD:EE:FF" # Reemplaza con la MAC de tu PC
            # 2. Encender el ventilador
            - service: switch.turn_on
              target:
                entity_id: switch.ventilador_oficina
            # 3. Activar una escena de luces
            - service: scene.turn_on
              target:
                entity_id: scene.escena_trabajo_concentrado
      # Acción por defecto (opcional): podría ser para 2 clics
      default:
        - service: light.toggle
          target:
            entity_id: light.lampara_escritorio
            

With this setup, one physical switch is transformed into a powerful, multi-functional control panel for any device or scene in your Home Assistant instance.


References and Resources

For more in-depth information, explore these official resources and community guides.