Connecting a IKEA Vindriktning to Home Assistant Using ESPHome

by Noloxs in Circuits > Sensors

26240 Views, 25 Favorites, 0 Comments

Connecting a IKEA Vindriktning to Home Assistant Using ESPHome

frontpage.png
DISCLAIMER: Modifying the IKEA Vindriktning will probably mean that you loss your warranty. Just saying...


I recently setup Home Assistant with the plan of making it the brains of all my home automation. As part of this I wanted to look into which sensors I could use. IKEA then announced the release of the Vindriktning which turned out to be a quite affordable option in terms of particle sensors, all in a lovely small enclosure which helps with the "Wife-approval-factor"

The only issue was that the sensor didn't connect to ÌKEAs trådfri gateway (ZigBee), so I couldn't just connect it to my Home Assistant setup right away. After a bit of searching, I came across a few post describing how they had attached an ESP8266 to the sensor and together with ESPHome was able to get the sensor data from the vindriktning into their home assistant.

Supplies

needed_parts.png
NB: I am preparing the ESP module to work with OTA (Over the air) updates, so I can update the device later without having to disassemble it and attach a USB programmer to it. This is why it needs to be a ESP8266 with 1MB or more flash storage


Parts:


Tools:

Preparing the ESPHome Device

esphome-new-device.png
esphome-select-esp-device.png
esphome-menu.install.png
ESP Flasher.png

Prepare ESPHome Device firmware

I am not going to go through how to setup ESPHome in Home Assistant as they have already made an excellent guide for this: Setting up ESPHome

NB: If you are planing to make more than one of these, then please go to Step 6: Managing Multiple Devices as there in that case are some details that are worth knowing before integrating the ESP


Add a new device to ESPHome:

  1. Go to your ESPHome web-ui and press on the "New device" button
  2. Enter a name, e.g. ikea-vindriktning-01 and press next
  3. Select ESP8266 and press next
  4. Press install and select "Manual download"
  5. If this fails, as it did for me, then just press the menu button on the device and select install from there
  6. Save the install file to your computer

There are multiple ways to flash the ESP with the newly created binary, I will only be describing the one I used which is manual install. For more information regarding other ways to flash the device see the install dialog in the ESPHome web-ui


Install using: Manual download

  1. Start by downloading the newest version of the ESPHome Flasher, it can be downloaded here: https://github.com/esphome/esphome-flasher (I just used a premade release)
  2. Open the ESPFlasher
  3. Select the USB Programmer in the Serial port field (Red box)
  4. Select the device binary you just downloaded in the Firmware field (Blue box)
  5. Make sure that the ESP is in flash mode (Many flashers have a button or switch for this)
  6. Press the "Flash ESP" button

Once the ESP Flasher reports that it is done and the flashing was successful, you can then continue to the next step.

Adding Support for the Particle Sensor

Modify the device code

Go to your ESPHome web-ui and press the edit button on your vindriktning device and apply the following changes:

Add the following lines at the bottom

uart:
  rx_pin: GPIO2
  baud_rate: 9600

sensor:
  - platform: pm1006
    pm_2_5:
      name: "Particulate Matter 2.5µm Concentration"


Next we need to disable logging, by setting the baud rate to 0. This is needed for UART to work

# Enable logging
logger:
  baud_rate: 0

Press the save button and your are done.

You should now have something resembling this (The ota and ap passwords should be auto-generated and different)

esphome:
  name: ikea-vindriktning-01

esp8266:
  board: esp01_1m

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:

ota:
  password: "123456789012345678901234567890"

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ikea-Vindriktning"
    password: "1234567890" 

captive_portal:

uart:
  rx_pin: GPIO2
  baud_rate: 9600

sensor:
  - platform: pm1006
    pm_2_5:
      name: "Particulate Matter 2.5µm Concentration"


Verify the OTA is working

Before starting to integrating the ESP module make sure that OTA is working.

To do this, turn on the ESP (Not in flash mode) and go to the ESPHome web-ui. The device should show as "online" in the upper right corner.

When it is online, simple open the device menu and press install followed by selecting the "Wirelessly" option

NB: Do NOT proceed before this is working, as it will be a pain to reflash the ESP manually later. Trust me...


NB: Again, if you are planing to make more than one of these, then please go to Step 6: Managing Multiple Devices as there in that case are some details that are worth knowing before integrating the ESP

Preparing the IKEA Vindriktning

remove_screws.png
disconnect_sensor.png
remove_screws_pcb.png

Getting the IKEA Vindriktning ready doesn't require a lot.

  1. Start by removing the four screws on the back of the sensor, and place them someplace safe, so you don't lose them.
  2. Now disconnect the fan and sensor wires from the PCB (Be very careful not to damage the wires, pull on the plug not the wires)
  3. Remove the 3 screws on the PCB and remove it from the front panel


Prepare the ESP-01s Module

wires.png
prepared_modules.png

Prepare the electronics

First you need to remove the header pins on voltage regulator and ESP module.

NB: I was making two sensors at the same time, which is why there is two of each set wires in the picture.

Next you need to prepare the following wires, don't worry about making them match the exact lengths or color, it is just what I used, but remember it is always easier to make them short later then longer.

  • 1 x black and red wire about ~45mm
  • 1 x white and black ̣~25mm
  • 1 x yellow ~55mm
  • 1 x small jumper

