🔨〽️💦diy filament humidity sensor

If you dive in to the deep ocean of 3D printing, you will face the situation of storeing your filament in a proper way sooner or later. To be more precise, you want to keep your filament as dry as possible because most filaments absorb moisture. If you store your filament in a large box like I do, the humidity value in that box is kinda important. That was exactly the motivation behind this diy project. Of course, that’s not the only case for such a sensor. You can use it in many different scenarios where the humidity and or temperature value becomes important 😉.

Topview of the complete sensor.
The finished sensor ready to use

The Idea

I wanted to create a relatively small sensor, which is battery powered, rechargeable and can be easily integrated into Home Assistant. After some research, I decided to go with the following setup. A simple ESP8266 (D1 Mini) including a battery shield in combination with DHT-11 humidity & temperature sensor. This setup can be easily driven by an ESPHome sketch and seamlessly integrated into Home Assistant. It’s also small enough to fit into a small container which, in my case, was originally made for hair gel.

Parts list

For this project we will use the following components:

*Some links are affiliate links. If you use them to buy the parts for your project you will help me and my next project. These links will cause no extra fee or costs to you

Top view of all components used in this project.
All components

Prepare the D1 Mini

Start with soldering the female pin header to the D1 Mini. Mostly the D1 Mini comes with a variety of pin headers, select the female ones that fits best. Solder the pins to downside of the D1 Mini so that the WIFI antenna isn’t blocked by the battery shield if it’s connected.

Soldering process of the female pin headers
Soldering the pin headers

Prepare the battery shield

The battery shield will provide the power for the D1 Mini and will also take care of the battery charging process. That’s pretty neat, but with a slight modification, we can make the board even more useful. If you add a 100K Ohm resistor between the plus pole of the battery and the analog A0 pin, you can read the battery operating voltage, which can be used to calculate the capacity of the battery. With that value, you can create an automation in Home Assistant, to inform you if the sensor needs to be recharged.

Closeup of the resistor modification of the battery shield
Modified battery shield

Prepare the DHT-11

To connect the DHT-11 sensor to the D1 Mini grab some wires and presolder the ends on one side. Next snip of some heat shrinks and slide them over the soldered wires.

Presoldered cables with heat shrinks
Prepared cables

In the next step we will solder the wires to the DHT-11. The DHT-11 has 4 pins in general where the third one f.r.t.l isn’t in use. Solder the wires to DHT-11 as shown on the picture. I used red for positive, white for GND and green as the data wire.

The DHT-11 with soldered wires
The DHT-11 with soldered wires

Make a Sandwich😉

In this step we will connect the sensor to the D1 Mini and the battery shield. So flip the D1 Mini and slide the sensor wires into the females pin header. White goes to the GND pin, red to the 5V pin and green to the D4 pin of the D1 Mini. Further we will connect the RST pin with the D0 pin.

Downside of the D1 Mini with connected sensor and bridged reset pin.
D1 Mini with connected sensor and bridged pins

Connecting RST and D0(GPIO16) is very important, because our sensor will run on battery and not be continuously on. That would consume too much power and the battery would be empty within one or two days. To prevent this, our sensor will use a feature called deep sleep. With this feature enabled, the D1 Mini will only wake up every couple hours, take some measurements, send the data to Home Assistant and fall back into sleep / energy saving mode. This way is super efficient and will max out the battery life up to two weeks instead of two days. To enable deep sleep on an ESP8266 device you have to bridge these two pins, otherwise the D1 Mini will never wake up again.

If everything is setup properly, connect the battery shield and the D1 Mini. Keep an eye on the pins, the labels on the battery shield must match with the ones on the D1 Mini.

Close up of the battery shield connected to the D1 Mini
The senors sandwitch

Prepare the battery

Before we flash the D1 Mini with our sketch, we will prepare the battery to our sensor. If you don’t have a connector, you can simply solder the wires to the battery socket of the D1 Mini battery shield. In my case, I had a spare connector lying around, so I soldered it to the battery to make disconnections simpler. It’s also recommended to disconnect the battery from the D1 Mini while flashing. If you don’t use a connector, you have to disconnect the D1 Mini from the battery shield for the flashing process.

Battery with soldered connector
Battery with soldered connector

Flashing the D1 Mini

To flash the sketch to your D1 Mini, go to the ESP Home section in your Home Assistant installation and create a new project and start with a project name. I named mine diy-humidity-sensor.

