HowTo: Tasmota – flash firmware

In addition to the hardware, the right software for your project is of course just as important. The Tasmota firmware is a practical and universally applicable firmware for the ESP8266 forest and meadow microcontroller. This allows you to implement various projects without having to program them yourself. What's more, you don't have to "reinvent the wheel" every time 🙂

Before you can use this with your microcontroller, it must of course first be transferred to it. How to do this and what you need to bear in mind is described in the following article.


Safety instructions

I know the following notes are always kind of annoying and seem unnecessary. Unfortunately, many people who knew "better" have lost eyes, fingers or other things due to carelessness or injured themselves. Data loss is almost negligible in comparison, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Because even the coolest project is not worth injury or other trouble.
https://www.nerdiy.de/sicherheitshinweise/

Affiliate links/advertising links

The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and make a purchase via this link, Nerdiy.de will receive a commission from the relevant online shop or provider. The price does not change for you. If you make your purchases via these links, you support Nerdiy.de in being able to offer other useful projects in the future. 🙂 


Requirements

Helpful articles:
Before you start with this article you should have installed and configured the Arduino IDE. You can find information about this in the following article.
Install programs - an example
ArduinoIDE - Tips and Tricks

Required material:

In the following list you will find all the parts you need to implement this article.

Required tool:

In the following list you will find all the tools you need to implement this article.


Copy the current Tasmota version from GitHub

Before you can start configuring and programming the Tasmota firmware, you must first download it from GitHub.

The files for the firmware can be found at: https://github.com/arendst/Sonoff-Tasmota

How you can download files from a GitHub is described in the article GitHub - How do I copy files from a GitHub to my computer? described.

After downloading the compressed firmware files you have to unpack them. You can find tips on this in the article WinRar? WinZip? WinWhat? - Honey I shrunk the files


Configuring the Tasmota firmware

Many settings of the Tasmota firmware can also be adjusted during operation. Nevertheless, I find it easier to import these settings directly using correctly configured firmware.
This is also absolutely necessary for some of the sensors used, as not all software components for each sensor or actuator are compiled ("added to the firmware") as standard.

You will find several folders in the GitHub project that you have now downloaded. For us, however, only the "lib" and "sonoff" folders are important. "lib" contains all the Arduino libraries that Tasmota needs to be compiled successfully. So install all the Arduino libraries it contains. You can find tips on this in the article ArduinoIDE - Installing a library Once you have done this, you can switch to the "sonoff" folder.
This contains all the required firmware files. Now open these by double-clicking on the "sonoff" or "sonoff.ino" file.
This opens the complete Tasmota project in the Arduino IDE.
Now switch to the "user_config.h" tab as shown. As the name suggests, you can configure all the options of the Tasmota firmware here. This is divided into various "subject areas".

The different options of the Tasmota firmware

The "user_config.h" that is now open contains all kinds of setting options. In most cases, you only need a fraction of them. For the sake of completeness, however, all options are listed and briefly described here.

So that you don't have to go through all the options individually, I have highlighted the options that you absolutely have to edit in green. These are, for example, passwords or URLs that you should configure individually or at least check. So check these options before you transfer the firmware to your Tasmota device.

"PROJECT" defines the name of your project. This is also the ID which is used as a prefix for the MQTT path used by this ESP.
"MODULE" defines the hardware on which this Tasmota firmware is installed. You can already specify whether this configuration is used for a Sonoff S26 or a simple WEMOS D1 Mini module.
"SAVE_DATA" activates or deactivates the saving of changed settings in the flash memory. You should leave this activated, as otherwise your settings will be lost after every restart or power interruption.
"SAVE_STATE" activates or deactivates that the last switching state is saved in the flash memory. If you use the Tasmota firmware to control a lamp, for example, you can ensure that its switching state is restored even after a power failure.
The IP address, gateway, subnet mask and IP of the DNS server used can be configured here. In most networks, however, this is not necessary because this data is negotiated dynamically with the router. The default values can therefore be left as they are in most cases.
Now we come to an important part that you should at least check before installing the firmware. This is where the login data for your WiFi is configured. Here you can enter the SSID (i.e. the name) of your WLAN under "STA_SSID1" and the password of your WLAN under "STA_PASS1". Under "STA_SSID2" and "STA_PASS2" it is possible to configure another WLAN. This is used if a connection to the first configured wifi has failed. "WIFI_CONFIG_TOOL" "WIFI_CONFIG_...
In the "Syslog" section, you can configure server data for a syslog server. This is not necessary for most users. Syslog is a system for monitoring log messages from individual clients in a network. A syslog server is required for this. In addition to the syslog data, the log messages that are output via the serial console or the web console can also be configured here. This allows you to set how detailed the output on the web or serial console is. The following levels are possible (which also become more detailed in this order): LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE
With "OTA_URL" you can specify a URL from which OTA (over-the-air) updates are obtained. So if you start an update later in the already installed Tasmota firmware, Tasmota will search for it at the specified address and install it if necessary.