Prepare all the wires by twisting and pre-tinning the ends. The only special case is the two black wires which you need to twist one of their two ends together before tinning.

The orientation of both the voltage regulator and the ESP module is important as they both have small LEDs showing state. So if you don't want these showing through the casing, turn the LEDs inwards and solder the wires to the same side as the LEDs (This is how I mounted mine)

Start by soldering the wires to the voltage regulator.

  1. The long red wire is soldered to VIN
  2. The long black wire is soldered to GND
  3. The long yellow wire is soldered to OUT

Then solder the wires to the ESP module (Google image search of ESP-01 Pinout)

  1. Connect VCC with EN using the small jumper wire
  2. Add the short black wire to GND
  3. The other end of the yellow wire to the VCC
  4. The white wire to GPIO2

Your electronics should now look similar to the picture.

Integrating the ESP-01s

modules_glued_in_place.png
assembled.png

Integrate the ESP to the IKEA Vindriktning

First you should start by pre-tinning the three pads on the PCB, the pads are, from left to right, REST (2), GND(4) and 5V(5).

Now solder the wires to the PCB:

  1. The other end of the long red wire to the 5V pad
  2. The ends of the two black wires to the GND pad
  3. The white wire to the REST pad


Confirm readings

Before continuing, make sure that everything is working as intended. To do this you need to reattach the sensor and fan to the PCB and power it all up using the USB C port on the PCB.

To confirm the readings, go to the ESPHome web-ui and find your Vindriktning device and press the "LOGS" button.

You should now being to receive log information from the device and if everything works as intended, then you should start seeing log statements like this:

Got PM2.5 Concentration: 4 µg/m³


Finishing the integration

Start by disconnecting the fan and sensor again. I found it easiest to start by screwing the PCB in while it is still easy to move the wires around.

I glued the ESP Module with the antenna facing down and the LED facing towards the PCB.

The voltage regulator was also just hot glued in place, but again with the LED pointing inwards.

The placement of the modules was so that they would affect the wind flow for the particle sensor the least as well as not requiring any modifications of the Vindriktning casing

Reconnect the fan and sensor and finally screw the front plate to the rest of the casing using the four screws.


Adding the device to Home Assistant

The only thing left is to add the device to Home Assistant so you are able to use it in your automations.

To do this open the Configuration menu in your Home Assistant instance and select "Devices & Services", from here you should be able to add your device to the ESPHome integration.

Enjoy!

Please leave a comment if anything is unclear or just want to add your input/improvements for all to see.

Managing Multiple Devices (Optional)

ESPHome operates on the principle that each device in the ESPHome web-ui corresponds to exactly one physical device. This means that if you were to take the same device binary and flash it to two separate physical devices, the two devices would essentially be seen as one, which isn't that useful in your home automation setup. And yes I learned this the hard way...

So the way to handle this is to have two devices in the ESPHome web-ui which have the same functional code, but doesn't share their IDs. But that presents another annoyance, you would then manually have to keep the functional code shared between them manually synchronized.

Fortunately ESPHome has a feature available called Substitutions which will allow us to make a single file which contains the shared functional code and each device will include this and substitute any variables need.


Installing a file editor

NB If you're already able to create and edit config files on your Home Assistant instance, then ignore the follow

To do this we need access to a file editor on the Home Assistant instance, there are many ways to edit the config files, so I will be going through the method I used, which is using the File editor add-on

  1. To install the file editor, open your Home Assistant and open your configuration menu
  2. From here select "Add-ons, Backups & Supervisor"
  3. You should now be in the Add-ons tap, able to click the ADD-ON STORE button in the bottom right corner
  4. In the store you can search / manually find and select the File editor add-on
  5. From here all you need to do is press the install button


Making the code suitable for multi-device use

Start by opening the File editor and pressing the "Browse Filesystem" button in the upper left corner (Folder icon). This should allow you to navigate to the following path:

config/esphome

This folder should contain all of your ESPHome devices as .yaml files.

In this folder we start by creating a new file and naming it something like:

.ikea-vindriktning-common.yaml
NB: It is important that you include the . (dot) at the start of the file name, this will hide it from the ESPHome web-ui so that this file doesn't show up as a separate device.


After creating it, we open it and add the following code and save the changes:

esphome:
  name: $devicename


esp8266:
  board: esp01_1m


# Enable logging
logger:
  baud_rate: 0


# Enable Home Assistant API
api:


ota:
  password: $ota_password


wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password


  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Ikea-Vindriktning"
    password: "1234567890"


captive_portal:


uart:
  rx_pin: GPIO2
  baud_rate: 9600


sensor:
  - platform: pm1006
    pm_2_5:
      name: "Particulate Matter 2.5µm Concentration"

The important difference in this code compared to the code in Step 2 is that the name and ota_password have been substituted with variables.

With the common code file created we can now edit each device in the ESPHome web-ui to look like the following.

substitutions:
  devicename: ikea-vindriktning-01
  ota_password: "123456789012345678901234567890"


<<: !include .ikea-vindriktning-common.yaml

All this does is define what the values of the two variables should be, and include the share code' using the include statement.

NB: This of course means that the values of the variables should vary between each device.

Finally just like in Step 2, you should be able to simple update the device using the OTA update feature

To make more devices, simply create a new device add the code above (with new values) and flash it to a new ESP module and you are done.