Setup to name your device
Add a useful name

Next choose the board type. Because we are using a D1 Mini click on ESP8266.

Setup an new project in ESP HOME
Select the board

After that click on next and then on install to choose a preferred installation method. I always use the manual download option because I like to flash my ESP’s using ESP Home Flasher.

Finished setup

Install the sketch

To finish the installation, copy the script below to your editor, compile it and flash it to the D1 Mini. If you don’t use secrets, change the WIFI credentials to your needs. This sketch will create several sensors in Home Assistant including the battery percentage one. Further it will use the deep sleep function to operate 1 minute and then goes into sleep for 3 hours.

  name: diy-humidity-sensor

  board: d1_mini

# Enable logging

# Enable Home Assistant API

  password: "SuperSecr3t"

  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
    ssid: "Diy-Humidity-Sensor"
    password: "SuperSecr3t"


#VCC on batter
  - platform: adc
    pin: A0
    id: "LIFEPO"
    name: "A0 voltage x 3.0"
    update_interval: 18s
    accuracy_decimals: 3
      - multiply: 3.0
  - platform: template
    name: "diy-humidity-sensor-battery-voltage"
    unit_of_measurement: 'V'
    update_interval: 18s
    accuracy_decimals: 2
    lambda: |-
      return (id(LIFEPO).state);
  - platform: template
    name: "diy-humidity-sensor-battery-percentage"
    unit_of_measurement: '%'
    update_interval: 18s
    accuracy_decimals: 0
    lambda: |-
      return ((id(LIFEPO).state-2.2) /0.8 * 100.00);

#Temperature and humidity
  - platform: dht
    model: DHT11
    pin: D4
      name: "diy-humidity-sensor-temperature"
      name: "diy-humidity-sensor-humidity"
    update_interval: 18s
  id: deep_sleep_1
  run_duration: 60s
  sleep_duration: 180min

Finish the installation

After flashing the D1 Mini, grab your enclosure and ensure that the DTH-11 will be exposed to the air. I drilled some holes into the lid of my container to ensure that.

Topview of container lid with holes
Lid with holes

Last not least connect the battery to the battery shield and place everything inside the container.

Sensor in the container
Sensor in the container

UPDATE: During my tests, I found out that the LED on the D1 Mini uses a quite large amount of power. This will decrease the run time of the sensor, so I desoldered the LED from the D1 Mini 😬.

Check Home Assistant

After connecting the battery to the sensor, you will find a new ESPHome device in Home Assistant which provides the sensors, which were defined in the sketch.

Home Assistant entity list
Entity list

These entities can simply added to a dashboard or used in an automation.

Dashboard card
Values in the dashboard

Sum up

And that’s it. Your diy filament humidity sensor is ready to go 😁 You can now measure the current humidity and temperatue inside you filament storage. You can also use the sensor data in an automation which informs you if the humidity in your filament storage increases or exceeds a certain level. Or you can display the information on a dashboard like I did.

I hope you like this project and I’m looking forward to your comments and shares.

🏃🌡️💦 DIY Multi sensor with tasmota

In this project we’ll build a DIY Multi sensor which can recognize motion and measures the current temperature / humidity in the room. The brain of the sensor will be a D1 Mini (esp8266) which uses the tasmota firmware to collect all the data, hooks into your local WIFI and send them to Home Assistant.

The DIY Multi sensor

Parts list

In this project we will use the following components

  • One D1 Mini (esp8266) incl. long pins
  • An DTH11 temperature / humidity sensor
  • A AM312 PIR sensor
  • A 3D printed enclosure from thingiverse
  • Couple 0.8mm wire
  • Some heatshrinks
  • Hot glue
All components

Wiring up the components

First of we will solder the long pins to the D1 Mini. I chose the long variants because both sensors will use 5V and GND from the same pins. Using long pins makes the wire soldering easier later on. Alternatively you could crimp your own dual dupont cable to power both sensors, but i.m.h.o soldering works much better for a solid connection.

Solder the long pins

Second, we’ll solder the wires to the sensors. I my case, I used black for GND, red for 5V/VCC and yellow as the data wire. Double check the pins on the sensors, e.g. mixing GND and VCC will destroy them immediately. The AM312 should have markings on the board to identify the pins. The DTH 11 doesn’t so check the sensor description or take a look at my pinout on the picture.

Soldered sensors

After preparing the sensors we’ll solder them to the D1 Mini. Watch out that the wires of AM312 must be run to the enclosure first, because the sensor is mounted outside in not inside out.

