Introduction: Home Automation With NodeMCU, HomeAssistant & MQTT

About: I'm trying to share fragments of my modest knowledge by creating tutorials and videos about tech, networking, wireless...

Do you want to start transforming your home in smart home?
And also to do that cheap?

NodeMCU and HomeAssistant are here to help about that.
I recommend you to watch this video, maybe it will be easier for you to follow. Otherwise, follow steps bellow.


1 × NodeMCU v3 NodeMCU on eBay:

2 × Breadboards Breadboards on eBay:

1 × Photoresistor Photoresistor on eBay:

1 × Magnetic switch Magnetic switch on eBay:

1 × Relay Relay on eBay:

1 × Button Buttons and Resistors on eBay:

7 × Resistors (2x 10kohm,4x 100ohm, 1x 4.7kohm)

4 × LEDs LEDs on eBay:

20 × Wires Wires on eBay:

1 × Temperature sensor DALLAS Temperature sensor on eBay:

1 × Motion sensor (PIR) Motion sensor:

1 × ADDITIONAL: Power bank

Step 1:


Get all needed supplies (components) and let's start.

Step 2:

Connect all components accordingly to this messy sketch. Sorry because of wire mess. :(

Step 3:

Install PlatformIO IDE, HomeAssistant + Python

Once more, you can follow this video to see more details about installation of HomeAssistant and Python.
To follow step by step PlatformIO installation and to see how to upload simple blinking LED program check this video.

Please note that you don't need to use strictly PlatformIO IDE, but it will probably be easier for you to follow.

Step 4:

Copy code to main.cpp file from here.
Replace mqtt_server IP to IP of your PC on which the HomeAssistant is installed. Replace SSID and password with your desired Wi-Fi SSID and password. Upload to NodeMCU.

Step 5:

In windows search (start) write %appdata% and open .homeassistant folder.
There you will find configuration.yaml. Open it and replace all content with this one.

Be careful if writing something additional because config is space sensitive! It must be structured within its rules.

Start HomeAssistant on your PC if it is not already started. Enter IP of that PC and add port :8123 after it in browser. In top right corner you will find option to configure UI. Select that and again in top right corner find RAW config editor and replace its content with this one.

Step 6:

Check that everything is connected correctly and MQTT is working as it should by sending data every few seconds and test how every sensor is working.

On your smartphone go to browser and enter IP of your HomeAssistant server and add port :8123. Save web page to home screen and you have access to your new home automation system in one tap.

Now on the end I encourage you to expand this project to be more useful and not just for educational purposes.
Thanks for joining me through this project build. :)