Giter Site home page Giter Site logo

geerlingguy / pico-w-garage-door-sensor Goto Github PK

View Code? Open in Web Editor NEW
204.0 12.0 20.0 130 KB

Wireless garage door sensor for Home Assistant powered by Raspberry Pi Pico W

Python 100.00%
esphome garage-door home-assistant microcontroller pico raspberry-pi

pico-w-garage-door-sensor's Introduction

Raspberry Pi Pico W Garage Door Sensor

Lint

I wanted to build a sensor to determine the state of my garage door—open or closed—and send that state to Home Assistant so I can display the status in a dashboard and build automation from it (e.g. warning me if I'm asleep and the garage door is open!).

If I wanted some sort of cloud integration, I could pay for the kit that connects to my garage door opener, but since the cloud is just someone else's computer, and I'd rather not rely on some company's weak security to protect data about my home... I want it all local.

Garage Door sensors

The actual sensors I use are the 'Enforcer' (model SM-4201-LQ) from Seco-Larm. I chose these because they are rugged and purpose-built for mounting to garage door tracks.

Watch this video to see how I installed the sensors on my garage doors, and how I wired them to the Pico W.

RPi Pico Breakout Board wired to garage door sensor

I used a RPi Pico Breakout board mounted directly to my garage wall, and wired one wire of each sensor to ground, and the others thusly:

  • east_garage_door to GPIO pin 2
  • west_garage_door to GPIO pin 3

You can pick any GPIO connection, though—just change the appropriate lines inside garage-door.yml before flashing the Pico W using the instructions below.

Flashing the Pico W

I decided to use a Raspberry Pi Pico W for this project—you could probably also use an ESP32 or ESP8266 with slight modifications, since this project uses ESPHome.

You will have to flash the firmware to the Pico W in order for it to work.

Note: I also have a MicroPython-based setup in the micropython subdirectory.

Preparing to flash the Pico W

Before you can flash anything to the Pico W, you have to define a few secrets that ESPHome will use when it compiles the program.

Create a secrets.yaml file inside this directory, and add the following:

---
wifi_ssid: your-wifi-ssid-here
wifi_password: your-wifi-password-here
ota_password: choose-an-ota-password

# Encryption key for HA API access.
# Generate a random 32-bit key with `openssl rand -base64 32`
api_encryption_key: choose-an-api-encryption-key

Note: The ESPHome docs API page can generate an encryption key in-browser.

Using Docker

In this directory, I run docker-compose up -d to start an esphome container that I'll use to flash the Pico.

Then enter the container:

$ docker exec -it esphome bash
root@docker-desktop:/config#

This drops you into the container inside the config directory, which is shared from this repository.

Compile the binary for the garage door sensor:

$ esphome compile garage-door.yml

Copy the generated binary into the current directory:

$ cp .esphome/build/rpi-pico/.pioenvs/rpi-pico/firmware.uf2 ./rpi-pico.uf2

Then on your host computer, with the Pico W booted into BOOTSEL mode (hold down the BOOTSEL button while plugging in the USB cable), copy the rpi-pico.uf2 file over to the Pico W. When the copy is complete, the Pico should reboot and start working as a garage door sensor.

Using pip source install

Make sure you have Python 3 installed on your computer, then run:

$ pip3 install esphome

Make sure your installation is working:

$ esphome version
Version: 2023.11.6

Then plug in your Pico W, while holding the BOOTSEL button, and when it mounts on your computer, run:

$ esphome run garage-door.yml --device /Volumes/RPI-RP2

On Raspberry Pi or other Linux devices, the --device should be /dev/sda1 (or whatever mount point)

After 20-30 seconds, ESPHome should compile and upload the firmware to the Pico.

Note: There's also an led-blink.yml configuration if you want to upload it quickly to verify esphome and your Pico are all wired up correctly. If you run that file, it should make your Pico start blinking it's onboard LED 2x per second.

Installation from a Raspberry Pi

If you are using a Raspberry Pi, first install Pip:

sudo apt install python3-pip git

Then follow the directions above for 'Using pip source install'.

First time install

For now, if you're not running things on a Mac at least, the first install must be done by copying a manually-downloaded .uf2 file to the Pico in BOOTSEL mode.

After ensuring esphome installed (see 'Using pip source install' above):

  1. Run esphome dashboard ./
  2. In a browser, visit the Pi's IP address at port :6052
  3. Click the three dots next to the project
  4. Click 'Install'
  5. Click 'Manual download'
  6. Click the link and wait for the download to be generated, then click the Download link.

Copy the downloaded rpi-pico.uf2 file to the Pico's filesystem while it's in BOOTSEL mode (hold down BOOTSEL while plugging it in). Unplug and replug the Pico.

Debugging with ESPHome

If you want to see debug output, after the first time you flash the Pico, you can change the run command to:

$ esphome run led-blink.yml --device /dev/tty.usbmodem2101

And it will compile ESPHome, load it onto the Pico, and start displaying logged output. You can change the log level using the logger.level setting.

pico-w-garage-door-sensor's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pico-w-garage-door-sensor's Issues

Compile Error

I'm not really a software guy but I've managed to get to the compile stage and get this error.

Tool Manager: Installing earlephilhower/toolchain-rp2040-earlephilhower @ 5.100300.220714
INFO Installing earlephilhower/toolchain-rp2040-earlephilhower @ 5.100300.220714
Error: Could not find the package with 'earlephilhower/toolchain-rp2040-earlephilhower @ 5.100300.220714' requirements for your system 'linux_armv7l'

I've been searching for days to see what I'm doing wrong with no luck. I running this on a Pi400 running Buster 10

Thanks

Garage door sensor not detecting open/close status

I've gone through and built my own garage door sensor based on the one explained in Jeff's video, but I've run into an issue.

When I try and close the garage door sensor, the LED does not turn off. I'm using the same parts described in the video (except for the breakout board, I had to order that directly from the seller [in China] so I'm waiting on that to arrive). The jumper cables are connected to the leads on the sensor (I twisted the leads on the sensor around the jumpers). Something weird I've experienced when running the esphome run command is that after the firmware is flashed and the Pi reboots, I get an ERROR Could not connect to serial port /Volumes/RPI-RP2 error.

