WeMos D1 Mini for Pool Temperature

Hey all,

In case it helps anyone, below are the steps for a project I just completed, which was to use a WeMos D1 mini PRO with a DS18B20 temperature probe to report the temperature of a pool into Home Assistant. The D1 Mini PRO is flashed with Tasmota, and the reporting is done via MQTT.

I’m relatively new to Home Assistant, and so it took me a while to work this out. There were a couple of good sources of information that helped me along:

  • The first is a website called “Neon – Sharing enlightening moments of home automation” by Malte Franken. On his website, Malte shows off a project where he used a WeMos D1 mini PRO with a DS18B20 temperature probe to report the temperature of a pool into Home Assistant (he also does a few other things with the same device). In his example, the D1 Mini PRO is flashed with ESPEasy. In my own home automation setup, I have multiple Sonoff devices that are flashed with Tasmota, and so instead I wanted to use Tasmota for this project to keep things standardized (and less work to support over time). Malte’s website is https://neon.ninja, and his GitHub site is at https://github.com/exxamalte.

  • The second is the youtube video “Tasmota + D1mini (or Sonoff) – Temp & Humidity, ws2812 LEDs, and Motion Detection” by DrZzs, published on March 19, 2018. DrZzs’ video was really helpful in helping me work out how to flash the D1 Mini PRO with Tasmota (which is a different process to doing this with a Sonoff), and I particularly liked his explanation of how to manage the configuration.yaml file. DrZzs is using a DHT11 probe to get temperature and humidity information in his example, but you can easily tailor the process for the DS18B20. Thanks DrZzs!

Hardware you will need

  • A WeMos D1 Mini PRO. I’m a fan of the D1 Mini PRO for several reasons, such as its small form factor, the ability to flash it with the Arduino IDE, it having onboard WiFi, and the capability to extend that WiFi signal / reception via an external antennae. The antennae was particular useful for this project, as in my case the D1 Mini PRO is mounted inside of a project box, underneath a wooden pool deck, about 50ft from the house. If you’re not sure what to buy, I recommend the “WeMos® D1 Mini Pro-16 Module + ESP8266 Series WiFi Wireless Antenna” from www.banggood.com. While this project is just about reporting temperature, the D1 Mini PRO has 11 pins, and so it provides the option to add other sensors or relays in the future, all on the same device.

  • A DS18B20 temperature sensor probe. When planning your project, give some thought to how long the cable on your probe needs to be. Malte used a one meter cable, but in my case I needed three meters, and so I went with the “DROK DS18B20 Temperature Sensor Digital Temp Probe Waterproof Thermal Cable Stainless Steel Probe 3 Meter Thermometer Gauge Thermistor Detector Sensor Indoor Outdoor Lab Car Usage” sold by DROK on Amazon.com. It works great. A tip though. Your probe is going to come with three wires – one for power, one for ground, and one for data. Be sure that you understand which color is for what function. My probe came with red, green and yellow wires, but while Red was for power (VCC 3.3V, as expected), green was for data (unexpected – as green can often be used for ground), and yellow was used for ground. After a few failed attempts, it too me looking at the Amazon comments to work out that I had the wires connected incorrectly.

  • A 4.7k resistor.

  • A project box to contain your D1 Mini PRO. I got mine from a local electronics store, but you could just as easily get one from Amazon. I recommend getting a project box that comes with an a pre-sized PCB, with ‘mounts’ so that PCB can be mounted inside of the box with room on either side of the PCB for through-hole soldering.

Software you will need

Initial / Test Hardware setup

  • Before we drop the D1 Mini PRO in the project box, I recommend putting it together on a breadboard to make sure everthing works. Malte has a really good diagram of what connects to what, which you can see below. Make sure the legs on your probe are connected to the correct pins (see my comments above).

  • Here’s what mine looked like:

