Controlling smart devices via NSPanel (Tasmota)

Intro
The Sonoff NSPanel is a fancy little combination of a dual-gang switch and a control panel.
In a previous blog post we flashed the NSPanel with Tasmota so we could run NSPanel LovelaceUI on it.
In this short blog post, I’ll show you how you can detach the buttons from the relais so you can control remote smart device without cutting power to them (or even control devices in a totally different location).
Wiring
The wiring for this install doesn’t really matter. The smart device we want to control can be wired behind the relais, parallel to the NSPanel, or even somewhere completely different.
In my situation, I have a set of IKEA smart bulbs behind relais 1 and a Shelly 2.5 with 2 more lights behind relais 2. So it makes sense I don’t want to cut power to either of these since I want to be able to control either of these seperately (e.g. a Home Assistant automation) as well.
Setup
Let’s define our goals for this configuration:
- The relais should be “on” when the NSPanel is powered on.
- We want to detach the buttons from the relais so we don’t cut power.
- Button presses:
- Pressing button 1 should toggle one of the lights connected to the Shelly 2.5.
- Pressing button 2 should toggle the IKEA smart bulbs.
- Double-pressing either button should toggle the other light connected to the Shelly.
- Tripple-pressing either button should toggle all lights (mainly useful to turn them all of at once).
- Holding a button should toggle the corresponding relais (in case we need to reset a device).

Based on these criteria, we run the following commands in the Tasmota console:
PowerOnState 1
Control power state when the device is powered up.1= power onSwitchMode0 5
Configures both buttons as pushbutton with hold.SetOption73 1
Detach buttons from relays and send multi-press and hold MQTT messages instead.
Sends messages tostat/{devicename}/BUTTON{x}like{"Button1":{"Action":"SINGLE"}}.We’ll handle the toggling of the devices via a Home Assistant automation.
SetOption32 20
Reduce the hold interval from 4 to 2 seconds.
Then add the following rule (in 1 line without linebreaks):Rule1 ON button1#state=3 DO Power1 2 ENDON ON button2#state=3 DO Power2 2 ENDON
This will trigger on a long-press of either button and toggle the corresponding relais.
Active the rule withRule1 1.
And 2 little Quality of Life improvements:
WebButton1 ShellyPwrandWebButton2 Lamp
This will change the names of the buttons in the WebUI.SetOption30 1
Enforce Home Assistant auto-discovery as light.

Finally, the Home Assistant automation to tie it all together:
# We'll use this group for the "toggle all" action
light:
- name: Office lights
unique_id: office_lights
platform: group
entities:
- light.shelly_25_1
- light.shelly_25_2
- light.ikea_bulbs
automation:
- alias: NSPanel buttons
description: Do actions based on NSPanel button presses
triggers:
# BUTTON 1
- alias: Button1 short press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON1
value_template: "{{ value_json.Button1.Action }}"
payload: SINGLE
id: btn1_short
- alias: Button1 double press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON1
value_template: "{{ value_json.Button1.Action }}"
payload: DOUBLE
id: btn1_double
- alias: Button1 triple press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON1
value_template: "{{ value_json.Button1.Action }}"
payload: TRIPLE
id: btn1_triple
# BUTTON 2
- alias: Button2 short press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON2
value_template: "{{ value_json.Button2.Action }}"
payload: SINGLE
id: btn2_short
- alias: Button2 double press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON2
value_template: "{{ value_json.Button2.Action }}"
payload: DOUBLE
id: btn2_double
- alias: Button2 triple press
trigger: mqtt
topic: stat/tasmota_nspanel/BUTTON2
value_template: "{{ value_json.Button2.Action }}"
payload: TRIPLE
id: btn2_triple
actions:
- choose:
# BUTTON 1
- conditions:
- alias: Button1 short press
condition: trigger
id:
- btn1_short
sequence:
- alias: Toggle Shelly2.5 output 1
action: light.toggle
target:
entity_id: light.shelly_25_1
- conditions:
- alias: Button1 double press
condition: trigger
id:
- btn1_double
sequence:
- alias: Toggle Shelly2.5 output 2
action: light.toggle
target:
entity_id: light.shelly_25_2
- conditions:
- alias: Button1 triple press
condition: trigger
id:
- btn1_triple
sequence:
- alias: Toggle all lights
action: light.toggle
target:
entity_id: light.office_lights
# BUTTON 2
- conditions:
- alias: Button2 short press
condition: trigger
id:
- btn2_short
sequence:
- alias: Toggle IKEA bulbs with 0.5s transition
action: light.toggle
target:
entity_id: light.ikea_bulbs
data:
transition: 0.5
- conditions:
- alias: Button2 double press
condition: trigger
id:
- btn2_double
sequence:
- alias: Toggle Shelly2.5 output 2
action: light.toggle
target:
entity_id: light.shelly_25_2
- conditions:
- alias: Button2 triple press
condition: trigger
id:
- btn2_triple
sequence:
- alias: Toggle all lights
action: light.toggle
target:
entity_id: light.office_lights
mode: single

And that concludes this very short and very specific blog post. Perhaps I just wrote this down as a reminder to myself, who knows ;)