Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Home Automation with MicroPython, the ESP8266 and Google Home

Dale Humby
October 16, 2020

Home Automation with MicroPython, the ESP8266 and Google Home

In this IoT talk we will demo a home automation project by wiring up a switch to an ESP8266, write and load a MicroPython web service on the hardware, link it to Home Assistant.

This is a live hardware build and coding session. All hardware will be locally sourced, the instructions and code will be on GitHub.

https://github.com/dalehumby/DevFest2020

Dale Humby

October 16, 2020
Tweet

More Decks by Dale Humby

Other Decks in Technology

Transcript

  1. Home Automation
    with MicroPython, the
    ESP8266 and Google Home
    Dale Humby
    CTO, Nomanini
    Google Cloud Developer Expert

    View full-size slide

  2. Level 1:
    Getting Started

    View full-size slide

  3. Get started: Switch a lamp on

    View full-size slide

  4. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  5. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  6. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  7. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  8. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  9. R120
    communica.co.za
    Get started: Switch a lamp on

    View full-size slide

  10. Get started: Switch a lamp on
    WiFi

    View full-size slide

  11. Get started: Switch a lamp on
    WiFi Internet

    View full-size slide

  12. Get started: Switch a lamp on
    WiFi Internet

    View full-size slide

  13. Level 2:
    Open Source

    View full-size slide

  14. tasmota.github.io/docs/Getting-Started/

    View full-size slide

  15. tasmota.github.io/docs/Getting-Started/
    R80
    communica.co.za/products/bmt-ftdi-
    usb-to-ser-converter

    View full-size slide

  16. tasmota.github.io/docs/Getting-Started/
    R80
    communica.co.za/products/bmt-ftdi-
    usb-to-ser-converter

    View full-size slide

  17. R1,400
    communica.co.za

    View full-size slide

  18. WiFi
    Internet

    View full-size slide

  19. Raspberry Pi 4
    vs
    Odroid C4

    View full-size slide

  20. Price ±R1,400
    1.5 - 2 GHz CPU
    4 GB RAM
    Gigabit Ethernet
    Low power < 5W
    40 PIN GPIO

    View full-size slide

  21. Price ±R1,400
    1.5 - 2 GHz CPU
    4 GB RAM
    Gigabit Ethernet
    Low power < 5W
    40 PIN GPIO
    Debian 10 / Raspberry OS
    Onboard WiFi + Bluetooth LE
    2x mini-HDMI
    2x USB2 + 2xUSB3
    5V USB type-C
    Needs heatsink!

    View full-size slide

  22. Price ±R1,400
    1.5 - 2 GHz CPU
    4 GB RAM
    Gigabit Ethernet
    Low power < 5W
    40 PIN GPIO
    Debian 10 / Raspberry OS
    Onboard WiFi + Bluetooth LE
    2x mini-HDMI
    2x USB2 + 2xUSB3
    5V USB type-C
    Needs heatsink!
    Ubunt 20.04 / Android 9
    1x full-size HDMI
    4x USB3
    Voltage range 5-17 V

    View full-size slide

  23. Home Automation
    Software Stack

    View full-size slide

  24. Home Assistant: Home automation
    Mosquitto MQTT broker: Pub/Sub protocol
    Prometheus: Time series database
    Grafana: Visualisation
    Node-Red: Flow-based software control
    Home Automation / IoT Stack

    View full-size slide

  25. Because micro-SD cards fail

    View full-size slide

  26. github.com/dalehumby/rpi-provision
    +
    Ready-made
    images on
    Docker Hub
    Because micro-SD cards fail

    View full-size slide

  27. github.com/dockersamples/docker-swarm-visualizer

    View full-size slide

  28. Level 3:
    Build your own
    hardware

    View full-size slide

  29. How much prepaid
    electricity do I have
    left?
    Where is all my
    electricity going?

    View full-size slide

  30. kWh remaining

    View full-size slide

  31. kWh remaining
    1,000 flashes per kWh

    View full-size slide

  32. kWh remaining
    1,000 flashes per kWh
    “API... what?”,
    said Plessey

    View full-size slide

  33. 1,000 flashes per kWh
    LDR sensor (R20) https://www.communica.co.za/products/bmt-ambient-light-sensor
    D1 Mini (R85) https://www.communica.co.za/products/bmt-esp8266ex-nodemcu-wifi-board
    Screen Scrapers for Hardware Hackers

    View full-size slide

  34. 1,000 flashes per kWh
    LDR sensor (R20) https://www.communica.co.za/products/bmt-ambient-light-sensor
    D1 Mini (R85) https://www.communica.co.za/products/bmt-esp8266ex-nodemcu-wifi-board
    Screen Scrapers for Hardware Hackers

    View full-size slide

  35. 1,000 flashes per kWh
    LDR sensor (R20) https://www.communica.co.za/products/bmt-ambient-light-sensor
    D1 Mini (R85) https://www.communica.co.za/products/bmt-esp8266ex-nodemcu-wifi-board
    Screen Scrapers for Hardware Hackers

    View full-size slide

  36. 1,000 flashes per kWh ESP8266
    D1 Mini
    LDR sensor (R20) https://www.communica.co.za/products/bmt-ambient-light-sensor
    D1 Mini (R85) https://www.communica.co.za/products/bmt-esp8266ex-nodemcu-wifi-board
    Screen Scrapers for Hardware Hackers

    View full-size slide

  37. https://en.wikipedia.org/wiki/ESP8266
    https://www.espressif.com/
    ESP8266
    From Espressif Systems
    ... The Arduino killer

    View full-size slide

  38. https://en.wikipedia.org/wiki/ESP8266
    https://www.espressif.com/
    ESP8266
    From Espressif Systems
    ... The Arduino killer
    32-bit CPU
    80 MHz clock
    160 kB RAM + 4 MB Flash
    Integrated WiFi + TCP/IP stack
    16 GPIO pins / I2C / SPI / UART / ADC
    Cheap - used “everywhere”

    View full-size slide

  39. Let’s
    get coding

    View full-size slide

  40. Putting it all
    together

    View full-size slide

  41. github.com/dalehumby/powermeter

    View full-size slide

  42. github.com/dalehumby/powermeter

    View full-size slide

  43. github.com/dalehumby/powermeter

    View full-size slide

  44. github.com/dalehumby/powermeter

    View full-size slide

  45. Swarm mode: Natively managing a cluster of Docker Engines

    View full-size slide

  46. k3s.io
    Lightweight kubernetes

    View full-size slide

  47. k3s.io
    Lightweight kubernetes
    PXE / Network boot
    worker nodes

    View full-size slide

  48. k3s.io
    Lightweight kubernetes
    PXE / Network boot
    worker nodes

    View full-size slide

  49. TensorFlow Lite
    coral.ai/products/dev-bo
    ard-mini
    $99
    nvidia.com/en-us/auton
    omous-machines/jetson-
    store/
    $99
    dog

    View full-size slide

  50. home-assistant.io/integrations/google_assistant/

    View full-size slide

  51. home-assistant.io/integrations/google_assistant/

    View full-size slide

  52. Resources
    MicroPython docs.micropython.org/en/latest/esp8266/tutorial/intro.html
    Home Assistant home-assistant.io
    Mosquitto MQTT mosquitto.org
    Where to buy {hardware}
    Communica
    communica.co.za
    Build Actions on Google Assistant
    codelabs.developers.google.com/codelabs/actions-1
    Dale Humby
    github.com/dalehumby
    [email protected]
    dalehumby.com
    We’re hiring
    nomanini.com/careers

    View full-size slide