Home Automation Smart Node

Home Automation Smart Node

A central actor in my home automation system is a Smart Node. These small nodes can:

  • Detect motion
  • Sense temperature & humidity
  • Indicate status with an RGB LED
  • IR Receiver (not yet implemented in software)

Parts List

To build the Smart Node, you will need the following

  • Wemos D1 Mini, or NodeMCU (Any ESP8266-based breakout board will do)
  • AM-312 PIR Sensor – this must be the AM312; I had the same experience as BRUH Automation
  • DHT-22 – you can use DHT11 – but for a reliability/accuracy comparison see this entry here
  • An infrared receiver
  • RGB LED (I like 10mm frosted)
  • MicroUSB Charger
  • Wire to connect it all

as well as the following tools:

  • Soldering iron
  • Some form of case (either 3d printed if you have a 3d printer, or a plastic box + drill for making holes)
  • Optional: Dupont crimper/ends

The Hardware

My firmware assumes the following wiring setup, based on the Wemos pin labelling. (Boot) indicates this pin must have a certain state during ESP Bootup, so if you’re adding a new sensor be careful when using D3 or D8.

Pin Hookup Hookup Pin
tx rst
rx a0
d1 RGB Green d0
d2 Motion RGB Red d5
d3 (Boot) RGB Blue d6
d4 (Onbard LED),IR DHT d7
gnd GND (Boot) d8
5v Motion, DHT, IR LED + 3v3

A visual diagram of this hookup is as follows:

The Software

The software is based on the Espurna firmware. Espurna is designed for finished devices, so I needed to define my own device types. You can download a copy of my changes to Espurna from my github here.

Once the code is flashed to the ESP8266, you can connect to the web interface and set a password (the default username is admin/fibonacci). It also has a nice administration page where you can see if everything is wired correctly. Setting the light colour should set the light to the appropriate colour (test red, green and blue to ensure your LED is wired correctly), as well as see the current temperature and humidity:



Home Assistant Configuration

Light – add to lights/<file>.yaml:

Motion – add to automations.yaml & scripts/<script>.yaml

The motion is momentary only and needs to trigger a script. The motion and lack of motion are the same command, as Espurna considers this a button press. The motion triggers a script, which will then set timers and react accordingly.

Here’s an example of how I’m turning off a light after a certain amount of inactivity:

The above code turns the light off after a templated delay. This allows me to have short delays in places like hallways, and long delays in places where we tend to sit and not move, such as a living room. The template refers to an input in home-assistant, which can be set to the desired time delay. Any motion during this time will reset the timer, so the lights will turn off n minutes after the last motion was detected.  Here’s an example of the input:

Temperature / Humidity

The following can go into your sensors.yaml file



The Case

If you have access to a 3d printer, you can print out a case to house everything. Most of my Smart Nodes are currently in project boxes, which I drilled holes in, and these work just fine if you don’t have access to a 3d printer.

This was designed in OpenScad by a colleague who has graciously offered to share the code. You can download the OpenScad source files, as well as the STL files required to print here: smartnode-case.tar.gz


1 thought on “Home Automation Smart Node”

Comments are closed.