daniloc / PicoW_HomeAssistant_Starter

Everything you need to get started with your own Intranet of Things, using the high-quality, low-cost Pico W as the backbone.
MIT License
198 stars 20 forks source link
arduino home-assistant iot mqtt raspberry-pi-pico

Raspberry Pi Pico W Home Assistant Starter Project Using arduino-pico

I'm pretty excited about Pico W: it's such a reliable, high-quality board and each one costs just $6 (if you can find one).

I'm building an IoT project with Pico W and Home Assistant, and it took weeks of research and experimentation to figure out the basics of integration of all the necessary components. This starter pulls together everything I've learned so you can get to building quickly.

Fill out src/Credentials.h, upload to your Pico W, then you'll have a working integration that allows you to toggle the Pico W's board LED from the Home Assistant dashboard. From this starter you'll have a solid foundation to build your own custom device in a private, local Intranet of Things.

image

This readme will provide pointers to everything you'll need. Let me know if it's missing anything!

Dependencies

Getting started


Prerequisites

  1. Hold the BOOTSEL button on your Pico W while connecting it via USB
  2. Open this project in VSCode
  3. Edit src/Credentials.h with:
    - WiFi SSID
    - WiFi Password
    - MQTT Username
    - MQTT Password
    - MQTT Broker IP
  4. Select the PlatformIO sidebar tab and choose Project Tasks > Upload and Monitor
  5. Once the project logs a connection to the MQTT broker, open your Home Assistant instance
  6. From Settings > Devices and Services, find the MQTT card and click the link that says X devices
  7. From the resulting list, select Pico W HA Starter
  8. Under the Controls heading you should see Board LED. Toggle the switch to turn your green board LED on and off
Screen Shot 2022-08-27 at 11 53 32 PM

That's it. Now you've got a working example integration of all the pieces needed to communicate between an inexpensive, high-quality microcontroller and Home Assistant, all happening on your local network.

See the examples in arduino-home-assistant for additional components you can easily integrate, including sensors, buttons, even HVAC controls.

Troubleshooting

Appendix: Setting up a local Home Assistant installation with Mosquitto

Home Assistant install

Home Assistant can be installed several ways on all kinds of hardware. Raspberry Pi is a popular choice, but you can also use your existing computer for initial explorations. Home Assistant Container is probably the quickest and most portable way to get started, whichever hardware you're using, though this does mean you'll have to manage some add-ons yourself, including MQTT.

MQTT and Mosquitto

MQTT provides realtime messaging between devices in a network. The Eclipse Mosquitto project offers a server that can act as an MQTT broker, a central hub for MQTT devices to send and receive data.

If you're using Home Assistant Operating System, check these instructions to install the Mosquitto MQTT broker add-on.

If you're using Home Assistant Container, this tutorial provides a great overview on how to set up and secure Mosquitto in a seperate container.

Once your MQTT broker is enabled, add the MQTT integration to your Home Assistant instance.

Pull requests

PRs are welcome on these points:

The goal of the project is to provide enough example structure to allow developers to add complexity without making a messy, crowded main.cpp file. PRs that simplify down to a single file probably won't be merged. If you have ideas on how to make this an even better foundation for building complex IoT projects, I'm all ears.


Questions? Comments? Gripes? Open an issue if you think there will be general interest or impact on the project. Otherwise hit me up: mail@danilocampos.com.