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.
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.
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. 🙂
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
In the following list you will find all the parts you need to implement this article.
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.
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.
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.
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.
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.
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.
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.
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. 🙂