The firmware is still flashed though since when I ran the led-blink file it would blink, but still, show the same error.

Please let me know if I'm doing something wrong in my setup.

Screenshots:
The setup:
image

The connections to the Pi:
image

esphome run command:
image

Compilation errors on macOS

HARDWARE: RP2040 133MHz, 264KB RAM, 2MB Flash
 - framework-arduino-mbed @ 3.1.1
 - framework-arduinopico @ 1.20400.0 (2.4.0)
 - tool-rp2040tools @ 1.0.2
LDF: Library Dependency Finder -> https://bit.ly/configure-pio-ldf
Dependency Graph
|-- WiFi @ 1.0
|   |-- SocketWrapper @ 1.0
Compiling .pioenvs/rpi-pico/src/esphome/components/rp2040/core.cpp.o
Compiling .pioenvs/rpi-pico/src/esphome/components/rp2040/gpio.cpp.o
In file included from src/esphome/components/rp2040/core.cpp:3:
src/esphome/components/rp2040/core.h:5:10: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://registry.platformio.org/search?q=header:Arduino.h
*
*****************************************************************

    5 | #include <Arduino.h>
      |          ^~~~~~~~~~~
compilation terminated.
Compiling .pioenvs/rpi-pico/src/esphome/components/rp2040/preferences.cpp.o
In file included from src/esphome/components/rp2040/gpio.cpp:3:
src/esphome/components/rp2040/gpio.h:5:10: fatal error: Arduino.h: No such file or directory

*****************************************************************
* Looking for Arduino.h dependency? Check our library registry!
*
* CLI  > platformio lib search "header:Arduino.h"
* Web  > https://registry.platformio.org/search?q=header:Arduino.h
*
*****************************************************************

    5 | #include <Arduino.h>
      |          ^~~~~~~~~~~
