ESP8266 + DHT22 + Homie -> Home-Assistant

So now that I had a Home-Assistant (HA) setup working, an esp8266 booting and that I can write software for, it was time to start making the two talk to each other and make something that can become unseful based on all this.

The choice went to the simplest element I had at hand, a DHT22 temperature and humidity sensor.

There were 5 steps to do this:

  • wire the dht22 on a test setup
  • find how to use it in a Homie firmware, and flash it
  • configure the device
  • configure HA for MQTT, which led me to rewrite the whole configuration
  • test it

So let's get to this step by step

Wiring the DHT22

It can be pretty simple, without pullup resistors and capacitor, I found this on instructable


I simply put this to another GPIO on my esp12f, but that's pretty much it. The result on the breadboard looks like this:

dht22 breadboard

That's about it, for testing of course, for a final sensors, I'll have to make it cleaner than that...

Homie firmware

I started looking up for code on how to use homie with the dht22, there are libs to make use of it, running:

platformio lib search dht

Showed me the DHT sensor library that is esspressif compatible, I simply installed it via:

platformio lib install 19

After that I looked online at examples to use it, and actually found this code which does exactly what I expected. At first I started writting each lines trying to include only the needed one. But I think this is really close to the bare minimum to get something fully working, so I simply renamed it to raton-dht and switch the version to 0.0.1.

Jumping a little off-topic, the version number has an interest, because Homie support OTA, using the pretty cool homie-ota, which includes a listing of firmware and an inventory of devices, which is pretty awesome for handling yor homie devices and update them if need be. I haven't tried it yet myself, but I definitely will once I get real devices up and running in the house. This really looks like a must-have to me. Once again, thanks jpmens!

Back on tracks, not having the OTA setup yes, I simply switched my GPIO0 to low and ran:

platformio run -t upload

And the next boot the dht sensors firmware was sitting in configuration mode.

Homie configuration

In the previous post, I didn't explain how to configure the homie devices, I actually did not discover it at this step, I played with this on the previous useless firmware to understand how it works.

First it is worth noting that the homie-esp8266 documentation has been moved from github to, there on the http json api page, you can find the 3 options that you can use to configure your device in configuration mode:

  • the Web UI
  • the android app which apparently is a a webview directly to the webui (at least that's my guess)
  • a curl example, but you'll need to know what the config.json looks like like described in the dedicated page

In any case, you'll need to be connected to the AP the homie device will create when in configuration mode, for me, working on a workstation, and not having my laptop at hand (and feeling too lazy to grab it, plug it as it isn't charged right now, configure another wireless device via wpa_supplicant), that only left me with my android phone... But there is a catch: android checks that it can reach outside to actually let you use your wifi connection.

I found here that on a rooted device you can run:

settings put global captive_portal_detection_enabled 0

This did the trick for me, so I ran that, connected to the Homie-XXXXX AP, and fired the android app, which found the device, and allow me to configure it, the configuration is pretty straightforward and short, once this is done, you can finally reboot the homie device in normal mode, where it connects to your AP/router and start trying to talk to the mqtt broker. Now on to the HA setup.

Home-Assistant MQTT configuration

As said in the previous post, I was planning on using the embedded MQTT broker in HA. According to the MQTT component page, to enable MQTT support in HA, we have to add


To the configuration file, other parameters are for specifying the broker, to use the embedded one, without further configuration, that's it. Restarting HA with that enables the MQTT broker.

Next we need to configure the sensors, but when I started to look to add this I realized how messy my HA configuration had become, with so few things it looked already pretty cluttered with useless things, comments that are only usefull when beginning to use it. So i decided to go for a huge cleanup and rewrite.

First step, version control, I planned on splitting it in multiple files, and this won't be any easy to handle and maintain if not in git, so I created a ha-cfg github repo

I went from this to that

It took some fiddling to understand the !include which is not totally obvious to use, but I'm pretty happy with the final result.

Now in my sensors.yaml I simply added

# temperature test
- platform: mqtt
  state_topic: devices/01397be0/temperature/degrees
  name: "Test temperature"
  qos: 0
  unit_of_measurement: "°C"

