Flashing custom firmware like tasmota or esphome and then restoring back to original

@amitxin I tried controlling the relay via writing the command #1000# and #1100# on the serial that connects the two microcontrollers, but the relays don’t respond to the command,

Can you help me establish communication between the STM microcontroller and ESP8266 and also help me with what command to transmit from esp8266 to the STM microcontroller to turn the relay ON and OFF via serial communication between the microcontrollers?

Did you connect ground from whereever you are sending tx signal ?

Yeah I connected GND, 3V3, RX, and TX from the microcontroller to the programming header of the device.

I have tasmota working properly on my 6 node device. Here is what you need

{"NAME":"Tinxy 6 Node","GPIO":[224,0,0,0,225,226,0,0,320,227,228,229,0,0],"FLAG":0,"BASE":18}

And 2 rules, one for controlling the relays and one for manual switch operation

on System#Boot do Baudrate 9600 endon
on Power1#State=1 do SerialSend2 #1100# endon
on Power1#State=0 do SerialSend2 #1000# endon
on Power2#State=1 do SerialSend2 #2100# endon
on Power2#State=0 do SerialSend2 #2000# endon
on Power3#State=1 do SerialSend2 #3100# endon
on Power3#State=0 do SerialSend2 #3000# endon
on Power4#State=1 do SerialSend2 #4100# endon
on Power4#State=0 do SerialSend2 #4000# endon
on Power5#State=1 do SerialSend2 #5100# endon
on Power5#State=0 do SerialSend2 #5000# endon
on Power6#State=1 do SerialSend2 #6100# endon
on Power6#State=0 do SerialSend2 #6000# endon
on System#Boot do SerialSend2 1 endon
on SerialReceived#Data=;10; do Power1 0 endon
on SerialReceived#Data=;11; do Power1 1 endon
on SerialReceived#Data=;20; do Power2 0 endon
on SerialReceived#Data=;21; do Power2 1 endon
on SerialReceived#Data=;30; do Power3 0 endon
on SerialReceived#Data=;31; do Power3 1 endon
on SerialReceived#Data=;40; do Power4 0 endon
on SerialReceived#Data=;41; do Power4 1 endon
on SerialReceived#Data=;50; do Power5 0 endon
on SerialReceived#Data=;51; do Power5 1 endon
on SerialReceived#Data=;60; do Power6 0 endon
on SerialReceived#Data=;61; do Power6 1 endon

I will be posting for the 3 node 1 fan module when I get it as well. You should be able to use this to get the 2 node and 4 node without fan working as well after making adjustments

1 Like

The device cannot work with a simple template like other tasmota devices because the relays are not connected with GPIO pins. Rather, the ESP sends serial messages to an MCU which is what controls the relays. The template I have shared adds “dummy” or “fake” relays which tasmota can identify and the rules follow the power state of the “fake” relay and send according serial messages to the MCU for relay toggling. The MCU also sends serial messages back to the ESP which is what rule2 reads and toggles the power states according to the power state of the physical switch

The rules also have to be enabled using

rule1 1
rule2 1

In order to make this work with the 2 or 4 node without fan module, edit the template and remove the relays you dont need, for example, remove 2 relays for the 4 node and remove 4 for the 2 node and edit the rules to remove the lines for the relays you removed

I do have the 4 node with fan module on hand but currently I can only get the fan and one relay working or have all 4 relays work only for toggling power on and off. If I do get it working fully I will share details

Thanks All in this discussion for input.
2 months back I flashed my tinxy 4 node with tasmota . When I connect with mains the tasmota comes up and connects with my network. That time I tried to find out the relay pin and MCU but was not able to finish the task due to my limited knowledge of this topic.
Today I found this forum where I got input on how to proceed.
Today I connected 4 node to mains power and connected via Web UI .
Using consol tried above method by you.
set the template for 4 node by removing relays 5 & 6 from the given template
Updated the following rules :slight_smile:

Template: {"NAME":"Tinxy 4 Node","GPIO":[224,0,0,0,225,226,0,0,288,227,0,0,0,0],"FLAG":0,"BASE":18}