compilation terminated.
Compiling .pioenvs/rpi-pico/src/esphome/core/application.cpp.o
Compiling .pioenvs/rpi-pico/src/esphome/core/color.cpp.o
Compiling .pioenvs/rpi-pico/src/esphome/core/component.cpp.o
Compiling .pioenvs/rpi-pico/src/esphome/core/component_iterator.cpp.o
*** [.pioenvs/rpi-pico/src/esphome/components/rp2040/core.cpp.o] Error 1
Compiling .pioenvs/rpi-pico/src/esphome/core/controller.cpp.o
*** [.pioenvs/rpi-pico/src/esphome/components/rp2040/gpio.cpp.o] Error 1
In file included from src/esphome/core/color.cpp:1:
src/esphome/core/color.h: In member function 'esphome::Color esphome::Color::operator+(const esphome::Color&) const':
src/esphome/core/color.h:116:12: warning: implicitly-declared 'constexpr esphome::Color::Color(const esphome::Color&)' is deprecated [-Wdeprecated-copy]
  116 |     return ret;
      |            ^~~
src/esphome/core/color.h:61:17: note: because 'esphome::Color' has user-provided 'esphome::Color& esphome::Color::operator=(const esphome::Color&)'
   61 |   inline Color &operator=(const Color &rhs) ALWAYS_INLINE {  // NOLINT
      |                 ^~~~~~~~
src/esphome/core/color.h: In member function 'esphome::Color esphome::Color::operator-(const esphome::Color&) const':
src/esphome/core/color.h:139:12: warning: implicitly-declared 'constexpr esphome::Color::Color(const esphome::Color&)' is deprecated [-Wdeprecated-copy]
  139 |     return ret;
      |            ^~~
src/esphome/core/color.h:61:17: note: because 'esphome::Color' has user-provided 'esphome::Color& esphome::Color::operator=(const esphome::Color&)'
   61 |   inline Color &operator=(const Color &rhs) ALWAYS_INLINE {  // NOLINT
      |                 ^~~~~~~~
src/esphome/core/color.h: In member function 'esphome::Color esphome::Color::gradient(const esphome::Color&, uint8_t)':
src/esphome/core/color.h:164:12: warning: implicitly-declared 'constexpr esphome::Color::Color(const esphome::Color&)' is deprecated [-Wdeprecated-copy]
  164 |     return new_color;
      |            ^~~~~~~~~
src/esphome/core/color.h:61:17: note: because 'esphome::Color' has user-provided 'esphome::Color& esphome::Color::operator=(const esphome::Color&)'
   61 |   inline Color &operator=(const Color &rhs) ALWAYS_INLINE {  // NOLINT
      |                 ^~~~~~~~
============================================ [FAILED] Took 3.41 seconds ============================================

Critical push notification for iPhone/iOS

According to this comment on YouTube, I may be able to make the notification 'critical' in Home Assistant by marking it like:

service: notify.mobile_app_phonename
data:
  message: Door open!
  title: Warning!
  data:
    push:
      sound:
        name: default
        critical: 1
        volume: 1

I believe I can just throw certain data into the data field / JSON payload in the UI, so I'll see if this makes it work when my phone is in night or focus mode.

question - google home support

instead of home assistant is there a way to directly connect it to google home?

i dont have home assistant on my home (just starting to set up stuff)
and i have another project for the pico w that is to turn my pc on with it (powered by the internal usb header)

Add delayed push notification every 10 minutes while garage door is open

This could be annoying during certain times, like when I'm mowing the lawn, but otherwise would be good to have. Maybe also add a motion sensor in the garage to use as a negative indicator in the future, but for now, just a basic alert like: https://www.home-assistant.io/integrations/alert/

# Example configuration.yaml entry
alert:
  east_garage_door:
    name: East garage door open
    done_message: East garage door closed
    entity_id: input_boolean.east_garage_door
    state: "on"
    repeat: 10
    can_acknowledge: true
    skip_first: true
    notifiers:
      - jeff_phone

(Their official example is even based on a Garage Door notification!)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.