====== Project "SmartHome" build: Central ======
My personal project to build Smart Home system and learn [[https://github.com/micropython/micropython|Micropython]] by utilising [[https://github.com/lvgl/lv_binding_micropython|LVGL]] on ILI9341 display by using ESP32 microcontroller.
Initial idea was to have one SmartHome Central space where I could see all rooms temperature and humidity measures in one place. I'm also planning to add soil moisture sensor (built on my favourite ESP32) and later on- control some of appliances at home. I did not want to go with already built systems (HomeAssistant or Tasmota) as my goal was to learn to build multi-component system by myself.
{{:project:smarthome:diagram.jpeg?nolink&800|}}
=== Central Unit ===
[[https://github.com/lixas/SmartHome-Central|Source is available]] on my github repository. Comments and ideas are welcome.
Central unit is ESP32 generic (no PSRAM) with 4mb PSRAM microcontroller with Micropython + LVGL firmware and ILI9341 display. It listenf for messages in MQTT and display innformation on screen. Also weather integration is made: current weather outside and forecast
{{:project:smarthome:img_20210113_215647.jpg?nolink&200 |}}
{{:project:smarthome:img_20210113_215701.jpg?nolink&200 |}}
| Wire connection diagram ||
| ESP32 | ILI9341 |
| 3v3 | VCC |
| GND | GND |
| 26 | CS |
| 33 | Reset |
| 27 | DC |
| 23 | SDI (Mosi) |
| 18 | SCK |
| 32 | LED |
| 19 | SDO (Miso) |
| 14 | T_CLK |
| 15 | T_CS |
| 13 | T_DIN |
| 12 | T_DO |
| 35 (not used) | T_IRQ |
I've used two different SPI busses, One for ILI9341 and another one for XTP2046 (touch) as i had plenty of pins on my central device.
=== Proxy unit ===
[[https://github.com/lixas/SmartHome-Proxy|Source is available]] on my github repository.
Proxy unit is also ESP32 generic based device, witch listens to all available BLE advertisement packages. It filters know MAC addresses and forward that messages to [[https://en.wikipedia.org/wiki/MQTT|MQTT]].
=== BLE thermometers ===
Probably, this section may be most interesting for various DIY'ers :-)
{{:project:smarthome:thermometer.jpg?nolink&200 |}}
Once I've stumbled on Youtube video, where person was discussing to DIY or BUY temperature sensor. Probably, you can not DIY cheaper yourself, because this sensor cost 4$. Yes, four dollars! It can be used as stand alone device as it is has its own screen.
Issue was BLE advertisement is encoded. Dear Xiaomi- let us use your devices freely in out projects. Open source is future!
But lucky for us, DIY'ers, [[http://atcnetz.blogspot.com/p/info.html|AAron Christophel]] dedicated a lot of his own time and was able to write [[https://github.com/atc1441/ATC_MiThermometer|custom firmware]] for extra cheap (4$) Xiaomi Thermometer model LYWSD03MMC. Its easy to change firmware in thermometer with any regular Android device. No additional hardware is needed. To change firmware- download bin file from [[https://github.com/atc1441/ATC_MiThermometer/blob/master/ATC_Thermometer.bin|ATC github repository]] to your phone. Then open [[https://atc1441.github.io/TelinkFlasher.html|web flasher]]. I've used Android Chrome browser for flashing.
Always consult official repository how flashing procedure is done! It may change over time.
- Download firmware file
- Enable bluetooth on your device.
- Open [[https://atc1441.github.io/TelinkFlasher.html|web flasher]] page and press button "**Connect**" and choose your device. If it is the first time you flash firmware- its name will be LYWSD03 or something similar. After flashing- it will be **ATC_######**. Last six digit will be last six pairs of your device mac address.
- "**Do activation**". It connect to device and calculates Device ID, token and Bind key. Nothing will be changed in firmware.
- Choose bin file. Take care of what file you choose. Mistake can brick your device. Anyway, not a huge loss- it's dirt cheap :-)
- "**Start flashing**". It may take 60-100 seconds to complete. It should restart after finishing. If it did not- wait 5 minutes and remove battery from thermometer.
=== Soil moisture sensors ===
I'm planning battery (LiFePO4) powered ESP32 device to measure soil moisture of my balcony greens and send data to central unit via BLE advertisement. My choice of LiFePO4 battery was because it's perfect candidate to directly power ESP32 (without any power management devices). More about that in my later posts. Now i'm in progress of building this.
=== What i have learned ===
* How BLE advertisement works;
* Setup environment, required for Micropython firmware building;
* What is MQTT and how it works, setup server locally.
{{tag> Micropython python ESP32 ILI9341 SmartHome LYWSD03MMC}}
~~DISCUSSION~~