Devember 2021[COMPLETED]- ultrasonic garage parking sensor

Love it

Might I recommend a few things extra, may be fun.

  1. Open a GitHub account if you don’t already have one, make a private repo (or public, I recommend private to folks starting out given how most people tend to be self conscious and don’t like airing their dirty ~laundry~ code in public; making the repo private alleviates these fears, … and imagine checking in a secret key of some kind, jeez).

  2. Add a README.md, and inside, write down install instructions, write down some notes about how hardware is setup… maybe add a link to this forum given how there’s photos here, add this bit of Python code that you see above.

  3. Add a LICENSE file (recommend GPL3 or Apache 2.0 or MIT)… and add a small SPDX header. It doesn’t really matter because it’s private, it’s just a good thing to do, if you want to take any next steps.

Don’t need to learn all the ins and outs of git (forget about all of that managing history and branching and all the weird and hard to wrap your brain around conceptual stuff); for now, important thing is to have a backup copy of your code online alongside some notes, … and a good starting point for your next projects whatever they may be.


Home Assistant is complicated, awesome but more complicated than what you have at the moment.

I think you should probably start by modularizing your existing code somewhat, make a def setup_sensor(trigger_pin, echo_pin): and a make a def read_distance(trigger_pin, echo_pin): and make a def update_display(distance_front, distance_side): … should be easier to add sensors from there (and eventually, move the logic to HA)

@risk Thanks for the detailed feedback! I’ll definitely look into both those options! More eyes would just make for better code and a better end project!

So update time. After several months of fighting with MQTT integration in home assistant and random forever loops and crashes, I “think” I have a functioning system. I originally had home assistant constantly publishing via the MQTT broker while the garage door was open. This lead to a huge MQTT message backlog on the pi preventing the system from accepting the MQTT “Stop” call and would eventually lead to the program locking up and needing a reset. So far the best solution I have found has been to change the Home Assistant automation. After some trial and error changing the publish type to “retain” keeps the correct message available to the pi without overwhelming it with a huge backlog of MQTT data.

1 Like