DIY 3D Printed Sensor Box for Home Assistant

Smart living is currently all the rage right now. With the proliferation of “smart” gizmos and gadgets, we’ve been forcibly trust into a dream world of science-fiction and convenience. As an aside, the global market share for home automation will soon eclipse $50 billion by 2020, so it’s huge! But as with everything in life there are trade-offs – convenience comes at a cost. In this post, I instead propose a relatively cheap and functional solution for a DIY multi-sensor device for the home that won’t break the bank!

Before we begin, I’d like to preface this guide with the following message: this guide assumes some basic knowledge of soldering and preferably access to a 3D printer or 3D printing services. As for the software side of things, I will not delve too much into Home Assistant and will leave it up to the reader to familiarize him/herself with this great piece of software.


The Smart Home

So in this post, I will share my recent experience using a completely free and powerful home automation hub called Home Assistant. As my readers will no doubt know, I’m no stranger to home automation. In fact, I’ve been relying on a completely custom setup I’ve created long ago to do similar things like turn on/off switches/lights, send alarm notifications, etc. But I’ve heard such great things about Home Assistant and let me just say, the rumblings are indeed true! This is a great piece of software and despite it being in its infancy, its potential is limitless. Let’s delve further.

The Cloud Hub

The brains of the local smart home is what we can the Hub, and note how I mentioned the word “local” in that description. Really to any sane mind, you’d figure that the hub should remain local to your network and not traverse the internet, right? There’s absolutely zero reason why you should need the internet to turn on a switch or illuminate a light bulb five feet away! More so, this hub acts as centralized system that manages all your connected devices and allows you to program automations – a sequence of actions that are taken based on triggered events – why would you want that power to reside on some foreign server anyway! And while the cloud provides some niceties, like remote storage, redundancy and convenience of access, privacy becomes a real issue for some – at least for me.

Home Assistant vs.

Enter Home Assistant…

Home Assistant is a an open source home automation tool that puts local control and privacy first. It integrates with a plethora of devices, protocols and technologies (way to much to ever list here) and is perfectly content on running on a Raspberry Pi, local server or even in a virtual machine – I as do.

Without a doubt, you’d want to install the variant called “”. While Home Assistant is only a Python program which can be installed on various platforms, is a more feature rich combination of Home Assistant and other tools which allows for easy installation and integration. It could be extremely confusing at first and you might even get bogged down with all the lingo and deciding suitable hardware for could also be a head-scratcher – but keep at it, it’s well worth it!

I do however suggest consulting this page for more information all possible ways to install Home Assistant. All right, enough with the sales pitch, get it installed (if you don’t have already) and lets move on to more interesting stuff!


Home automation is nothing if you don’t have devices like switches, sensors, or lights to integrate into your living space. And while the list of available devices, sensors and protocols can be daunting for most – not to mention costly – I prefer the DIY approach whenever possible. That’s why we’re creating our own because without sensors a smart home isn’t really that smart…


For this project we’ll be creating a multi-sensor box that can be placed wherever you can supply a 5V power source. So keep that in mind when thinking about placement in your home.

The following components will be needed:

Main Component List

  • WeMos D1 Mini Micro Controller
  • TEMT6000 Light Sensor
  • AM312 PIR Motion Sensor
  • BME280 Temperature, Humidity, Barometric Pressure Sensor

Miscellaneous List

  • 22-28AWG wires
  • Micro-USB cable
  • 5v power adapter (1000ma is fine)
  • 4-pin JST connector
  • Project Case

These components can be easily and cheaply had through the usually places like Ebay or Aliexpress. So
go shopping! (and then wait two months for the parts to arrive…)


We’ll be using the very popular ESP8266 Wemos D1 Mini (or rather clone of) to control the sensors and relay telemetry back via Wifi to HA. However, to shortcut the process and save us the hassle from writing complex Arduino sketches ourselves, ESPhome will be used.

For those that don’t know, ESPhome is a powerful ESP8266/ESP32 framework that uses configuration files to program the “brains” of your projects. Luckily if you already installed, ESPhome is a simply a few clicks away,>Add-on Store, search for “ESPHome” and bang, it should now appear in your side bar.

ESPhome Side Bar

ESPhome Side Bar

Putting it Together

The next portion of this guide involves connecting the various sensors to the ESP8266 and while Dupont connectors and header pins remain an option for us (provided you soldered header pins to the ESP8266 that is), I will instead elect to remove all header pins from the sensors and solder all components directly. This will provide a more robust connection and save some space in the process.

Motion Sensor

Hardware Configuration

The first component we’ll connect will be the AM312 motion sensor. For this sensor we are free to use either 3.3V or 5V but I have opted to go with the 5V pin as to free up the 3.3V pin for later use. We’ll also use pin D6 for the data line. Here’s the diagram.

ESP8266 and AM312 Diagram

ESP8266 and AM312 Diagram

ESPhome Configuration

