Home Assistant - Tasmota & ESP Sensors (Part 3)
Download the ESP Flasher Tool from https://github.com/Jason2866/ESP_Flasher/releases.
We'll start off with an ESP32, there is a good comparison of the differences between the ESP8266 and ESP32 here https://makeradvisor.com/esp32-vs-esp8266/.
Download the latest Tasmota firmware binary from https://tasmota.github.io/docs/Download/.
We'll just get the standard uncompressed firmware image, this should be called 'tasmota32.bin' on the firmware page.
Open up the ESP-Flasher tool and select the serial port the ESP is connected to.
Browse to the firmware we have just downloaded and select it.
On the ESP hold the boot and reset buttons, release the reset button and select "Flash ESP" in the tool, you can now release the boot button.
Once the flash process completes, the device should reboot, if not just press the reboot button.
The logs should show the device booting back up. Look for available WiFi networks and something with the name 'tasmota' in it should be visible.
Connect to the WiFi network, the Tasmota ESP will run in Access Point mode, and runs a captive portal, so usually a webpage will open to the ESP on http://192.168.4.1/ if this doesn't appear just open a browser and connect to it.
Enter your Wi-Fi network settings and save the configuration, this will write it to the flash memory inside the device. The device will restart and join you network.
Next we will connect to the device on your network, your browser should redirect you, if not you can either IP scan for the device, or much simpler, back in the ESP Flasher tool, it should show the IP as it boots up.
[21:34:11]00:00:00.003 HDW: ESP32-D0WDQ6
[21:34:11]00:00:00.039 UFS: FlashFS mounted with 308 kB free
[21:34:11]00:00:00.069 CFG: Loaded from File, Count 5
....SNIP....
[21:34:12]00:00:00.935 WIF: Connecting to AP1 YOUR-WIFI in mode 11n as tasmota-A14000-0000...
[21:34:13]00:00:01.108 WIF: Connected
[21:34:13]00:00:01.372 HTP: Web server active on tasmota-A14000-0000 with IP address 192.168.10.190
Now we can configure the ESP with the MQTT settings so the device can communicate with Home Assistant.
In the menu, open 'Configuration' and 'Configure MQTT'.
The host is the IP (or DNS) of the Home Assistant server, enter the User and Password configured on the MQTT broker earlier and click on 'Save'.
After a reboot the device should reload the main homepage, you can go into the 'Consoles' menu to see the boot-up messages.
In Home Assistant, go back to the Add-ons in the 'Settings', 'Add-ons', and open the 'Add-on Store'. Find and install TasmoAdmin.
No configuration is required, so we can just go ahead and start the service.
Back into 'Settings' then 'Devices and Services' and there should be the Tasmota integration discovered. Press 'Configure' and it should automatically configure and detect the ESP device we've just flashed.
Once complete, our integrations page should show 1 device with some entities under the Tamota card.
We can click on the '1 device' to see some basic information about the ESP device.
Lets configure a sensor to monitor in the ESP device.
We'll start off with a DS18B20 temperature sensor module.
http://wiki.sunfounder.cc/index.php?title=DS18B20_Temperature_Sensor_Module.
This device is 3-5V, so connect VCC and GND to 3.3V and ground pins respectively on the ESP. The final connection will be DQ which is the 1-wire connection for transmitting the data, I've gone with pin D12.
In the ESP go into the 'Configuration' menu and select 'Configure Module', on GPOI12 select the SD18x20 module and 'Save'.
Once the device reboots, on the main screen we should see a temperature reading at the top of the page.
Back over in home assistant, we can check the homepage, and we should see the sensor listed and the current temperature reported by the sensor via the ESP.
We can add more sensors, lets add a ultrasonic module http://wiki.sunfounder.cc/index.php?title=Ultrasonic_Module.
This device requires 2 connections for data, one for sending the pulse and another for the return signal.
This device will handle 5V, so connect VCC and GND to 5V and ground pins respectively on the ESP. The connect Trig and Echo up to pins D25 and D26.
We the configure the sensor in the ESP module.
This time we are configuring GPIO pins 25 and 26 for the SR04 module and assigning one for the trigger and another for the echo. The trigger sends the pulse and the echo receives the signal back to turn it into a distance measurement.
We should see the sensor data on the homepage of the ESP.
By default, the sensor data is sent every 60 seconds, lets change that to every 10 seconds. In the ESP interface, open 'Console' and enter the command 'TelePeriod 10'.
You should see the frequency of the data being sent in the console change to sending every 10 seconds.
You should see the data update more frequently (every 10 seconds) in Home Assistant.
Great, now you can add more sensors, relays or whatever devices you want to your ESP and Home Assistant.