Configuration

  • We need to setup the Arduino IDE to configure ESP8266 devices such as the D1 Mini PRO. In the Arduino IDE, select “File”, then “Preferences”. In the “Additional Boards Manager URLs:” field, type “http://arduino.esp8266.com/stable/package_esp8266com_index.json”.While you’re on this page, take a note of the ‘Sketchbook location:’ folder at the top of the window. You’ll need this shortly.

  • We now need to install the libraries needed by the Arduino sketch. Select “Tools”, then “Board: …”, then “Boards Manager …”.

    • Search for “esp8266”. Select “esp8266 by ESP8266 Community”, and “Install”.

    • Search for “json”. Select “ArduinoJson by Benoit Blanchon”, and “Install”.

    • Search for “pubsub”. Select “PubSubClient by Nick O”Leary”, and “Install”.

    • Open the “Sonoff-Tasmota-development/lib” folder. Take a copy of everything you find here, and copy it into a folder called ‘library’ in the Sketchbook location above.

  • Back in the Arduino IDE, open select “File”, then “Open”, and then the “Sonoff.ino” sketch. Select the “my_user_config.h” tab.

    • Look for the “// – Project -----” section. Give your project a name, and keep the quotes. I choose “Pool_Project”

    • Look for the “// – Wifi -----” section. Update the appropriate fields with your WiFi network SSID, and password, and keep the quotes.

    • Look for the “// – MQTT -----” section. Update the ‘MQTT_HOST’ variable with the IP address of your MQTT broker. IN my case, I’m using the embedded broker in Home Assistant, and so the IP address is the same as my Home Assistant installation.

  • Open Device Manger (in Windows, or your computer’s equivalent). Connect the D1 Mini PRO to your computer using the appropriate cable (in my case it is a USB to Micro USB), and take note of the new COM port number that appears.

  • Back in the Arduino IDE, Select “Tools”, then “Board: “Arduino/Genuino Uno”. Scroll to the bottom of the list. Additional boards will appear that were not shown earlier. Select “LOLIN(WEMOS) D1 mini PRO”

Select “Tools”, then “Port”, then the COM port name that you saw in device manager earlier. On the main IDE toolbar, select the circle with the tick to verify your code, and then the circle with the right-facing arrow to upload the code the D1 Mini PRO.

After the upload, unplug the D1 Mini PRO from the computer. Wait a few seconds, and then plug it back in. Wait for the D1 Mini PRO to boot up and associate with the network, and then check your router’s admin page or other network tool to identify it’s IP address. However you have your system setup, assign that IP address statically to the D1 Mini PRO.

  • Open a web browser, and input the IP address of the D1 Mini PRO. This should bring you to the ‘Sonoff’ web page that is being hosted by the D1 mini PRO. Select “Configuration” and then “Configure Module”. Under “Module Type”, select “18 Generic”. Select “Save”, and then the D1 Mini PRO will restart.

  • After the reboot, open a web browser and navigate to the same IP address. Select “Configuration” and then “Configure Module”. You will now see a list of pins on the Wemos D1 Mini PRO. Select the box next to “D7 GPIO13”, and select DS18x20 (4). This tells the D1 Mini PRO to expect temperature data from our probe through the D7 pin. Select “Save”

  • The board will restart, and this time if everything has worked ok, you’ll see the temperature value at the top of the Tasmota screen. Success!

Capture1

  • We’re almost there. Now in Home Assistant, open your configuration.yaml file, and add the following:

Capture4

  • Note that the ‘Pool_Project’ name needs to exactly match the project name that you gave your device in the Arduino IDE. If you watched DrZzs’ video, you’ll see that he had some trouble with the value_template function, and that he used a program called MQTT Lens to sniff the MQTT traffic to determine what the value should be in the configuration.yaml file. If you bought the same temperature probe from amazon that I did, you shouldn’t need to change anything. If you bought anything else however, I recommend downloading the using MQTT Lens to determine what the DS18B20 value should be. Check out DrZzs video if you need more information.

  • Save your configuration file, and restart home assistant. With some luck, you’ll now see the temperature reported in Home Assistant.

Capture3

Final Hardware Setup

So now that you have gotten this far, it’s time to put our breadboard setup into its final state in the project box. Here is what I did.

And that’s it. I hope this helps someone. If you use these steps and find any errors, please let me know and I will update / correct the post.

Skip

6 Likes

Neat project. FYI ESPhome considerably simplifies the firmware setup and has an api that works natively with home assistant without the need for mqtt. You can still use mqtt and I do simply as I find it aids debugging (you can see the device messages in an mqtt client).

1 Like

Thanks for sharing this and linking to my blog.

BTW: In the meantime I have actually migrated my own device to ESPHome. The migration itself was really simple and did not require any rewiring.

2 Likes

Thanks @exxamalte. I’m ready to migrate over to ESPHome. Would you mind posting a copy of your config for the device?

Sure, you can find the ESPHome configuration here under the heading “Device configuration”: Smarter Swimming Pool 5: Under the Surface – neon.ninja

Great write up. On to the project list it goes…

I have an old solar pool heater pump controller that uses 2 temperature probes. I assume I can plug both of these directly into the wemos D1?

1 Like

Well, that depends on the type of temperature sensor and wether it’s supported in ESPHome.