Besides the hardware, the right software for your project is just as important. A practical and universally applicable firmware for the “forest-and-meadow microcontroller” ESP8266 is the Tasmota firmware. This allows you to realize various projects without having to program yourself. Besides, you do not have to “reinvent” the wheel every time. 🙂
Before you can use this with your microcontroller, it must first be transferred to this. How to do it and what you have to pay attention to is described in the following article.
Hints for our lovely english readers: Basically, many of the articles on Nerdiy.de are translations from the original german articles. Therefore, it may happen here and there that some illustrations are not available in english and that some translations are weird/strange/full of mistakes or generally totaly wrong. So if you find some obvious (or also not obvious) mistakes don't hesitate to leave us a hint about that in the comment section.
Also please don't get confused, that instead of a "dot" often a "comma" is used as decimal separator. 🙂
I know the following hints are always a bit annoying and seem unnecessary. But unfortunately, many people who knew it "better" from carelessness lost their eyes, fingers or other things or hurt themselves. In comparison, a loss of data is almost not worth mentioning, but even these can be really annoying. Therefore, please take five minutes to read the safety instructions. Even the coolest project is worth no injury or other annoyance. https://www.nerdiy.de/en/sicherheitshinweise/
The links to online shops listed here are so-called affiliate links. If you click on such an affiliate link and shop via this link, Nerdiy.de receives a commission from the online shop or provider concerned. The price doesn't change for you. If you do your purchases via these links, you will support Nerdiy.de in being able to offer further useful projects in the future. 🙂
Before you start with this article, you should have the Arduino IDE installed and configured. Information on this can be found 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 the GitHub
Before you can start configuring and programming the Tasmota firmware, you must first download it from the GitHub.
The files for the firmware can be found at: https://github.com/arendst/Sonoff-Tasmota
How to download files from a GitHub is in the article GitHub – How to copy files from a GitHub to my computer.
After downloading the compressed firmware files you have to unpack them. Tips can be found in the article WinRar? WinZip? WinWas? – Darling I shrunk the files
Configure the Tasmota firmware
Many settings of the Tasmota firmware can also be set during operation. Nevertheless, I find it easier to import these settings directly through a correctly configured firmware.
In addition, this is absolutely necessary with some of the sensors used, since not all software components for each sensor or actuator are compiled by default (“added to the firmware”).
The different options of the Tasmota firmware
In the now open “user_config.h” all kinds of settings are available. Most of the time you only need a fraction of it. For the sake of completeness, all options are listed here and briefly described.
So that you do not have to go through each option individually, I marked the options that you must necessarily edit green. For example, passwords or URLs that you absolutely have to configure individually or at least check. Check these options before transferring the firmware to your Tasmota device.
In the “MQTT” section you can set the basic parameters for connecting to the MQTT server.
– “MQTT_USE” activates the MQTT client.
– “MQTT_HOST” sets the address of your MQTT server.
– Under “MQTT_FINGERPRINTX” you can define the fingerprint for encrypting your MQTT connection.
– “MQTT_PORT” sets the port of your MQTT server.
– In “MQTT_USER” and “MQTT_PASS” you can specify username 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 causes the respective MQTT messages to also be sent to MQTT clients that were not yet online at the time of sending the MQTT message.
– With “MQTT_STATUS_OFF” you can set the string used in commands to turn off something.
– With “MQTT_STATUS_ON” you can set the string used in commands to turn something on.
– With “MQTT_CMND_TOGGLE” you can set the string used in commands to switch something.
– With “MQTT_CMND_HOLD” you can set the string to be sent if a button is pressed for longer than specified in KEY_HOLD_TIME.
In these sections, various details about the MQTT topics used can be determined.
With “MQTT_FULLOPIC” you determine the structure of the used Topics. 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 – in other words, to receive values and commands.
The prefix specified under “PUB_PREFIX” is used to publish values.
Telemetry data is sent via the prefix specified in “PUB_PREFIX2”.
Under “MQTT_TOPIC”, “MQTT_GRTOPIC”, “MQTT_BUTTON_TOPIC”, “MQTT_SWITCH_TOPIC” the topics will be defined.
“MQTT_TOPIC” stands for the individual topic of the Tasmota device. In the process, part of the MAC address of your Tasmota device is always attached.
“MQTT_GRTOPIC” stands for a topic in which you can group together several Tasmota devices.
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 still specify the name or the ID of the MQTT client.
You can usually leave all these values like that.
With these and the options in the next section you can set the criteria for the summer/winter time changeover. The parameters that start with “TIME_DST …” specify under which conditions the standard time (winter time) is changed to summer time. The parameters that start with “TIME_STD _…”, on the other hand, are decisive for the opposite case, ie the changeover from summer to winter time. The parameters are otherwise identical for both areas: “… HEMISPHERE” determines which part of the globe you are on. This option is not actually needed for the time change but rather for the calculation of the correct sunrise and sunset time.
Now it goes to the parameters for the time change. Since the time change (at least in Germany) from winter to summer time always takes place on the last Sunday of March at 02:00 o’clock you have the parameter “TIME_DST_WEEK” on “Last”, the parameter “TIME_DST_DAY” on “Sun” (= Sunday) , set the parameter “TIME_DST_MONTH” to “Mar” (= March) and the parameter “TIME_DST_HOUR” to two. With the parameter “TIME_DST_OFFSET” you set at which time difference the time changeover occurs. You also have to indicate the deviation through the time zone. In the case of Germany, that has the time zone UTC+1, +60 minutes, here applies for the summer time +120 minutes.
The time change from summer to winter time (again in Germany) always takes place on the last Sunday in October at 03:00 o’clock.
Therefore you have to set the parameter “TIME_STD_WEEK” to “Last”, the parameter “TIME_STD_DAY” to “Sun” (= Sunday), the parameter “TIME_STD_MONTH” to “Oct” (= October) and the parameter “TIME_STD_HOUR” to three. With the parameter “TIME_STD_OFFSET” you then give which time difference occurs in this case. You also have to indicate the deviation through the time zone. In the case of Germany, that has the time zone UTC+1=+60 minutes, then applies here for the standard time (= winter time) +60 minutes.
With the options “LATITUDE” and “LONGITUDE” you can 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 to find out the location of any location is described in the article Determining latitude and longitude of any position using Google Maps. Make sure that you indicate the position (as shown) in the decimal system. How to do this is also described in the mentioned article.
“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 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 power up. The following settings are available: 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 between 1 and 250 milliseconds in which the ESP8266 is put into sleep mode. This way, you can save some energy. Of course, the ESP8266 reacts in the worst case only 250 milliseconds later.
“KEY_DEBOUNCE_TIME” defines the debounce time of a connected probe. A value of 50 indicates that after a key has been detected, the button in question will be ignored for 50 milliseconds.
“KEY_HOLD_TIME” defines the length of time a button must be pressed until it is recognized as a permanently pressed button. The specified value is again multiplied by 0.1 seconds. A value of 40 corresponds to a duration of 4 seconds. So after 4 seconds, the “button is pressed”-event is triggered.
“SWITCH_DEBOUNCE_TIME” defines the debounce time of a connected switch. A value of 50 thus indicates that after a detected switch position change the relevant switch is ignored for 50 milliseconds.
“SWITCH_MODE” defines the behavior of the configured relay with respect 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 unit Fahrenheit.
“TEMP_RESOLUTION” defines the resolution with which the temperature is displayed. You can choose between no and up to three digits after the comma. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise, this supposedly more exact value is guessed rather than exact.
“HUMIDITY_RESOLUTION” defines the resolution with which the humidity is displayed. You can choose between no and up to three digits after the comma. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise, this supposedly more exact value is guessed rather than exact.
“PRESSURE_RESOLUTION” defines the resolution with which the air pressure is displayed. You can choose between no and up to three digits after the comma. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise, this supposedly more exact value is guessed rather than exact.
“ENERGY_RESOLUTION” defines the resolution with which the energy consumption is displayed. You can choose between no and up to five digits behind the comma. ATTENTION: The respective resolution must of course also be supplied by the connected sensor. Otherwise, this supposedly more exact value is guessed rather than exact.
With these options, the behavior in the case that for the Tasmota device no valid wireless LAN access data are stored. If “USE_WPS” is activated (ie the two // removed before the corresponding entry) you have the possibility to connect your Tasmota device to your router via the WPS function. If “USE_SMARTCONFIG” is activated you can configure the access data with the Android app ESP8266 Smart Config.
The “USE_RF_FLASH” option, if activated on a SONOFF 433Mhz RF Bridge, enables programming of the connected co-processor via the web interface of the Tasmota firmware. Further details can be found in the article Tasmota – Sonoff RF Bridge RF-Chip (EFM8BB1) with Portisch Firmware flashing.
Start the programming process
After you have adjusted or configured the firmware according to your wishes, it is now time to transfer them to the ESP8266 of your Tasmota device. This example programs a standard ESP8266 adapter board of the WEMOS D1-Mini with the Tasmota firmware.
I hope everything worked as described. If not or you have any other questions or suggestions, please let me know in the comments. Also, ideas for new projects are always welcome. 🙂
P.S. 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 appreciate it that I share these information with you, I would be happy about a small donation to the coffee box. 🙂