A MicroPython lib for automatically registering IoT devices with a Home Assistant server via the MQTT-discovery protocol.
(And various example devices using the lib, such as thermostats, valves and sensors.)
This project is under active development.
The aim is to create a framework for registering ESP8266 and ESP32 devices (eg sensors and lights) with Home Assistant via MQTT Discovery protocol.
The MQTT Discovery lib is mostly stable and could be used in any project:
For example usage see:
- ./build/py/counter/ ← basic
- ./build/py/environment_sensor/ ← medium
- ./build/py/light_solar_security/ ← medium
- ./build/py/solar_hot_water_controller/ ← complex
- ./build/py/valve/ ← medium
https://pipenv.readthedocs.io/en/latest/
pip install --user pipenv
or
brew install pipenv
then
pipenv install
https://github.com/espressif/esptool
https://github.com/wendlers/mpfshell
http://micropython.org/webrepl/
Give user access to /dev/ttyUSB0:
sudo usermod -a -G dialout $USER
sudo usermod -a -G tty $USER
sudo reboot
Downloads: https://micropython.org/download#esp8266
Erase:
PORT=/dev/tty.usbserial-1420
pipenv run python -m esptool --port $PORT erase_flash
Flash:
pipenv run python -m esptool --port $PORT --baud 115200 write_flash 0 bin/esp8266-$VERSION.bin
Instructions from here:
micropython/micropython#2335 (comment)
Erase:
pipenv run python -m esptool --port $PORT --after no_reset --baud 460800 erase_flash
Flash esp_init_data_default.bin
:
pipenv run python -m esptool --port $PORT write_flash 0xffc000 bin/esp_init_data_default.bin
Flash to the 16mb ESP8266 module (eg. Lolin D1 Mini Pro) for your version of esp8266-*.bin
:
pipenv run python -m esptool --port $PORT --baud 460800 write_flash -fm dio -fs 16MB 0x00000 bin/esp8266-$VERSION.bin
Downloads: https://micropython.org/download#esp32
pipenv run python -m esptool --port $PORT erase_flash
pipenv run python -m esptool --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ~/Downloads/esp32-$VERSION.bin
pipenv run mpfshell
From the top-level project directory, run the transfer.py
helper script, replacing $APP
with the desired code directory:
pipenv run python build.py --help
screen /dev/ttyUSB0 115200
To exit: ctl-a d