Tasmota
Installing |
Follow Steps with these icons |
---|---|
SnifferBuddy |
, |
Smart Plugs for MistBuddy |
, |
SnapBuddy |
, |
Tasmota has enabled us to build low-cost sensor and camera devices that primarily use MQTT to transmit sensor readings. To date, GrowBuddies have implemented two ESP hardware configurations: the Wemos D1 ESP286 for sensor functionality and the ESP32-AI Thinker Cam for capturing time-lapse and streaming video.
Resources
Wi-Fi module pinouts AI Thinker Tasmota Configuration documentation Tasmota ESP32-CAM Source Code
Commands To Verify the Install
Two commands, i2cscan
and i2cdevice
are extremely helpful in determining if the software and wiring are correct.
i2cscan
i2cscan
is an extremely useful command. Executing i2cscan
from the console is useful to show you if the i2c sensor is wired correctly. It is useful right after an installation to see if the wiring to the ESP286 is correct.
21:41:54.158 CMD: i2cscan
21:41:54.179 MQT: growBuddy/snifferbuddy/RESULT = {"I2CScan":"Device(s) found at 0x62"}
The above is a verification that the wiring works for the ESP286/SCD40 I built since 0x62 is the SCD40’s I2C address.
i2cdriver
i2cdriver
shows the list of drivers that were loaded by the Tasmota build. For example, by default, the SCD40 is not in the ESP286 Tasmota Sensors build. This is shown in Tasmota’s build table.
I find the builds table challenging to read. Here’s my take:
The rows are for each sensor where there is a Tasmota driver.
The s column is for sensors. I’m guessing (this is not obvious to me) the X (Sensor included) and - (Sensor not in build) in this column is referencing the ESP286 Tasmota sensors build.
The t column is for ESP286/ESP386 Tasmota build. This column says the SCD30 and SCD40 are in the ESP32 Tasmota build - so I assume also in the ESP32 Sensor build since it is a subset.
21:40:49.852 CMD: i2cdriver
21:40:49.861 MQT: growBuddy/snifferbuddy/RESULT = {"I2CDriver":"7,8,9,10,11,12,13,14,15,17,18,20,24,29,31,36,41,42,44,46,48,62"}
From the results of i2cdriver, I can see the SCD40 (which sits on i2c address 0x62) is in this build. I created a custom build in order to include the SCD40 in the set of software drivers shown by i2cdriver
.
Switchmode
The Tasmota command switchmode
commands Tasmota to send an mqtt message when there is a change in state. This command came in handy when I had an actuator that just needed on/off (like a power switch as the name implies).
switchmode1 15
switchmode2 15
Compile Tasmota with GitPod
To add a sensor to the build or debug, you’ll want to get into VS Code and play around with the code.
This video will get you started compiling using GitPod Compiling your own custom Tasmota on the web - No installs, no coding!.
follow the directions on the Tasmota Compiling page. Assume GitPod.
After building, go into the build_output directory, right-click on
tasmota-sensors.bin.gz
and click to download.
Go to the main Tasmota screen and select Firmware Upgrade.
Upload the sensor binary and click on Start Upgrade.
Flash Tasmota Onto a Sonoff Plug
We need a way to turn a plug on or off. For example, MistBuddy uses two Tasmotized plugs. One turns MistBuddy’s fan on and off. The other turns MistBuddy’s mister on and off. By Tasmotizing the plugs, other Buddies can send mqtt messages to turn a plug on or off.
The Sonoff S31 (or S31 Lite) can be flashed so that Tasmota is running on our local network. This YouTube video gives instructions on how to flash Tosmota.
ooh! Extra care when soldering. If not, well…it is way too easy to rip off one of the pads…
Once flashed and rebooted:
Put the plug back together.
Set the Module type to Sonoff S31.
Use the Tasmota S31 configuration when you go through the Tasmota install
Adding a Sensor Driver
ESP286/SCD30 Modifications
I added this section to maintain what I learned with the Wemos D1 + SCD30 Setup
I fixed a problem with the SCD30 + ESP286 (Wemos D1) not working without a restart. I couldn’t get the Tasmota team to look at it at the time it happened so I fixed it and submitted a PR. A bit later on, another person had the same challenge. Wonderfully, arendst pointed out From the datasheet it needs 2 seconds to power up. The current code doesn’t allow this. (see PR 15438). This may be unique to the Wemos mini D1 ESP286 (noisy power…?).
After further investigating the Wemos D1 powering and communication with the SCD 30, Arends notes: As I thought. The Wemos D1 is flakey at power on. (That’s what $1.50 buys us!). In latest dev there is a new command called SetOption46 0..255 allowing you to stall initialization for 0..255 * 10 milliseconds to let stabilize the local Wemos power. You might want to experiment with values like SO46 10 os SO46 20 for a 100mSec or 200mSec delay. If you own the Adafruit SCD30 you might also want to power the device from 5V as it draws a lot of power when measuring (notice the fainting power led because the wemos LDO just cannot provide enough power for the device. YMMV.
I have not had a challenge running on 3.3V. Obviously, Arendst knows ALOT so his advice should be kept in mind.
The SetOptions46
is avalailable in Tasmota 12.1.1
The files I modified include:
xsns_42_scd30.ino. From what I can tell, Tasmota started as an Arduino project. The interface into (3rd party) sensor code is a .ino file like this one for the scd30. The current code:
void Scd30Detect(void)
{
if (!I2cSetDevice(SCD30_ADDRESS)) { return; }
scd30.begin();
On the ESP2866 Wemos, the code doesn’t get past the initial if
statement in the scenario when the ESP8266 is powered up. It does pass when restarting with restart 1
on the command line. Most likely, powering up is taking longer on the ESP286 to the point Tasmota is impatient and doesn’t wait for the scd30 to be powered up. I did not debug further to find out how to robustly fix it. I got to a build that “works for me” with simply:
void Scd30Detect(void)
{
#ifdef ESP32
if (!I2cSetDevice(SCD30_ADDRESS)) { return; }
#endif
scd30.begin();
tasmota/my_user_config.h. For more info on this file see the Tasmota compiling YouTube video. I changed:
#define TEMP_CONVERSION false // [SetOption8] Return temperature in (false = Celsius or true = Fahrenheit)
to true
to show temperature readings in celsius. As the comment states, I could have set this on the command line using SetOption8 1
.