Craig's Tasmota page

I've been using home automation for a long time. I started with X10 but found its one-way power line control protocol did not work that well for me. Later I switched to Insteon which uses two-way power line and RF control. I only used power line modules and quickly found that they didn't really work all that much better. In the long my experience with Insteon was a failed experiment. Modules are significantly more expensive than X10 and the protocol is proprietary. But my biggest complaint is that the company frequently makes backwards incompatible changes. Several times over the years I bought new hardware that would not inter operate with my existing hardware.

Tasmota and Sonoff

I was seriously considering buying some Zigbee modules and doing research when I found a YouTube rant by Paul Hibbert that compares Zigbee to WiFi: Zigbee Is A Con And The Industry Is Lying To You. I hadn't realized that so many WiFi modules were available and when I looked into them I found that these typically use the cloud for control. But it wasn't difficult to find alternative, open source firmware that would allow me to use my own server. While looking at the list of devices supported by Tasmota I found Sunoff and ordered a S31 smart plug. Once I saw how easy it was to get the S31 working with Tasmota and how well everything worked I ordered more S31's and also some Basic modules. At this point I have more than ten modules in operation.

Flashing

I recommend the "Getting Started" page on the Tasmota site for instructions on flashing Tasmota over the factory firmware; since Tasmota supports OTA updates via http, this is something you usually only need to do once. When I first tried Tasmota I followed a guide that used version 6.4. Later I built 8.1 from source to gain TLS support (see Building below).

Under Unix I like the Espressif esptool tool, under Windows I've found ESPEasy works well.

The recommended USB serial cable is the FTDI RT232R-3V3. These feature 3.3V TTL level UART levels on a 6 pin, 0.1" pitch connector. They supply 5V but the Sonoff boards I've used all have regulators that handle this without damage.

To flash S31 modules I made an adapter cable that plugs into the FTDI cable and temporarily tack the wires to the board. I use the same color codes as the FTDI cable to help insure correct connection. Red for VCC, orange for RX, yellow for TX and black for ground.

Sonoff S31 Serial Sonoff Basic Serial

To flash Basic modules I usually solder in a 1x4 sip socket and use wires to jumper between the FTDI cable and the module.

Building

I wanted TLS support but pre-compiled images do not have it because the feature is large; modules typically have 1M of flash and if your binary is larger than half of this (512K) you won't have enough free space to support OTA upgrades. The strategy is to turn off support for hardware you don't have and features you don't use to make room for TLS.

Last time I checked the current documentation was brief and lacking. There's also the problem that content frequently moves or completely disappears (!?!?) and I can't find the old version even on archive.org. If you find broken links here please drop me a note.

One procedure I found when I was starting out discussed using Windows 10 but the use of Atom and PlatformIO is similar when using linux. Here's a quick summary of my procedure:

Even with TLS enabled you must use http with the OTA firmware upgrades.

Upgrading

When you update to a newer version it's best to clean up some directories to avoid build issues:
rm -rf .cache .pio

Upgrade the Theme

Initially I used 6.4 but later upgraded to 8.1 built from source to gain TLS support. Here's how to upgrade the theme to new black background; paste into the web console:

WebColor {"WebColor":["#eaeaea","#252525","#4f4f4f","#000000","#dddddd","#65c115","#1f1f1f","#ff5661","#008000","#faffff","#1fa3ec","#0e70a4","#d43535","#931f1f","#47c266","#5aaf6f","#faffff","#999999","#eaeaea"]}

Timezone

Use the web console to configure the Timezone (this shows Pacific time):

Backlog Timezone 99 ; TimeDST 0,2,03,1,3,-420 ; TimeSTD 0,1,11,1,2,-480

The 99 says to use TimeDST and TimeSTD. Use "time" to check.

I also set ntpserver1 to use a local server and remove the other default servers:

Backlog ntpserver1 203.0.113.123 ; ntpserver2 0 ; ntpserver3 0

My modules are tightly firewalled and cannot connect to the internet.

Location

If you configure your location it can be used to calculate sunrise and sunset:

Backlog Latitude 37.755199 ; Longitude -122.452400

For privacy I like to pick a nearby landmark instead of using my actual location.

Night Light

This is trivial to do using timers assuming you have configured timezone and location:

Sunset Sunrise

You can add a bias (e.g. 30 minutes before sunrise) and even add random fuzz (e.g. ± 10 minutes).

In case it's not obvious you need to enable both arm and repeat or else each timer will only fire once.

Display hostname and IP address in GUI