At this point we should attempt to program the ESP8266 for the first time. Connect the micro-USB end to the ESP8266 and the other end to your HA’s USB port and in ESPhome hit the “plus” icon to create a new node.

Give it a name, I chose “sensor_node1”, enter “Generic ESP8266” for the device type, and insert your WiFi credentials then click submit. Edit the node after creation and the configuration file should look something like this:

  name: sensor_node11
  platform: ESP8266
  board: esp01_1m

  ssid: "xxx"
  password: "xxx"

# Enable logging

# Enable Home Assistant API


I added the manual_ip section, go ahead and do the same if you like. Compile and upload it to the ESP8266, hopefully all is good and your newly created node appears on your network. If so, you can remove the USB cable and future uploads can be OTA (Over-the-air) without the cable. Cool!

Let’s now add the section for the motion sensor, compile and upload.

  - platform: gpio
    pin: D6
    name: "Sensornode 1 Motion"
    device_class: motion

Home Assistant should have already notified you of a newly found integration, if not, go to Configuration->Integrations and the motion sensor should be available and ready for testing under the name “binary_sensor.sensornode_1_motion“.

You can test the sensor by going back to ESPhome and by clicking “SHOW LOGS” and observing the output while waving your hand in front of the sensor or you can use the states pages in HA (Developers->states) to monitor its state.

Hopefully this works for you, if so, let’s move on to the next sensor.

Light Sensor

Hardware Configuration

The TEMT6000 sensor is a light sensor, connects to the only analog pin (A0) of the ESP8266 and measures the ambient light from 0-200 in LUX units. More information about this sensor is here. I wired this sensor as follows:

ESPhome Configuration

Now for the ESPhome configuration:

  - platform: adc
    pin: A0
    name: "Sensornode 1 Illuminance"
    unit_of_measurement: lx
      - lambda: |-
          return (x / 10000.0) * 2000000.0;
    update_interval: 30s

Compile, upload and test. You should now have a new sensor called: “sensor.sensornode_1_illuminance“. Play around with it, I used a flashlight to forcibly alter the light to the sensor. Inspect that the sensor does indeed change value after 30 seconds, which is what we set as the update interval.

Temperature, Humidity, & Pressure Sensor

Hardware Configuration

The last sensor we’ll add is the BME280 sensor which is an all-in-one temperature, humidity and pressure sensor. Information about that sensor can be found here. This sensor is slightly different in that it needs 4 wires and requires I²C to be set up in your configuration for it to work. I²C is a special bus type that is used to attach lower-speed peripherals to processors and microcontrollers within short distances and which also allows daisy chaining.

As usual, ground goes to ground. We’ll also supply 3.3 volts and connect both SDA/SCL go to their respective pins.

Let’s look at the wiring diagram for this:

ESP8266 to BME280 Diagram

ESP8266 to BME280 Diagram

ESPhome Configuration

As mentioned earlier, we need I²C to be set up for this sensor to work. The following snippet accomplishes this:

  sda: D2
  scl: D1
  scan: False

And don’t forget the sensor configuration:

 - platform: bme280
      name: "Sensornode 1 Temperature"
      oversampling: 1x
      name: "Sensornode 1 Pressure"
      name: "Sensornode 1 Humidity"
    address: 0x76
    update_interval: 30s

A couple of things to note here. First off the “sensor:” line needs to only appear once in your configuration, ensure that you have not copied that line twice. Secondly, the BME280 is very sensitive and has the tendency to “self-heat”, thereby throwing off its readings. Because of this, I’ve changed the oversampling from 16x (as recommended on the ESPhome site) to 1x in effort to combat this.

Once more, compile, upload and test. This adds three new sensors for us to use: “sensor.sensornode_1_temperature“, “sensor.sensornode_1_humidity” and “sensor.sensornode_1_pressure“.

Here are all my sensors in action:

Home Assistant Sensor Frontend

Home Assistant Sensor Frontend

Project Case

I really couldn’t find a case that would fit the bill for this project, so I decided to design one in Fusion 360. The original goal was to house all the components within the same case but after getting higher than normal temperature readings (probably due to the heat coming off the ESP8266), I opted instead to put the BME280 sensor within its own case and connect the two with a 4-pin JST connector (again, easily found on ebay). Not elegant by any means but at least the temperature measures are more realistic, which is what we want.

The light sensor connects to the lid with a dab (ok large dab) of hot glue to secure it in place and the motion sensor and ESP8266 are housed within the bigger case. See shots below.

You’ll find the STLs here for my case at thingiverse.

Project Box Fusion 360 Model

Project Box Fusion 360 Model

The completed project!

Home Assistant and Beyond

Finally we can place the finished project somewhere strategic and use the sensors in our automations.

With a little more effort and using two additional add-ons; InfluxDB and Grafana, we could capture and graph data over time. Perhaps a topic for a later post…

Grafana and InfluxDB

Grafana and InfluxDB

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.