I recently learned about the ESP8266, a $5 chip that includes WiFi and is Arduino compatible. This means that all your DIY projects can now be done for a fraction of the price.
@@ -169,355 +170,11 @@ Home Assistant will keep track of historical values and allow you to integrate i -Components
- -I’ve been using Adafruit for my shopping:
- --
-
- Adafruit HUZZAH ESP8266 Breakout (assembly instructions) -
- Adafruit HDC1008 Temperature & Humidity Sensor Breakout Board (assembly instructions) -
- MQTT server -
Besides this, you will need the usual hardware prototype equipment: a breadboard, some wires, -soldering iron + wire, Serial USB cable.
- -Connections
- -On your breadboard, make the following connections from your ESP8266 to the HDC1008:
- -ESP8266 | -HDC1008 | -
---|---|
GND | -GND | -
3V | -Vin | -
14 | -SCL | -
#2 | -SDA | -
I picked #2
and 14
myself, you can configure them in the sketch.
Preparing your IDE
- -Follow these instructions on how -to install and prepare the Arduino IDE for ESP8266 development.
- -After you’re done installing, open the Arduino IDE, in the menu click on sketch
-> include library
->
-manage libraries
and install the following libraries:
-
-
- PubSubClient by Nick ‘O Leary -
- Adafruit HDC1000 -
Sketch
- -If you have followed the previous steps, you’re all set.
- --
-
- Open Arduino IDE and create a new sketch (
File
->New
)
- - Copy and paste the below sketch to the Arduino IDE -
- Adjust the values line 6 - 14 to match your setup -
- Optional: If you want to connect to an MQTT server without a username or password, adjust line 63. -
- To have the ESP8266 accept our new sketch, we have to put it in upload mode. On the ESP8266 device -keep the GPIO0 button pressed while pressing the reset button. The red led will glow half bright to -indicate it is in upload mode. -
- Press the upload button in Arduino IDE -
- Open the serial monitor (
Tools
->Serial Monitor
) to see the output from your device
-
This sketch will connect to your WiFi network and MQTT broker. It will read the temperature and humidity
-from the sensor every second. It will report it to the MQTT server if the difference is > 1 since last
-reported value. Reports to the MQTT broker are sent with retain set to True
. This means that anyone
-connecting to the MQTT topic will automatically be notified of the last reported value.
1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -48 -49 -50 -51 -52 -53 -54 -55 -56 -57 -58 -59 -60 -61 -62 -63 -64 -65 -66 -67 -68 -69 -70 -71 -72 -73 -74 -75 -76 -77 -78 -79 -80 -81 -82 -83 -84 -85 -86 -87 -88 -89 -90 -91 -92 -93 -94 -95 -96 -97 -98 -99 -100 -101 -102 -103 -104 -105 -106 -107 -108 -109 - |
|
Configuring Home Assistant
- -The last step is to integrate the sensor values into Home Assistant. This can be done by setting up -Home Assistant to connect to the MQTT broker and subscribe to the sensor topics.
- -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 - |
|