Tasmota: Difference between revisions
displays |
|||
| Line 79: | Line 79: | ||
|} | |} | ||
=== Peripherals === | ===Peripherals=== | ||
There are a different set of supported peripherals out of the box depending on which Tasmota build you used. Refer to the BUILDS page at https://github.com/arendst/Tasmota/blob/development/BUILDS.md to determine if a particular feature is enabled. | There are a different set of supported peripherals out of the box depending on which Tasmota build you used. Refer to the BUILDS page at https://github.com/arendst/Tasmota/blob/development/BUILDS.md to determine if a particular feature is enabled. | ||
I will cover some of the peripherals I have used in some of my projects below. | I will cover some of the peripherals I have used in some of my projects below. | ||
==== SSD1306 display ==== | ====SSD1306 display==== | ||
The SSD1306 is an OLED display that comes in various sizes. The Wemos D1 OLED module is one such device with a screen size of 64x48. Tasmota supports this display through the <code>tasmota-displays.bin</code> image. | The SSD1306 is an OLED display that comes in various sizes. The Wemos D1 OLED module is one such device with a screen size of 64x48. Tasmota supports this display through the <code>tasmota-displays.bin</code> image. | ||
To get the display working: | To get the display working: | ||
# Attach the display to the Wemos D1 stack. | #Attach the display to the Wemos D1 stack. | ||
# Configure the Tasmota pins so that GPIO4 and GPIO5 are set to I2C SCL and I2C SDA respectively. | #Configure the Tasmota pins so that GPIO4 and GPIO5 are set to I2C SCL and I2C SDA respectively. | ||
# Run i2cscan via MQTT or the console. You should see the display: | #Run i2cscan via MQTT or the console. You should see the display: | ||
{{Highlight | {{Highlight | ||
| code = 05:26:20.151 CMD: i2cscan | | code = 05:26:20.151 CMD: i2cscan | ||
| Line 97: | Line 97: | ||
| lang = text | | lang = text | ||
}} | }} | ||
# Configure the display in Tasmota by setting: | |||
#* <code>DisplayAddress 0x3c</code>, the address discovered by i2cscan | #Configure the display in Tasmota by setting: | ||
#* <code>DisplayModel 2</code>, for SSD1306 | #*<code>DisplayAddress 0x3c</code>, the address discovered by i2cscan | ||
#* <code>DisplayWidth 64</code>, <code>DisplayHeight 48</code>, for the display resolution | #*<code>DisplayModel 2</code>, for SSD1306 | ||
#* <code>DisplayDimmer 100</code>, to turn the display on | #*<code>DisplayWidth 64</code>, <code>DisplayHeight 48</code>, for the display resolution | ||
#* <code>DisplayMode 0</code>, for text mode | #*<code>DisplayDimmer 100</code>, to turn the display on | ||
# Save and restart (<code>Restart 1</code>) | #*<code>DisplayMode 0</code>, for text mode | ||
# Confirm that text can be written by running: <code>Displaytext Hello</code>. | #Save and restart (<code>Restart 1</code>) | ||
#Confirm that text can be written by running: <code>Displaytext Hello</code>. | |||
To control the text location, specify any arguments within square brackets before the text when calling the <code>DisplayText</code> command. For example, to print "Hello World" across two lines, we write hello on line 1 column 1 (l1c1) and world on line 2 column 1 (l2c1): | To control the text location, specify any arguments within square brackets before the text when calling the <code>DisplayText</code> command. For example, to print "Hello World" across two lines, we write hello on line 1 column 1 (l1c1) and world on line 2 column 1 (l2c1): | ||
| Line 110: | Line 111: | ||
| code = Displaytext [l1c1]hello | | code = Displaytext [l1c1]hello | ||
Displaytext [l2c1]world! | Displaytext [l2c1]world! | ||
| lang = terminal | |||
}}With the power of Tasmota rules, we can trigger text to be written when a state changes. In the case of a CO2 monitor, we can create the following rule which clears and prints the PPM value on the first line of the display whenever the value changes. | |||
{{Highlight | |||
| code = Rule1 on MHZ19B#CarbonDioxide do DisplayText [zc1l1]%value%ppm endon | |||
Rule1 1 | |||
| lang = terminal | |||
}} | |||
This rule would print "400ppm" if the CO2 reading was at 400, for example. | |||
Alternatively, we can also trigger rules on every TelePeriod time (the telemetry period) by prefixing the trigger with <code>Tele-</code>. This might be desirable for values that requires constant polling. | |||
{{Highlight | |||
| code = Rule1 on Tele-MHZ19B#CarbonDioxide do DisplayText [zc1l1]%value%ppm endon | |||
Rule1 1 | |||
| lang = terminal | | lang = terminal | ||
}} | }} | ||
Revision as of 04:44, 20 May 2021
Flashing Tasmota
Obtain ESPTool and the latest Tasmota binary. Use ESPTool.py to erase and load Tasmota via serial.
Here is what I did to flash a Wemos D1, for example.
$ python -m esptool --port /dev/ttyUSB0 erase_flash
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 50:02:91:fe:9d:a4
Uploading stub...
Running stub...
Stub running...
Erasing flash (this may take a while)...
Chip erase completed successfully in 8.6s
Hard resetting via RTS pin...
$ python -m esptool --port /dev/ttyUSB0 write_flash -fs 1MB -fm dout 0x0 tasmota.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting....
Detecting chip type... ESP8266
Chip is ESP8266EX
Features: WiFi
Crystal is 26MHz
MAC: 50:02:91:fe:9d:a4
Uploading stub...
Running stub...
Stub running...
Configuring flash size...
Compressed 613568 bytes to 438208...
Wrote 613568 bytes (438208 compressed) at 0x00000000 in 38.7 seconds (effective 126.8 kbit/s)...
Hash of data verified.
Leaving...
Hard resetting via RTS pin...
Configuration
After a factory reset, you will need to configure its WiFi settings manually by connecting to the WifiManager created access point. After it connects to the proper network, connect to it again through a web browser.
The following section applies to my own network and setup. For my own network, because the IoT devices are all in its own isolated network, I need to do a SSH tunnel in order to access the web interface. This is done by running: ssh -L 8080:192.168.1.x:80 root@iot-router and then connecting to localhost:8080 in a web browser. In the web interface, there are a few things that needs to be configured in order for it to work properly with the NodeRED/MQTT service outside of the IoT network.
- Setup the device template. Remember to check off 'activate' or else the template won't get applied.
- Configure MQTT. Set the host as
mqtt, port as1883, topic as the device name, and the prefix astasmota/%topic%/. The mqtt hostname resolves to the MQTT server and the IoT router allows MQTT traffic on port 1883 to leave the network to this server.
MQTT and hostname
When configuring the Tasmota hostname and MQTT strings, you may substitute variable names. This table outlines what you can use.
| Description | What you type | What you get |
|---|---|---|
| %06X | 0353C0 | |
| last 4 digits of mac | %04d | |
| hostname | %s | |
| MQTT prefix | %prefix% | One of: cmnd, stat, tele
|
| MQTT topic | %topic% | User defined. Eg: WP5-1
|
Peripherals
There are a different set of supported peripherals out of the box depending on which Tasmota build you used. Refer to the BUILDS page at https://github.com/arendst/Tasmota/blob/development/BUILDS.md to determine if a particular feature is enabled.
I will cover some of the peripherals I have used in some of my projects below.
SSD1306 display
The SSD1306 is an OLED display that comes in various sizes. The Wemos D1 OLED module is one such device with a screen size of 64x48. Tasmota supports this display through the tasmota-displays.bin image.
To get the display working:
- Attach the display to the Wemos D1 stack.
- Configure the Tasmota pins so that GPIO4 and GPIO5 are set to I2C SCL and I2C SDA respectively.
- Run i2cscan via MQTT or the console. You should see the display:
05:26:20.151 CMD: i2cscan
05:26:20.173 MQT: tasmota/D1-2/RESULT = {"I2CScan":"Device(s) found at 0x3c"}
- Configure the display in Tasmota by setting:
DisplayAddress 0x3c, the address discovered by i2cscanDisplayModel 2, for SSD1306DisplayWidth 64,DisplayHeight 48, for the display resolutionDisplayDimmer 100, to turn the display onDisplayMode 0, for text mode
- Save and restart (
Restart 1) - Confirm that text can be written by running:
Displaytext Hello.
To control the text location, specify any arguments within square brackets before the text when calling the DisplayText command. For example, to print "Hello World" across two lines, we write hello on line 1 column 1 (l1c1) and world on line 2 column 1 (l2c1):
Displaytext [l1c1]hello
Displaytext [l2c1]world!
With the power of Tasmota rules, we can trigger text to be written when a state changes. In the case of a CO2 monitor, we can create the following rule which clears and prints the PPM value on the first line of the display whenever the value changes.
Rule1 on MHZ19B#CarbonDioxide do DisplayText [zc1l1]%value%ppm endon
Rule1 1
This rule would print "400ppm" if the CO2 reading was at 400, for example.
Alternatively, we can also trigger rules on every TelePeriod time (the telemetry period) by prefixing the trigger with Tele-. This might be desirable for values that requires constant polling.
Rule1 on Tele-MHZ19B#CarbonDioxide do DisplayText [zc1l1]%value%ppm endon
Rule1 1