The basic parameters for connecting to the MQTT server can be set in the "MQTT" section. - MQTT_USE" activates the MQTT client.
- "MQTT_HOST" specifies the address of your MQTT server.
- Under "MQTT_FINGERPRINTX" you can set the fingerprint for encrypting your MQTT connection. - - "MQTT_PORT" sets the port of your MQTT server.
- In "MQTT_USER" and "MQTT_PASS" you can define the user name and password for your MQTT server.
- With "MQTT_BUTTON_RETAIN", "MQTT_POWER_RETAIN" and "MQTT_SWITCH_RETAIN" you can activate the retain flag for the respective MQTT messages. This means that the respective MQTT messages are also sent to MQTT clients that were not yet online at the time the MQTT message was sent.
- With "MQTT_STATUS_OFF" you can set the string that is used in commands to switch something off.
- With "MQTT_STATUS_ON" you can set the string that is used in commands to switch something on.
- With "MQTT_CMND_TOGGLE" you can set the string that is used in commands to switch something.
- With "MQTT_CMND_HOLD" you can set the string that is to be sent when a button is pressed for longer than specified in KEY_HOLD_TIME.

Various details on the MQTT topics used can be defined in these sections.
With "MQTT_FULLOPIC" you define the structure of the topics used. By default, this always consists of the "prefix" and the respective "topic".

The prefixes are then defined under "SUB_PREFIX", "PUB_PREFIX" and "PUB_PREFIX2".
Your Tasmota device uses the prefix specified under "SUB_PREFIX" as a subscription - i.e. to receive values and commands.
The pefix specified under "PUB_PREFIX" is used to publish values.
Telemetry data is sent via the prefix defined in "PUB_PREFIX2".

The topics are then defined under "MQTT_TOPIC", "MQTT_GRTOPIC", "MQTT_BUTTON_TOPIC", "MQTT_SWITCH_TOPIC".
Here, "MQTT_TOPIC" stands for the individual topic of the Tasmota device. A part of the MAC address of your Tasmota device is always appended.
"MQTT_GRTOPIC" stands for a topic in which you can combine several Tasmota devices in a group.
With "MQTT_BUTTON_TOPIC" and "MQTT_SWITCH_TOPIC" you can set special topics for any connected buttons and switches.

With "MQTT_CLIENT_ID" you can define the name or ID of the MQTT client.

You can normally leave all these values as they are.

"TELE_PERIOD" defines the interval at which the telemetry data is sent. This time is specified in seconds. With a value of 300, the telemetry data such as connection data and sensor values are therefore sent to the set MQTT topics every five minutes.
With "DOMOTICZ_UPDATE_TIMER" you can define the interval at which the relay status is sent or updated to your Domoticz instance.
With the help of the parameter "HOME_ASSISTANT_DISCOVERY_ENABLE" you can activate the automatic detection of your Tasmota device. If you are using Home Assistants, this function should be activated.
Various settings for the web server running on the Tasmota device can be configured in this area. "WEB_SERVER" determines the user mode in which the web server runs. If you have set this to "2"=Admin, you should see the following option "WEB_PASSWORD" be sure to set a password. Otherwise, anyone who has access to your network will be able to change and control the configuration of your Tasmota device. With "FRIENDLY_NAME" you can then specify a more legible name. This will be used for display in the web menu and for any linking with Alexa.
You can use the "NTP_SERVERX" option to specify the address of the NTP server. You can specify three different servers. If the first server is not available, the next configured server is automatically used as a replacement.

