Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Finding Some Tasmota Consistency

Tasmota, ESPHome, Home Assistant… I am drawn to these platforms because of the flexibility that they provide, but sometimes you have to find some unique solutions to solve problems. This one involves a little duct tape, but works quite well. In addition to the problem below, consistency has been something I’ve struggled with using Tasmota, but this solution also provided me a way to get all my devices working the same by standardizing a lot of their configuration.

The Problem

Put simply, if I have any sort of Wi-Fi issues or power issues, my Tasmota devices are not gracefully or automatically fixing themselves. One of my core tenants of Automation is that it should be resilient and have a high “Wife Approval” score. When lights and switches disconnect and then require someone to manually reset the devices in order to restore order in the house, both of those tenants get a low score.

My Solution

I took to the Tasmota discord and found some sweet commands that I was unfamiliar with that solve my problem. In Information Technology, many devices come with a “Heartbeat” function. Simply put, a heartbeat is an active means by confirming that the device is operating normally. Heartbeats can be passive, however in this case we are using a very active means of communication.

  • Every x seconds, NodeRed publishes a command to my Tasmota devices restarting a timer for x + 10 seconds.
    • The Tasmota devices automatically start the same timer for 120 seconds after a reboot.
  • On each tasmota device, once the timer runs out, it will automtaically restart itself.

Thus, if the Tasmota device is not connected to Wi-Fi or MQTT, it will automatically restart itself to re-establish it’s connection to the server which once connected, the Tasmota device will start receiving the heartbeat again.

Implementation

Tasmota

On the Tasmota device, we setup a Rule and a RuleTimer to trigger the rule. Here are the commands:

# Create Rules
    # Rule1 triggers with RuleTimer1.
    # Rule2 triggers on system restart and sets RuleTimer1 for 120 seconds.
Backlog Rule1 ON Rules#Timer=1 DO Restart 1 ENDON; Rule2 ON System#Init DO RuleTimer1 120 ENDON

# Enable the Rules (set to 0 to disable rules)
Backlog Rule1 1; Rule2 1

# Heartbeat RuleTimer
RuleTimer1 30

NodeRed

NodeRed Flow
I setup 3 inject scripts. The first is my timezone setup script. It sets my NTP, Timezone, etc. The second inject will create and enable the rules using the commands above. The 3rd inject fires every 20 seconds resetting the timer on all my devices. Here is the code that I use in my function to reset the timer on all my devices:
// Get my Redis Connection from the Global Context
const redis = global.get('redis');
// Get the list of device names from Redis
const tasmotaDevices = await redis.call(
  'LRANGE',
  'tasmota.devicenames.foote_tb_primary',
  0,
  1000
);

// Loop over each device name and output an array with the MQTT
// topic and payload to reset the RuleTimer1
for (let x = 0; x < tasmotaDevices.length; x++) {
  node.send({
    topic: `tasmota/cmnd/${tasmotaDevices[x]}/Ruletimer1`,
    payload: 30,
  });
}

In this case, i’m using Redis to store my list of Tasmota device names. I did this because it makes it very easy to create automations that trigger on all devices since I just need to loop over a list. Overall, this solution has been A+ and has worked perfectly.