Sensor outside in

We will solder the wires as follows to the D1 Mini:

  • Both sensor 5V / VCC to the 5V pin
  • Both sensor GND to the GND pin
  • The data wire of the AM312 goes to pin D1 (GPIO05)
  • The data wire of the DTH11 goes to pin D2 (GPIO04)

Also ensure to add a couple heatshrinks and some hotglue to prevent a short circuit inside the enclosure.

Sensors soldered to the D1 Mini

Last not least we will place all components into the enclosure, add a drop of glue to hold the AM312 in place and hook up a micro USB cable to connect everything to our PC.

Sensors in the enclosure

Installing Tasmota

After finishing the wiring we’re now able to flash the Tasmota firmware on the D1 Mini to connect it with Home Assistant and your MQTT broker.

First, plug in your multi sensor using a USB cable with data wires in it, open the Chrome/Chromium Browser, go to the Tasmota installation page and simply click “connect”

Tasmota installation wizard

Second, select the USB port your device is connected to and click “connect”. If your device does not show up you might need to install an additional driver. If so please try to install the CP210x or the CH341 drivers and retry the step.

Select device

After that go to the wizard, wait until Tasmota is installed on the D1 Mini. If the installation finishes successfully, your D1 Mini will spawn a WiFi-Access point called Tasmota_XXX.

Installation in progress

Connect to the access point and go to the IP Enter your WiFi credentials to add your multi sensor to your home network. Please keep in mind, that only 2.4GHz networks are supported.

Connect it to your home network

Configuring Tasmota

If the device is connected its time to configure the multi sensor the way we want it. Open the IP address in your browser and configure the device as follows:

1. Click on “Configuration” => “Configure Other”

  • Enable MQTT and the HTTP API
  • Give your device a proper name
  • Click save
Other settings

2. Click on “Configuration” => “Configure MQTT”

  • Add your MQTT IP and credentials
  • Change the topic to something more useful
  • Click save
MQTT settings

3. Click on “Configuration” => “Configure Module”

  • Select the module type generic
  • Click save
  • Click again on “Configuration” => “Configure Module”
  • Select “Switch” on the entry D1 with the number 1
  • Select “DTH11” on the entry D2
  • Click save
Module settings

You should now see the first temperature and humidity data on the Tasmota home screen.

Temperature values on home screen

To bring the AM312 in our DIY Multi sensor to life we have to add some console command to Tasmota. At the moment the PIR Sensor will only trigger the POWER event in the console. With the following commands we will configure it to send a useful MQTT payload which we can use in Home Assistant automation.

To set these configuration go to the home screen of your Tasmota device and click on “Console”. Than post the following commands one by one into the console and press “Enter”.

SwitchMode1 1
SwitchTopic 0
Rule1 on Switch1#state=1 do publish stat/%topic%/PIR1 ON endon on Switch1#state=0 do Publish stat/%topic%/PIR1 OFF endon
Rule1 1

In a nutshell, these commands will create a rule which will send the “ON” payload to the /stat MQTT topic if motion is detected and “OFF” if the sensor returns to the normal state. If you want to learn more about the SwitchMode, SwitchTopic and the Rule command please checkout the Tasmota Button and Rule documentation.

You can verify the result of the rule in the Tasmota console or on directly on your MQTT broker.

Console output

Use the data in Home Assistant

To use all the data in Home Assistant we can simply use the regular Tasmota and the MQTT integration. The Tasmota integration will create the entities for the DTH11 sensor and for the AM312 sensor we can simply watch for the MQTT topic and payload we created earlier in our automation.

Home Assistant Tasmota integration

If you want to use the the MQTT Result in Lovelace, you can create a new binary sensor for this in your configuration.yaml. This sensor can be used with the entity card and looks way better on a dashboard.

      - unique_id: binary_sensor.tasmota_multisensor_2_pir_sensor
        name: "tasmota-multisensor-2 PIR Sensor"
        state_topic: "stat/tasmota_multisensor_2/PIR1"
        availability_topic: "tele/tasmota_multisensor_2/LWT"
        qos: 1
        payload_available: "Online"
        payload_not_available: "Offline"
        device_class: motion

Sum up

And you’re done 😅. I hope you enjoyed the build process as much as I did and that you’re now looking at your own functional version of the DIY Multi sensor.

If you like, feel free to share your sensor on twitter and link me 😉