Tasmota is an alternative open-source firmware for devices that are based on the ESP8266 WiFi chipset. The firmware provides the devices with timers, a web interface, Over The Air (OTA) updates and sensors support. It also allows control under HTTP, MQTT, KNX and serial. It is written for the Arduino IDE and PlatformIO.
With the Tasmota firmware installed, your device can read the state of buttons and switches, and many types of sensors for things like temperature, humidity, light, IR, etc. It can also control devices like relays, LEDs, displays, IR transmitters and many more.
In short, Tasmota turns your ESP8266 based board into a versatile IoT device without having to write your own code.
In this blog post, we will install Tasmota on the ESP8266 NodeMCU development board using the Arduino IDE. Then, as an example, we will configure Tasmota to toggle the onboard LEDs and one external LED. This will be a good starting point for future IoT and DIY home automation projects.
It was initially written for Sonoff devices, but it supports devices from many other brands like Electrodragon, MagicHome, AriLux, Blitzwolf, and Allterco. Of course, you can also install it on development boards like the Wemos D1 mini and the ESP8266 NodeMCU.
Find the location of your Arduino ‘sketchbook’ folder, see File > Preferences > Settings in your Arduino IDE.
Copy the contents of the Tasmota ‘lib’ folder to the sketchbook ‘libraries’ folder.
Copy the Tasmota ‘sonoff’ folder to your sketchbook folder.
Find the location of the Arduino IDE folder, see File > Preferences > Settings.
Inside the Arduino IDE folder, find the directory ‘packages\esp8266\hardware\esp8266\2.x.x ‘
Replace ‘platform.txt’ with the Tasmota file ‘arduino\version 2.x.x\platform.txt’.
Configure the Tasmota firmware
Connect your ESP8266 development board to your computer. In the Arduino IDE, open the file ‘sonoff.ino‘ from your sketchbook ‘sonoff’ folder.
Open the tab ‘my_user_config.h‘ and change the settings for network and WiFi:
// -- Wifi ----------------------------------------
#define WIFI_IP_ADDRESS "0.0.0.0" // [IpAddress1] Set to 0.0.0.0 for using DHCP or enter a static IP address
#define WIFI_GATEWAY "192.168.10.1" // [IpAddress2] If not using DHCP set Gateway IP address
#define WIFI_SUBNETMASK "255.255.255.0" // [IpAddress3] If not using DHCP set Network mask
#define WIFI_DNS "192.168.10.1" // [IpAddress4] If not using DHCP set DNS IP address (might be equal to WIFI_GATEWAY)
#define STA_SSID1 "yourwifinetwork" // [Ssid1] Wifi SSID
#define STA_PASS1 "yourwifipassword" // [Password1] Wifi password
#define STA_SSID2 "" // [Ssid2] Optional alternate AP Wifi SSID
#define STA_PASS2 "" // [Password2] Optional alternate AP Wifi password
#define WIFI_CONFIG_TOOL WIFI_MANAGER // [WifiConfig] Default tool if wifi fails to connect
// (WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, WIFI_SERIAL)
#define WIFI_CONFIG_NO_SSID WIFI_MANAGER // Default tool if wifi fails to connect and no SSID is configured
Enter the IP address or set it to “0.0.0.0” if you’re using DHCP.
You can give your device a unique project name, so it will be easier to recognize between the other devices in your network:
// -- Project -------------------------------------
#define PROJECT "Sonoff" // PROJECT is used as the default topic delimiter
I will change the device name later, in the Tasmota web interface.
Also, change the ‘CFG_HOLDER’ parameter to a new (random) value every time you change and upload the settings to the board.
// -- Master parameter control --------------------
#define CFG_HOLDER 234 // [Reset 1] Change this value (max 32000) to load SECTION1 configuration parameters to flash
If you do not change the parameter, the new settings will not take effect. The ‘CFG_HOLDER’ can be found under ‘Master parameter control’.
ESP8266 NodeMCU board settings
Before you compile and upload the firmware. first check the following board settings under the “Tools” menu in the Arduino IDE:
Board: “Generic ESP8266 Module”
Flash Size: 1M (no SPIFFS)
Flash Mode: “DOUT”
lwIP Variant: “v2 Higher Bandwidth (no features)”
Erase Flash: “Only Sketch”
Do not forget to select the right USB/COM-port.
Compile and upload the sketch to your development board.
Configuring Tasmota on the ESP8266 NodeMCU
After your ESP8266 has been flashed and restarted, look for it’s IP address in your network. If you don’t know where to find it, you should probably check your router first.
Enter the IP address of the ESP8266 in your browser. The Tasmota main menu will appear.
Once the Tasmota web interface appears, we need to change the module type from the default “Sonoff Basic” to “Generic”. Go to “Configuration” and choose “Configure Module”. Select “Generic” for Module Type and Save.
The module will restart. Next, we will configure the GPIOs of the ESP8266 board.
Setting the ESP8266 GPIO options
To test Tasmota on the ESP8266, we will first configure the built-in LED on the NodeMCU board to be turned on and off by using the web interface. On this version of the board, the LED is on GPIO16 (D0).
In the Tasmota interface, go to Configuration and then Configure Module. Make sure all the GPIOs are set to “None”. Then set GPIO16 to “Relay1i“. Hit “Save” and return to the Main Menu.
At the top of the Main Menu, you will see a button labeled “Toggle”. Pressing the button will now toggle the built-in LED on the NodeMCU board. This confirms that Tasmota is installed correctly and working as intended.
More LEDs, more fun
While we are at it, let’s add some more controls for LEDs. The NodeMCU board actually has 2 built-in LEDs: the second one is on the ESP-12 module itself. This LED is assigned to GPIO2 (D4). So in the Tasmota configuration, set GPIO2 to “Relay2i“.
After that, we will add an external LED on GPIO4 (D2). The anode (positive, long leg) is connected to the D2 pin via a 470-ohm resistor. The cathode (negative, short leg) is connected to the GND pin via a jumper cable. See the picture below.
Next, in the Module Configuration, we set the GPIO4 to ‘Relay3‘. The configuration should look like the picture below.
On the main page, three buttons now let you toggle the two built-in as well as the external LED.
Also, notice that in the above two pictures I changed the device name from “Sonoff” to “ESP8266” (Configuration > Configure other > Friendly Name 1).
Now, by using the toggle buttons in the Tasmota main menu, you can turn on or off the three LEDs.
Now you know how to toggle the GPIOs, you can use Tasmota to toggle relais on the NodeMCU, or use the GPIOs to read values from buttons or sensors. On its own, this is already a very useful application of the firmware.
In the next blog post, we will see how we can use the MQTT functionality of Tasmota. This will let the ESP8288 communicate with applications like Node-Red or Home Assistant, and will turn the NodeMCU into a very versatile DIY device for home automation projects.