# humidity test
- platform: mqtt
  state_topic: devices/01397be0/humidity/relative
  name: "Test humidity"
  qos: 0
  unit_of_measurement: "%"

And I was all set.


After that and restarting HA with the new configuration, I booted the esp again and could see:

** Booting into normal mode **
{} Stored configuration:
   Hardware device ID: 01397be0
   Device ID: 01397be0
   Boot mode: normal
   Name: dht#1
     SSID: SFR-5458
     Password not shown
     Port: 1883
     Base topic: devices/
     Auth? no
     SSL? no
     Enabled? yes
     Port: 80
     Path: /ota
     SSL? no
 Attempting to connect to Wi-Fi...
 Wi-Fi connected
Triggering HOMIE_WIFI_CONNECTED event...
 Attempting to connect to MQTT...
Sending initial information...  OK
Subscribing to topics...  OK
 MQTT ready
Triggering HOMIE_MQTT_CONNECTED event...
Calling setup function...
Sending Wi-Fi signal quality (100%)...  OK
Sending uptime (8s)...  OK

And on HA web-ui I know have test humidity and test temperature sensors showing up on the top row.


And that's it!

21 août 2016 12:39:25 -- tags [ esp8266 , dht22 , home-assistant , homie ]

22 juin 2017 19:43:22 - JohnetteX

I see your page needs some fresh content. Writing manually takes a lot of time, but there is tool for this boring task, search in google: murgrabia's tools

20 août 2017 17:46:42 - car insurance quotes

auto insurance quotes cheapest car insurance cheap insurance for cars cheap car insurance online

9 septembre 2017 15:01:14 - nurpnzrix

payday loans online same day <a href=""> payday loans with no bank account</a> &lt;a href=&quot;;&gt; payday loans&lt;/a&gt; - online payday loans payday loans online direct lenders only

1 février 2018 13:48:59 - WinnerAmeks

If you’re interested in winning millions, then I’m here to help! At <a>Casino</a> you can play over 450 world-class games and I’m giving you an exclusive Welcome Bonus to get you stuck into winning. Use it today to increase your chances of hitting our jackpots. All you have to do is <a>sign up today</a> and watch the rewards come rolling in. <a>Prepare to hit the big time</a> <a>Hacer giros para ganar millones</a> <a>Holen Sie sich spinnen, um Millionen zu gewinnen</a> <IMG></IMG>

12 mars 2018 22:03:23 - Josephmub

Thanks! I enjoy this. which is better levitra or viagra or cialis <a href="">buy cialis online</a> what is cialis pills for <a href=>generic for cialis</a>

5 avril 2018 14:31:09 - Guestbroni

guest test post <a href=" ">bbcode</a> <a href="">html</a> simple

17 mai 2018 12:55:09 - AnthonyThype

<a href="">canadian pharcharmy online</a> <a href=>best online international pharmacies</a>

22 mai 2018 18:31:44 - reputable mexican pharmacies online

<a href="">online pharmacy</a> <a href=>no prescription pharmacy canada</a>

4 juin 2018 13:15:04 - canadian pharmacies online

<a href="">canadian pharmacy</a> <a href=>legitimate canadian pharmacies</a>

10 juin 2018 04:13:29 - canadian pharmacy

<a href="">canadian pharmacies shipping to usa</a> <a href=>approved canadian online pharmacies</a>

13 juin 2018 07:17:01 - best online pharmacy

<a href="">prescriptions from canada without</a> <a href=>rx online no prior prescription</a>

25 juin 2018 16:48:01 - Webseokl

