ESPHome – Home Automation Simplified
I was pleasantly surprised when I decided to try to add some DIY sensors to home assistant. Using ESPHome is extremely simple and in this post, we will learn how to control a GPIO pin and also obtain temperature & humidity data from a wireless node, by using Home Assistant. The best part is that it does not require any code to be written as it does this automatically.
Step 1: Watch the Video
It is much easier to see everything being done through a video first and that is why I’d recommend watching the video shown above to get an idea of how everything works. This post will only contain the important steps needed to do this yourself.
Step 2: Install ESPHome
First, we need to install the ESPHome add-on in Home Assistant. Navigate to the add-on store by doing the following:
- Hass.io -> Add-On Store
Add the following URL to the store so that it can find the ESPHome Add-On:
Once done, simply search for ESPHome, click the add-on that shows up and hit the install button. Installation may take some time so please give it a few minutes as this will depend on your internet connection. Once installed, simply hit the START button and wait a few seconds for it to start. Then, click the button that says “OPEN WEB UI” which will take you into the ESPHome screen.
Step 3: Configure the Board (Node)
In ESPHome, devices are called nodes, and we first need to create one so that it can then begin communicating with Home Assistant.
Click the add button to create a new node. Then give it a name by using the characters shown on screen. I will call it “living_room”. Then, select the device type which is “WeMos D1 Mini” for this demo. Finally, add your WiFi network details so that the board can connect to your WiFi network and then click “SUBMIT” to create the node.
ESPHome needs to be restarted after creating a new node. This can be done by navigating to hass.io -> ESPHome and then clicking the RESTART button. Give it a few seconds and then open up the WEB UI.
We now need to configure this node so that we can control the LED that is connected to pin D2. The ESPHome website contains all the information you need to configure different components and since we will be controlling a GPIO pin, we can use the example configuration entity information from the following page:
Click the EDIT button for the node and then paste the configuration information and update it as shown in the image and then, save the file. Since this is the first time we are using the board with ESPHome, we need to manually upload the code to the board. Once this is done, we can then automatically upload any updates wirelessly using the OTA update feature.
To manually download the code, we first need to compile it. So use the node options menu to compile the code for the node. This will take a while and it took about 100 seconds for me. Once done, simply download the binary file. Then, visit the following link and download the ESPHome flasher tool for your system:
Double click the file to open it. Then plug in your board, select the correct COM port, select the binary file we downloaded and then hit the FLASH button. This will download the code to your board so give it a few seconds to complete. Once done, the board will automatically connect to your WiFi network and you will be able to see this in the logs.
Step 4: Add the Node to Home Assistant
Home Assistant will automatically detect the board and give you a notification for it. You can either click that to get started or you can navigate to the following:
- Configuration -> Integrations
You will then be able to see the node, so click configure and confirm the addition. Now, all we need to do is add it to the dashboard. So head over to the dashboard/overview section and then select the “Configure UI” option from the options menu in the top right section. Then, click the Add button, select Entities and then give it a new name. You can then use the entity list to select the switch which will have the same name as the node. Click save, close the dashboard configuration view and that’s all you need to do. If you toggle the switch then the LED on the board should toggle as well and the state will be displayed on the dashboard.
Step 5: Interface the DHT11 Sensor
I will be using the DHT11 sensor to obtain temperature and humidity values. Connect it to the board by using the reference wiring diagram. You first need to copy the example configuration from the ESPHome website using the following link:
Then, head over to ESPHome and edit the configuration for the node by adding the configuration. Be sure to update the pin and also add the model name as seen in the image. Once done, simply hit the upload button and wait for it to complete everything. It will automatically create, compile the code and also upload it to the board wirelessly, using the OTA feature. Once complete, you will see the output logs and the board will automatically connect to your network.
Step 6: View the Temperature & Humidity Values
The next thing we need to do is add the sensor values to the dashboard. This step is similar to the previous section. Select the Configure UI option to create a new card, then give it a name and add the entities as shown in the image. Click save, exit the configuration screen and you will then be able to view the sensor information on screen.
That’s how easy it is to get started with home automation using ESPHome. We will continue interfacing different modules to home assistant so please do consider subscribing to our YouTube channel as it helps us create projects like this.
Thank you for reading!