You can use these and the options in the next section to define the criteria for the summer/winter time changeover. The parameters starting with "TIME_DST..." define the conditions under which the system switches from standard time (winter time) to summer time. The parameters starting with "TIME_STD_...", on the other hand, are decisive for the reverse case, i.e. the changeover from summer to winter time. The parameters are otherwise identical for both areas: "...HEMISPHERE" determines on which part of the globe you are located. This option is not actually required for the time changeover, but rather for calculating the correct sunrise and sunset times.

Now it's time to set the parameters for the time changeover. As the time changeover (at least in Germany) from winter to summer time always takes place on the last Sunday in March at 02:00, you must set the parameter "TIME_DST_WEEK" to "Last", the parameter "TIME_DST_DAY" to "Sun" (=Sunday), the parameter "TIME_DST_MONTH" to "Mar" (=March) and the parameter "TIME_DST_HOUR" to two. With the parameter "TIME_DST_OFFSET" you then specify which time shift occurs in this case. You must also specify the deviation due to the time zone. In the case of Germany, where the time zone is UTC+1, i.e. +60 minutes, +120 minutes applies here for summer time.

The time change from summer to winter time (again in Germany) always takes place on the last Sunday in October at 03:00.
You must therefore set the "TIME_STD_WEEK" parameter to "Last", the "TIME_STD_DAY" parameter to "Sun" (=Sunday), the "TIME_STD_MONTH" parameter to "Oct" (=October) and the "TIME_STD_HOUR" parameter to three. You then use the "TIME_STD_OFFSET" parameter to specify which time shift occurs in this case. You must also specify the deviation due to the time zone. In the case of Germany, where the time zone is UTC+1, i.e. +60 minutes, the standard time (=winter time) is +60 minutes.

You can use the "LATITUDE" and "LONGITUDE" options to set the position of the Tasmota device. This is necessary to calculate the correct sunrise and sunset time. If you want to use this function, it is important to enter the correct data here. How you can find out the position of any location is described in the article Find the latitude and longitude of any location with GoogleMaps described. Make sure that you enter the position (as shown) in the decimal system. How to do this is also described in the article mentioned.

"APP_TIMEZONE" defines the time zone.
"APP_LEDSTATE" defines the function of the integrated LEDs (in many Sonoff devices)
"APP_PULSETIME" defines the pulse duration in the form of multiples of 0.1 seconds. A value of 5 therefore corresponds to 0.5 seconds or 500 milliseconds. A value of 0 deactivates this function.
"APP_POWERON_STATE" defines the state of the configured relays after switching on. The following settings are available here: POWER_ALL_OFF, POWER_ALL_ON, POWER_ALL_SAVED_TOGGLE, POWER_ALL_SAVED, POWER_ALL_ALWAYS_ON, POWER_ALL_OFF_PULSETIME_ON
"APP_BLINKTIME" defines the pulse length of a "flashing" relay
"APP_SLEEP" defines a time period between 1 and 250 milliseconds in which the ESP8266 is put into sleep mode. In this way, some energy can be saved. Of course, in the worst case scenario, the ESP8266 only reacts 250 milliseconds later.
"KEY_DEBOUNCE_TIME" defines the debounce time of a connected push-button. A value of 50 therefore indicates that the relevant button is ignored for 50 milliseconds after a detected button press.
"KEY_HOLD_TIME" defines the length of time a button must be pressed before it is recognized as a permanently pressed button. The specified value is multiplied by 0.1 seconds. A value of 40 therefore corresponds to a duration of 4 seconds. The "Button is pressed" event is only triggered after 4 seconds.
"SWITCH_DEBOUNCE_TIME" defines the debounce time of a connected switch. A value of 50 therefore indicates that the relevant switch is ignored for 50 milliseconds after a switch position change is detected.
"SWITCH_MODE" defines the behavior of the configured relay in relation to a connected switch. The following options are possible:
TOGGLE; FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, PUSHBUTTON_TOGGLE
"WS2812_LEDS" defines the number of connected WS2812 LEDs.
"TEMP_CONVERSION" activates (=1) or deactivates (=0) the conversion of the temperature to the Fahrenheit unit.
"TEMP_RESOLUTION" defines the resolution with which the temperature is displayed. You can choose between none and up to three decimal places. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise this supposedly more exact value is more of a guess than exact.
"HUMIDITY_RESOLUTION" defines the resolution with which the humidity is displayed. You can choose between none and up to three decimal places. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise this supposedly more precise value is more of a guess than exact.
"PRESSURE_RESOLUTION" defines the resolution with which the air pressure is displayed. You can choose between none and up to three decimal places. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise this supposedly more precise value is more of a guess than exact.
"ENERGY_RESOLUTION" defines the resolution with which the energy consumption is displayed. You can choose between none and up to five decimal places. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise this supposedly more exact value is more of a guess than exact.

