Wemos D1 simple OLED display for OpenHAB

I managed to use an Wemos D1-mini and its OLED shield to create a mini-display for temperature, with (almost) no line of code.
Configuration is done once, and displayed information is entirely sent through MQTT.

Here’s a little tutorial:

  • Flash the D1 mini with Tasmota with tasmota-display.bin build
  • Perform the basic Tasmota setup (wifi, MQTT, …)
  • Connect the OLED shield on the D1 mini
  • Set the I2C pins :
    • Web interface / Configuration / Configure Module
    • D2 GPIO4 : I2C SDA
    • D1 GPIO5 : I2C SCL
  • Check the OLED shield is detected :
    22:11:45 CMD: i2cscan
    22:11:45 MQT: stat/esp01/RESULT = {"I2CScan":"Device(s) found at 0x3c"}
  • Configure the display settings through display commands :
    • DisplayModel 2 (SSD1306 ie OLED Shield)
    • DisplayWidth 64
    • DisplayHeight 48
    • DisplayMode 0
    • Optionally DisplayRotate 2 to display upside down
  • Finally, type use the Display command to check your display settings :
  • Optionally “Configure timers” to turn display on/off on fixed times

The device is now ready to receive MQTT “display commands”.
I created the following rule :

rule "esp01publishtemp"
    Item HueSensor1Temperature received update
    val mqttActions = getActions("mqtt","mqtt:broker:mosquitto-nas")
    val esp01Temp = String.format("%2.1f",(newState as DecimalType).floatValue)
	logInfo("esp01.rules", "esp01publishtemp : newState=" + newState + " ,esp01Temp="+esp01Temp)

Explanations : When HueSensor1Temperature item is updated (no matter if it’s MQTT based or not) :

  • Format the payload with 1 decimal
  • Format the display :
    • [0zf1] : Turn the display on (0), clear it (z) and select font 1
    • Display the text for the first line (“Outside” in french here)
    • [c1l2f2s2p-4] : On column 1 (c1) and line 2 (l2), select font 2 (f2), scale factor 2 (s2) and pad 4 characters to the right (p-4)
    • Display the value
  • Send the MQTT payload to the moquitto-nas broker

At first, nothing will be displayed until the first MQTT update.

This page list all display possibilities with tasmota.

Enjoy !