Hello everyone!

I wonder if anyone could suggest the approach for this idea. I have 27 Sonoffs basic with GPIO14, TX and RX soldered with wires connected to the physical light switches. Everything works perfectly on Tasmota but now I need to set functions to TX and RX on Home Assistant, total of 54 commands (TOGGLE), no need for POWER1 TOGGLE since it is already configured on each light entity created. Also I want to use the HOLD message, so it will result on 135 commands (including POWER1 topic).

What do you guys think it would be the best approach? Create 135 automations looking the MQTT message and executing a script? Create 135 MQTT switches?

Something like this:

**Total of 27 relays:**

- 81 physical switches
- 54 TOGGLE commands
- 81 HOLD commands

It would be very nice to have it on a single automation so the action could identify the trigger and execute a scriptâ€¦

Here are all topic states:

```
stat/s_1_luz_tv/POWER1
stat/s_1_luz_escada/POWER1
stat/s_1_sala_luz_corredor/POWER1
stat/s_1_sala_luz_mesa/POWER1
stat/s_1_sala_luz_escritorio/POWER1
stat/s_1_cozinha_luz_principal/POWER1
stat/s_1_cozinha_luz_fogao/POWER1
stat/s_1_cozinha_luz_area_serviĂ§o/POWER1
stat/s_1_quartos_2_luz_principal/POWER1
stat/s_1_quartos_2_luz_cabeceira/POWER1
stat/s_1_banheiros_2_luz_principal/POWER1
stat/s_1_banheiros_2_luz_espelho/POWER1
stat/s_1_quartos_1_luz_armario/POWER1
stat/s_1_quartos_1_luz_cabeceira/POWER1
stat/s_1_banheiros_1_luz_principal/POWER1
stat/s_1_banheiros_1_luz_espelho/POWER1
stat/s_1_banheiros_1_luz_mictorio/POWER1
stat/s_2_sala_luz_tv/POWER1
stat/s_2_sala_luz_escada/POWER1
stat/s_2_sala_luz_principal/POWER1
stat/s_2_sala_luz_mesa_jantar/POWER1
stat/s_2_sala_luz_balcao/POWER1
stat/s_2_sala_luz_acesso_terraco/POWER1
stat/s_2_cozinha_luz_principal/POWER1
stat/s_2_banheiro_luz_principal/POWER1
stat/s_2_terraco_luz_principal/POWER1
stat/s_2_terraco_luz_deck/POWER1
stat/s_1_luz_tv/POWER2
stat/s_1_luz_escada/POWER2
stat/s_1_sala_luz_corredor/POWER2
stat/s_1_sala_luz_mesa/POWER2
stat/s_1_sala_luz_escritorio/POWER2
stat/s_1_cozinha_luz_principal/POWER2
stat/s_1_cozinha_luz_fogao/POWER2
stat/s_1_cozinha_luz_area_serviĂ§o/POWER2
stat/s_1_quartos_2_luz_principal/POWER2
stat/s_1_quartos_2_luz_cabeceira/POWER2
stat/s_1_banheiros_2_luz_principal/POWER2
stat/s_1_banheiros_2_luz_espelho/POWER2
stat/s_1_quartos_1_luz_armario/POWER2
stat/s_1_quartos_1_luz_cabeceira/POWER2
stat/s_1_banheiros_1_luz_principal/POWER2
stat/s_1_banheiros_1_luz_espelho/POWER2
stat/s_1_banheiros_1_luz_mictorio/POWER2
stat/s_2_sala_luz_tv/POWER2
stat/s_2_sala_luz_escada/POWER2
stat/s_2_sala_luz_principal/POWER2
stat/s_2_sala_luz_mesa_jantar/POWER2
stat/s_2_sala_luz_balcao/POWER2
stat/s_2_sala_luz_acesso_terraco/POWER2
stat/s_2_cozinha_luz_principal/POWER2
stat/s_2_banheiro_luz_principal/POWER2
stat/s_2_terraco_luz_principal/POWER2
stat/s_2_terraco_luz_deck/POWER2
stat/s_1_luz_tv/POWER3
stat/s_1_luz_escada/POWER3
stat/s_1_sala_luz_corredor/POWER3
stat/s_1_sala_luz_mesa/POWER3
stat/s_1_sala_luz_escritorio/POWER3
stat/s_1_cozinha_luz_principal/POWER3
stat/s_1_cozinha_luz_fogao/POWER3
stat/s_1_cozinha_luz_area_serviĂ§o/POWER3
stat/s_1_quartos_2_luz_principal/POWER3
stat/s_1_quartos_2_luz_cabeceira/POWER3
stat/s_1_banheiros_2_luz_principal/POWER3
stat/s_1_banheiros_2_luz_espelho/POWER3
stat/s_1_quartos_1_luz_armario/POWER3
stat/s_1_quartos_1_luz_cabeceira/POWER3
stat/s_1_banheiros_1_luz_principal/POWER3
stat/s_1_banheiros_1_luz_espelho/POWER3
stat/s_1_banheiros_1_luz_mictorio/POWER3
stat/s_2_sala_luz_tv/POWER3
stat/s_2_sala_luz_escada/POWER3
stat/s_2_sala_luz_principal/POWER3
stat/s_2_sala_luz_mesa_jantar/POWER3
stat/s_2_sala_luz_balcao/POWER3
stat/s_2_sala_luz_acesso_terraco/POWER3
stat/s_2_cozinha_luz_principal/POWER3
stat/s_2_banheiro_luz_principal/POWER3
stat/s_2_terraco_luz_principal/POWER3
stat/s_2_terraco_luz_deck/POWER3
```

I have a working singe automation for a Xiaomi Cube that goes like this:

```
- alias: BotĂŁo Xiaomi quarto
trigger:
platform: mqtt
topic: 'zigbee2mqtt/casa_xiaomi_botao_quarto_01'
condition:
condition: template
value_template: "{{ trigger.payload_json.click in ('single','double','triple','quadruple','many','long') }}"
action:
service_template: "script.botao_xiaomi_quarto_01_{{ trigger.payload_json.click }}"
```

I was thinking of something like this, so I could just create all scripts like this: `script.interruptor_s_1_luz_tv_POWER2_TOGGLE`

.

Thanks a lot!