(re-)configurable ESP8266 pins supporting MQTT discovery

In https://github.com/AlexMekkering/Hass-Mqtt-Esp8266-Pins I created a collection of (re-)configurable MicroPython scripts for ESP8266 boards which expose their GPIO pins by using MQTT topics which comply with Home Assistant’s MQTT discovery protocol (starting with Home Assistant 0.48).
My main goals of this all were:

  • to have a common code base for all my ESP8266 boards
  • it’s easy to install
  • it’s configurable per ESP8266 board
  • it supports Home Assistant’s MQTT discovery

Currently it supports switches and lights, but I tend to extend this to sensors and binary sensors also.
It’s interactively configurable.

Installation

TL;DR for ESP8266 on /dev/ttyUSB0

Installation of Hass-Mqtt-Esp8266-Pins can be as simple as:

  1. Flash the MicroPython firmware on the ESP8266 board by following https://docs.micropython.org/en/latest/esp8266/esp8266/tutorial/intro.html
    esptool.py --port /dev/ttyUSB0 erase_flash
    esptool.py --port /dev/ttyUSB0 --baud 460800 write_flash --flash_size=detect 0 esp8266-20170612-v1.9.1.bin
    
  2. Copy .py files from the src folder to the ESP8266 board
    git clone https://github.com/AlexMekkering/Hass-Mqtt-Esp8266-Pins.git
    ampy -p /dev/ttyUSB0 put Hass-Mqtt-Esp8266-Pins/src/hass_mqtt
    ampy -p /dev/ttyUSB0 put Hass-Mqtt-Esp8266-Pins/src/main.py
    
  3. Configure Wifi, MQTT and GPIO pin settings
    screen /dev/ttyUSB0 115200
    >>> import hass_mqtt.setup
    … and let the interactive setup process guide you …
  4. Restart the ESP8266 board
    >>> from machine import reset; reset()

For more info, please see https://github.com/AlexMekkering/Hass-Mqtt-Esp8266-Pins and please let me know what you think about it.

4 Likes