I like to turn this on:
SetOption53 1

Change GUI Switch Labels

It's possible to customize the switch label (e.g. "Toggle 1") to text of your own choosing:
Webbutton1 Distruct

Configure For Use With a Wall Switch

This is just a matter of setting the SwitchMode2 to inverted follow:
Switchmode2 2

MQTT Broker

While you can do interesting things without a MQTT broker you'll probably want to use one. I use Eclipse Mosquitto.

PowerRetain

Once you have a Broker configured you can turn PowerRetain on so that MQTT keeps track of the power state of modules:
PowerRetain 1

This causes the module to come back in the same on/off state after a reboot, crash, or loss of power.

Use GPIO Inputs On One Module To Control Outputs On Another

This was difficult to figure out. For whatever reasons there does not appear to be high level documentation or concrete examples out there. The closest thing I found was this block post titled LEGO Nightstand Light Switch.

I was able to make this work using two ESP8266 dev boards. When you configure the module type to Generic you get a configuration page that looks like this:

Amica ESP8266 NodeMCU Generic Configuration

In my case, the "D" number correspond to Arduino digital pin numbers as well as what is silk screened onto my dev board. The GPIO numbers correspond to Espressif documentation. Notice that next to some of the pins are comments like Button1 and Relay1. These are assumed if they are not explicitly configured with the per-pin pulldown menu items. Let's say you want to have two inputs that are connected to on/off switches. If you configured two pins to be switches (e.g. Switch1 and Switch2) but do not configured any relays then operating either switch will control the default or explicit relay.

Here's an example of a working configuration. There are two ESP8266 modules. Since pins D3 (GPIO0), D4 (GPIO2), and D8 (GPIO15) select different boot modes (e.g. the UART bootloader) I'll avoid using them as inputs. There's also a red LED on D0 (and a blue one on D4).

The first module, livingroom-display, has LEDs connected two four pins: D1, D2, D5, and D6. Each LED has one pin hooked to an I/O pin and the other to a dropping resistor connected to 3.3V. To illuminate the LED we need the I/O pin to be driven low. So we'll configure the pins to use the inverting version of a relay: Relay1i, Relay2i, Relay3i, and Relay4i:

Display Configuration Livingroom Display Schematic Display Main

The second module, frontdoor-sensor, has two inputs connected to switches. We want these inputs to control the LEDs/relays on livingroom-display. For inputs we'll use D2 and D5 and configure them as Switch2 and Switch3 (remember we want to control Relay2i and Relay3i on livingroom-display). We also need two dummy relays: Relay2 and Relay3:

Sensor Configuration Sensor Main

We also need to change the SwitchMode from the default of toggle (0), to inverted follow (2):

Backlog SwitchMode2 2 ; SwitchMode3 2

Next we need to change the SwitchTopic:

SwitchTopic livingroom-display

This causes MQTT updates to set the specific topic.

Finally we need some rules so that when an input on frontdoor-sensor changes that module will publish the new MQTT status so that livingroom-display can track the updated values (enter all in one line):

rule on switch2#state=2 do publish cmnd/livingroom-display/power 2 endon; on switch3#state=2 do publish cmnd/livingroom-display/power 2 endon

At this point grounding D2 or D5 on frontdoor-sensor will turn on the 2nd or 3rd LED on livingroom-display.

Some things to keep in mind about all this:

Using GPIO Pins on a Sonoff Basic

The most recent Sonoff Basic R2 uses a version of the ESP8255. If you configure the Tasmota module type to "Sonoff Basic" you won't be able to access most of the GPIO pins. The workaround is to set the module type to "Generic" and make GPIO0 Button1, GPIO12 Relay1, and GPIO13 Led1i (inverted).

Sonoff Basic Configuration Basic/Generic Configuration

This preserves the standard functionality of a Basic while making pins including GPIO10, GPIO14 and, GPIO16 usable. While these are not exposed as pads the Sonoff Basic R2 board GPIO14 and GPIO16 are near a corner of the chip and it's not too tricky to tack wires to the pins. In this picture GPIO14 is the top right pin and GPIO16 is the upper right side pin:

Sonoff Basic Mod

The Sonoff Basic R2 uses a QFN-32. It is 5mm square and the center-to-center pin spacing is 0.5mm. GPIO10 is on the left side of the chip, second from the top and would be much more difficult to solder a wire to.

The smallest wire wrap wire I could find for this kind of modification Alpha Wire 2936. It's 36 AWG (0.005") with white insulation.

References


Copyright © 2020
Craig Leres