In this section you can Language used which the Tasmota device should use for the web menu, for example. To activate the respective language, the // in front of the corresponding line must be removed. All other lines should then be deactivated by prefixing them with //. In the example shown above, German(de-DE) is set as the language.

These options can be used to define the behavior in the event that no valid WLAN access data has yet been stored for the Tasmota device. If "USE_WPS" is activated (i.e. the two // in front of the corresponding entry are removed), you have the option of connecting your Tasmota device to your router using the WPS function. If "USE_SMARTCONFIG" is activated, you can enter the access data with the Android App ESP8266 Smart Config configure.

With the parameter "USE_ARDUINO_OTA" you activate the OTA function. This makes it possible to install "Over the Air (=OTA)" updates on the Tasmota device. The big advantage of this is that you can install the firmware on the Tasmota device via the WLAN connection without having to connect it with a USB cable. If you have the memory available, I recommend leaving this function activated.
In this area, you can specify the MQTT library used. To do this, activate or deactivate the desired option by removing or adding the // in front of it. Normally, you can leave the "MQTT_PUBSUBCLIENT" option shown here set.
"MQTT_TELE_RETAIN" activates or deactivates the retain flag for the telemetry data sent. This means that if another MQTT client subscribes to the respective telemetry topic after values have been sent to it, these values are sent again to the newly connected MQTT client.
With "DOMITICZ_IN_TOPIC" you can define the Domiticz input topic. With "DOMITICZ_OUT_TOPIC" you can define the Domiticz output topic.
With "USE_HOME_ASSISTENT" you can activate the automatic "announcement" of your Tasmota device. The option "HOME_ASSISTENT_DISCOVERY_PREFIX" can then be used to set the desired prefix.
The "USE_MQTT_TLS" option activates or deactivates TLS encryption for your MQTT communication. This is a great security gain but unfortunately also comes at the expense of the memory used. Depending on the memory usage, you may not be able to use this function in every configuration.
You can use "USE_KNX" to activate or deactivate support for the KNX protocol. The associated web menu can also be activated or deactivated using "USE_KNX_WEB_MENU".
The main settings for your web server can be set in this section. The "USE_WEBSERVER" option can be used to activate or deactivate the complete web server functionality. "WEB-PORT" defines the port used and "WEB_USERNAME" the desired user name. You can use the "USE_EMULATION" option to simulate a Belink WeMo including Hue Bridge. This enables you to control the respective device via the SmartHome function of your Alexa device.
With "USE_DISCOVERY" and the corresponding subcategories, you activate the function that your Tasmota device automatically searches for the host name of your MQTT server or that the web server can be reached via a local domain name. To do this, the corresponding options "WEBSERVER_ADVERTISE" and "MQTT_HOST_DISCOVERY" must be activated.
With "USE_TIMERS" and the following options you can activate/deactivate and control the timer functions of Tasmota. With "USE_TIMERS_WEB" you can activate/deactivate that the timers can be controlled/displayed via the web interface. With "USE_SUNRISE" you can add various functions that allow you to react to sunrise and sunset times. In order to be able to define these times precisely, you can also use "SUNRISE_DAWN_ANGLE" to define exactly which twilight should be used. The following options are available: DAWN_NORMAL, DAWN_CIVIL, DAWN_NAUTIC, DAWN_ASTRONOMIC
"USE_RULES" activates/deactivates support for custom rules. So if you want to control your Tasmota device individually using certain rules, you should activate this function.
The option "USE_ADC_VCC" is important if you want to use the integrated ADC of your ESP8266. If this option is activated, the internal ADC is used to measure the supply voltage. In this case, it is not possible to measure external voltages. This function must be deactivated for this purpose.
With "USE_DS18x20" you can activate or deactivate support for DS18x20 temperature sensors. You can also use "W1_PARASITE_POWER" to improve support for the parasite power supply.
In this section, support for various sensors connected via the I2C protocol can be activated/deactivated. To do this, the "USE_I2C" option must always be activated. The individual support for the respective sensors is then configured by activating/deactivating the respective option.
The "USE_SPI" option can be used to activate/deactivate support for sensors and actuators that communicate via SPI.
In addition to I2C and SPI, sensors and actuators with a serial interface can also be connected. In this section you can activate/deactivate the support for the respective sensors.
With the Tasmota firmware it is also possible to send and receive infrared commands. The settings required for this can be found in this section. The function "USE_IR_REMOTE" activates/deactivates the possibility to send commands. The "USE_IR_RECEIVE" function, on the other hand, activates/deactivates the function for receiving commands.
You should activate the "USE_WS2812" option if you want to control WS2812 LEDs with your Tasmota device. You can also use "USE_WS2812_CTYPE" to set the LED type, e.g. NEO_GRB/NEO_RGB/etc. The "USE_WS2812_DMA" option allows you to control the WS2812 LEDs via the DMA interface. This is particularly useful for time-critical displays and also reduces the processor load.
The "USE_ARILUX_RF" option activates/deactivates support for the Arilux RF controller.
You can use the "USE_SR04" option to activate/deactivate support for the widely used HC-SR04 ultrasonic distance sensor. 

The option "USE_RF_FLASH", if activated on a SONOFF 433Mhz RF Bridge, enables the programming of the connected co-processor via the web interface of the Tasmota firmware. You can also read more about this in the article Tasmota - Sonoff RF Bridge RF-Chip(EFM8BB1) with Portic Firmware flashing find.

In this and the following section, you can configure options that are mainly useful for developers. You can use the "USE_DEBUG_DRIVER" option to activate/deactivate experimental drivers for sensors and actuators that have not yet been fully tested.
These options activate/deactivate certain "standard configurations". "USE_CLASSIC" activates all options that are necessary for the "classic" Tasmota version. "USE_SESNORS" activates all options for the most commonly used sensors. "USE_KNX_NO_EMULATION" creates a version with KNX but without emulating this function. "BE_MINIMAL" deactivates most of the functions and thus creates a very compact firmware image, which is perfect for uploading to an ESP8266 via OTA.

Starting the programming process

After you have adapted or configured the firmware according to your wishes, it is now time to transfer it to the ESP8266 of your Tasmota device. In this example, a normal ESP8266 adapter board of the WEMOS D1-Mini is programmed with the Tasmota firmware.

First select the ESP8266 adapter board you are using.
In the case of a WEMOS D1-Mini, the options should be set as shown. With the option "Erase Flash..." you can also set which data should be erased during programming. You can choose between "Only Sketch"= only the firmware, "Sketch + Wifi Settings"= firmware and Wifi configuration data and "All Flash Contents"= all data. Normally you can leave this set to "Only Sketch".
To start the programming process, simply click on the turquoise-green arrow symbol (second from the left) in the top icon bar.
This starts the compilation and subsequent programming of the firmware. Depending on the size of the firmware, this process can take one to five minutes. If this was successful, it will be confirmed to you by "Upload complete" in the lower status bar.
You can also check the start-up process of the freshly programmed ESP8266 via the serial interface. After successful installation, the Tasmota firmware issues all kinds of status messages via this. To do this, click on the menu item "Tools" and "Serial monitor". You can also find more information about the serial interface in the article Ardunio - Using the serial interface find.
In the window that now opens, you can read all the messages from the ESP8266 or the Tasmota firmware that are displayed during the boot and connection process, among other things.

Have fun with the project

I hope everything worked as described for you. If not or you have questions or suggestions please let me know in the comments. I will then add this to the article if necessary.
Ideas for new projects are always welcome. 🙂

PS Many of these projects - especially the hardware projects - cost a lot of time and money. Of course I do this because I enjoy it, but if you think it's cool that I share the information with you, I would be happy about a small donation to the coffee fund. 🙂

Buy Me a Coffee at ko-fi.com       

2 comments

  1. In the current tasmota firmware version from github, the sonoff folder as described above no longer exists. Compiling doesn't work. What am I doing wrong?
    Kind regards
    Fabian

Kommentar hinterlassen

Your email address will not be published. Erforderliche Felder sind mit * markiert

This site uses Akismet to reduce spam. Learn how your comment data is processed.