ON System#Boot DO baudrate 9600 ENDON
ON Power1#State=1 DO serialsend2 #1100# ENDON
ON Power1#State=0 DO serialsend2 #1000# ENDON
ON Power2#State=1 DO serialsend2 #2100# ENDON
ON Power2#State=0 DO serialsend2 #2000# ENDON
ON Power3#State=1 DO serialsend2 #3100# ENDON
ON Power3#State=0 DO serialsend2 #3000# ENDON
ON Power4#State=1 DO serialsend2 #4100# ENDON
ON Power4#State=0 DO serialsend2 #4000# ENDON

ON System#Boot DO SerialSend2 1 ENDON
ON SerialReceived#Data=;10; DO Power1 0 ENDON
ON SerialReceived#Data=;11; DO Power1 1 ENDON
ON SerialReceived#Data=;20; DO Power2 0 ENDON
ON SerialReceived#Data=;21; DO Power2 1 ENDON
ON SerialReceived#Data=;30; DO Power3 0 ENDON
ON SerialReceived#Data=;31; DO Power3 1 ENDON
ON SerialReceived#Data=;40; DO Power4 0 ENDON
ON SerialReceived#Data=;41; DO Power4 1 ENDON

rule1 1
rule2 1
1 Like

Hello, I am glad to see that my post helped you. The 6 node I have on hand uses the GPIO pins 1 and 3 as a hardware serial bridge. The edits you have made are absolutely correct except for the command to enable the rules. The rule can be enabled with

rule1 1
rule2 1

as in the binary instruction, 1 being on and 0 being off. If anyone needs any help with tasmota I would recommend joining the tasmota discord server as I would not have been able to figure these modules out without their help

Yup thanks rule2 2 was typo

1 Like

Any luck on 4 node fan device ?
this may help u

Nope, no luck so far with complete compatibility with tasmota. Thanks for the link, will try to see if that helps. You could probably get it working with ESP home though


did anybody figure out how to get the status of the switch for the first time? for example, once the esp gets connected to wifi and becomes available on a 4N model, the status of the switch (S4 for example) isn’t available unless the Line voltage is detected (someone turn the switch for first time), then the MCU would provide a feedback (;41; or ;40; for example) and the status is known.

is there a separate UART command to get/query the switch status without user triggering the physical switch?

I tried some random commands like #0000# or #1111# etc, but no luck.

for people who are interested in flashing with esphome, here is the config I use for a 4N model. The initialization logic is not there in it (the problem I explained above)

  name: lwall2
    - uart_read_line_sensor.h

  board: esp01_1m

# Enable logging
  baud_rate: 0
  level: VERBOSE 