<img src=""> <a href=><img src=""></a> Понятно, что вручную их не вариант каждый раз проверять. В данном материале я рассмотрю несколько сервисов и программ, которые решают этот вопрос. Блог SEO Jedi. Продвижение сайта в тематике «Окна ПВХ» Всем привет! Подбор площадок <b><u><a href=>раскрутка сайта на яндекс</a>. </b></u> Сегодня хочу рассказать о создании и дальнейшем продвижении сайта по продаже окон ПВХ. Конкуренция у этих товарищей жесточайшая, поэтому и подходы к раскрутке и рекламе должны отличаться от лидеров мнений, чтобы хоть какая-то была возможность появляться в органическом поиске, а не только вбухивать умопомрачительные бюджеты в контекст. Начну историю с истории создания сайта. В процессе расскажу, какими сервисами пользуюсь при работе по созданию и продвижению сайтов. (more…) Качественные ссылки для Google и Yandex. Всем привет! Это один из самых важных моментов, который будет влиять на дальнейшее продвижения ресурса <a href=>продвижение синоним</a>. Обратные ссылки — это один из самых больших и устойчивых факторов ранжирования поиска. Ссылки были важны с самого начала существования поисковых систем, и я могу гарантировать, что они будут важны до тех пор, пока существуют поисковые системы. Ссылки являются основой SEO, но за последние годы они сильно изменились. запросы: <u><b>продвижение сайта с нуля, </b></u> раскрутка и оптимизация сайта, раскрутить интернет магазин самому, продвижение сайта в топ яндекса, seo продвижение сайта обучение, продвижение сайта google adwords, продвижение сайтов, <b><u>раскрутка сайта что это такое, </b></u> раскрутка сайта google, продвижение компании в сети интернет диплом, <u><b>продвижения на английском, </b></u> продвижение сайта на яндексе цена, <img src="">

21 juillet 2018 20:24:18 - online pharmacy no prescription

<a href="">canadian pharmary without prescription</a> <a href=>legitimate canadian pharmacies</a>

7 août 2018 18:35:56 - canadian mail order pharmacies to usa

<a href="">canadian pharmacies shipping to usa</a> <a href=>safe canadian online pharmacies</a>

21 septembre 2018 12:50:50 - Auto approve list

I’m compiling my latest list. I’m sorry there hasn’t been any recent updates. I’ve had some problems building the list along the way. I’ll talk more about that at a later date.

27 septembre 2018 05:11:28 - Free auto approve list 9-25-2018

I added a new blog post yesterday. There’s a smaller list than usual in it. I’m currently working on a bigger list. It’s going to take some time to compile it. I hope all of you are having a good week. I’m planning on doing some design changes to my site. I’m also thinking about adding some new things too. I’ll talk more about that in the days and weeks to come.

28 septembre 2018 08:44:09 - Free auto approve list 9-25-2018

I added a new blog post yesterday. There’s a smaller list than usual in it. I’m currently working on a bigger list. It’s going to take some time to compile it. I hope all of you are having a good week. I’m planning on doing some design changes to my site. I’m also thinking about adding some new things too. I’ll talk more about that in the days and weeks to come.

2 octobre 2018 19:59:48 - Free auto approve list 10-2-2018

I just updated my site with a new list. I’ve also come to a new conclusion about how many of these links exist out there. I’m not too sure if my conclusion is right or not. Read all about it in my latest blog post. See you there!

4 octobre 2018 13:41:15 - Find a fuck buddy

What's up to every , since I am really keen of reading this web site's post to be updated daily. It consists of pleasant information.

6 octobre 2018 02:23:19 - Milf Selfies

I'm really impressed with your writing skills as well as with the layout on your blog. Is this a paid theme or did you modify it yourself? Anyway keep up the excellent quality writing, it is rare to see a great blog like this one today.

7 octobre 2018 03:01:30 - Free Online Dating

Hi all, here every person is sharing these kinds of familiarity, therefore it's good to read this webpage, and I used to pay a visit this web site every day.

9 octobre 2018 14:26:13 - NarcosXXX

Oh my goodness! Impressive article dude! Many thanks, However I am encountering problems with your RSS. I don't know why I cannot subscribe to it. Is there anyone else getting similar RSS problems? Anybody who knows the answer will you kindly respond? Thanx!!

13 octobre 2018 07:38:10 - Snack Subscription

The other day, while I was at work, my sister stole my iphone and tested to see if it can survive a forty foot drop, just so she can be a youtube sensation. My iPad is now broken and she has 83 views. I know this is entirely off topic but I had to share it with someone!