# Enable Home Assistant API
  password: ""

  password: ""

  ssid: !secret wifi_ssid
  password: !secret wifi_password
  domain: ".example.com"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "lwall2 Fallback Hotspot"
    password: "xxxxxxxxxxxxxx"


    number: GPIO12
    inverted: yes

  id: uart_bus
  tx_pin: 1
  rx_pin: 3
  baud_rate: 9600
    #dummy_receiver: true

  - platform: custom
    lambda: |-
      auto my_custom_sensor = new UartReadLineSensor(id(uart_bus));
      return {my_custom_sensor};
      id: "uart_readline"
      name: "UART Feedback"
          - lambda: |-
              ESP_LOGD("main", "The current value is %s", x.c_str());

              if (id(uart_readline).state == "41") {

              } if(id(uart_readline).state == "40") {
              if (id(uart_readline).state == "31") {
              } if(id(uart_readline).state== "30") {
              if (id(uart_readline).state == "21") {
              } if(id(uart_readline).state== "20") {
              if (id(uart_readline).state == "11") {
              } if(id(uart_readline).state== "10") {

  - platform: template
    name: "Relay4 Wall Switch"
    id: relay4_wall_switch

  - platform: template
    name: "Relay3 Wall Switch" 
    id: relay3_wall_switch

  - platform: template
    name: "Relay2 Wall Switch" 
    id: relay2_wall_switch

  - platform: template
    name: "Relay1 Wall Switch" 
    id: relay1_wall_switch


  - platform: template
    name: "Relay1"
    id: relay1
    optimistic: true 
      - uart.write: '#1100#'
      - uart.write: '#1000#'   

  - platform: template
    name: "Relay2"
    id: relay2
    optimistic: true 
      - uart.write: '#2100#'
      - uart.write: '#2000#'        


  - platform: template
    name: "Relay3"
    id: relay3
    optimistic: true 
      - uart.write: '#3100#'
      - uart.write: '#3000#'    

  - platform: template
    name: "Relay4"
    id: relay4
    optimistic: true 
      - uart.write: '#4100#'
      - uart.write: '#4000#'    


uart_read_line_sensor.h (lifted from docs)

#include "esphome.h"

class UartReadLineSensor : public Component, public UARTDevice, public TextSensor {
  UartReadLineSensor(UARTComponent *parent) : UARTDevice(parent) {}

  void setup() override {
    // nothing to do here

  int readline(int readch, char *buffer, int len)
    static int pos = 0;
    int rpos;

    if (readch > 0) {
      switch (readch) {
        case ';': // Return on CR
          rpos = pos;
          pos = 0;  // Reset position index ready for next time
          return rpos;
          if (pos < len-1) {
            buffer[pos++] = readch;
            buffer[pos] = 0;
    // No end of line has been found, so return -1.
    return -1;

  void loop() override {
    const int max_line_length = 20;
    static char buffer[max_line_length];
    while (available()) {
      if(readline(read(), buffer, max_line_length) > 0) {


great point, I am also having issues with this while working with home assistant because the serial communication does not seem 100% reliable when sending too many commands at once and I can’t figure out how to check the status for the relays. There must be a mechanism to check this since the tinxy app must be doing the same. Maybe @mohit could give us any information regarding this?

There is one more rule I must mention. When powerloss occurs, the relays turn off. Since the relays are not connected to GPIO, tasmota thinks they are still turned on due to the default poweronstate restoring the power state to what is stored in memory. To fix this, you can either tell tasmota to boot up with the power states off with PowerOnState 0 or add this rule to tasmota

ON Power1#Boot=1 DO serialsend2 #1100# ENDON
ON Power2#Boot=1 DO serialsend2 #2100# ENDON
ON Power3#Boot=1 DO serialsend2 #3100# ENDON
ON Power4#Boot=1 DO serialsend2 #4100# ENDON
ON Power5#Boot=1 DO serialsend2 #5100# ENDON
ON Power6#Boot=1 DO serialsend2 #6100# ENDON
ON Power1#Boot=0 DO serialsend2 #1000# ENDON
ON Power2#Boot=0 DO serialsend2 #2000# ENDON
ON Power3#Boot=0 DO serialsend2 #3000# ENDON
ON Power4#Boot=0 DO serialsend2 #4000# ENDON
ON Power5#Boot=0 DO serialsend2 #5000# ENDON
ON Power6#Boot=0 DO serialsend2 #6000# ENDON

Like before, turn on the rule with

rule3 1

This rule checks what power state is stored in memory and restores it accordingly. You could do this more efficiently with conditional rules but they are not enabled in the precompiled binary, so consider doing that if you are compiling yourself. You can also optionally remove the parts that turn off the relay when it boots since they relays turn off when the module power down anyway

Hi @Fiery from what I understood, sometimes it takes a moment to give the feedback, so the serial commands needs to be sequential after getting the feedback from MCU. only after getting the feedback, it should write the next command, just what I feel. I might need to modify my code to adopt this logic.

@mohit Could you please share some info on how to query the status of the relay/switches(wall switch)? if that is a thing.

I guess it is easy to use this PowerOnState 0

I’ve got my 6N model last week and tinkered with it a little. This time, I installed tinxy app first and configured the module with it before doing flashing. I noticed a difference, the MCU didn’t turn on the relays even after powering on the device with Sx connected to power, so I guess there is something going on there. a new firmware update for MCU pushed through the app?

anyways, I flashed the 6N model with esphome and I can safely assume that all relays will be OFF on initial boot (even with Sx terminals connected to power)

but my 4N model still behaves the same! :grimacing:

My 6N is the same, turns off all relays on power down (not a reboot, reboot maintains the same power state). Tasmota can store the powerstate in memory which allows me to restore the power states. Perhaps you could manually instruct the 4N to turn all relays off on powerup?

Note: I also connected to the tinxy app before flashing, but I did also copy the firmware off the device using esptools before flashing

@Fiery yes, something like that should fix it. I do have pretty good power backup so I don’t think it would be an issue, just an annoying thing I can’t wrap my head around.

Good thing that you paired it with tinxy app first, probably that might have pushed some updates to the MCU or yours might already have come with updated firmware. the only way to confirm this theory is to get another 4N, pair with tinxy app and then flash esphome.