Project by Michael; WiFi Garage Door Controller with Raspberry Pi Pico W

I’ve just shared a new project: “WiFi Garage Door Controller with Raspberry Pi Pico W”



I strapped a Raspberry Pi Pico W to my garage door motor and now I can control my garage door from my phone! The Pico W hosts a simple webpage on my local network with three control buttons - one for Up, Stop and Down. Pressing one of the buttons does exactly what you’d expect.

Read more

7 Likes

When I run this code I get the following error.
Any thoughts?

Connecting to WiFi…
Setting up webserver…
connected
ip = 192.168.1.30
Client connected
Client connected
Request: b’GET / HTTP/1.1\r\n’
DOOR=UP => -1
DOOR=DOWN => -1
DOOR=STOP => -1
Task exception wasn’t retrieved
future: coro= <generator object ‘serve_client’ at 2000d9f0>
Traceback (most recent call last):
File “uasyncio/core.py”, line 1, in run_until_complete
File “”, line 136, in serve_client
NameError: local variable referenced before assignment

2 Likes

Hi @Matthew206744 - can you post an exact copy of your source code? (With WiFi credentials removed of course)

1 Like

A straight copied the code from your example and saved it as main.py and then changed out my Wi-Fi credentials. When I run the code I get the error I posted in the previous comment.

I’m able to run other scripts just fine on my Pico w.

1 Like

@Matthew206744 try inserting this line at line # 122

stateis = ""

1 Like

Perfect, That fixed the problem.

Thank you for following up. I love this example and I love your video.
It was so informative and helpful. I had been thinking of getting a Pico for a while but after I saw this project, I finally bought one.

3 Likes

So good to hear, and thanks for the kind words! Have fun with your new project, and thanks for bringing this to our attention!
The project code is updated to suit.

1 Like

Oh, perfect timing. I started a project to open our gate with voice command with just a 433mHz wireless switch on the gate end with a 12v relay. Now you have me thinking of using a mosfet instead. I like that pico protoboard, good to learn about it.

4 Likes

Congrats on making Hack-A-Day!

4 Likes

Ideal pico -w start project. Only bit I need to solve now is how to connect closed detector switch and feedback data to phone screen.

3 Likes

Hi Alan,

I just got my Pico W and started workin on some different bits and bobs: HomeStation/main.py at main · LiamHowell/HomeStation · GitHub

Do you have some functions built for detecting the state of the switch you could share?

EDIT: Got the live data updating on the webpage, still working out how to make it easily customisable but all of the functions are there!

2 Likes

Try this, Each time it is interrogated the signal on GP16 is reported

Modified garage code.

pin_SW = Pin(16, Pin.IN, Pin.PULL_UP)

1 Like

Hi Alan,

Its also worth checking out @Michael 's most recent project: Raspberry Pi Pico W | Create a Simple HTTP Server - Tutorial Australia

replacing the line
if button.value() == 1: # button not pressed
with
pin_SW.value() == 1: # button not pressed

Will change the logic so that you are reading the door sensor :smiley:

Liam

Just about to pick the parts for this and notice my door works a bit differently. The Controller is a GDO-6v4 by Automatic Technology. It has only one input labeled OSC, which mimics the OPERATE button on the panel and the remote only uses one button too. They both work similarly i.e it toggles operation, down if fully open, up if fully closed and stop if partway.
I’ll let you all know how it goes.

1 Like

I have a gate that operates on the same principle, 3 pinout instead of 5, however that’s an obstacle I can tackle. Unless there is no other way, I don’t want to run a 10m cable from the Pico in the garage opener to the gate, is there any way I can have two separate Pico’s on the same webpage so I can have 6 buttons, one side for the garage and one side for the gate?

@Levi199251 here’s a few ideas - non-exhaustive.

  1. If WiFi reaches the gate you could use MQTT to drive both Picos from a MQTT dashboard.

  2. Have the webpage hosted on one Pico W, and when any action is executed that pertains to the distant gate, that Pico W can publish the MQTT message, which the gate-Pico is listening for.

  3. Perhaps even having a single Pico W hosting the webpage, and a simple RF radio connecting that server to the remote gate-pico. No WiFi required.

3 Likes

Hi,

first post on the forum, I found this great project on Youtube as I wanted to replace my Garage Door RPi with a Pi Pico. I’m not experienced with Python so far so I’m learning as I go.
I got the control working (I have 4 buttons for “open”, “close”, “vent” and “light”) and can control the pico through webhook calls from my homeserver, so that’s cool!
I also have 3 sensor-out on my door control box for “open”, “close” and “light on”. I set up an async def query_status which checks the last state of all 3 sensor pins vs their current state and prints “Door open”, “Door not open”, “Door closed” etc. and detects all states perfectly fine, so that’s cool, too!

However, what I’m really struggling with is, instead of simply printing the status change, in adition call a webhook on my local server like
http://192.168.0.1:8080/?homserver?cmd=set%20garage_door_open%20on
since I haven’t figured out a working way to do a request.get in an asyncio-function.
What I tried:

  • urequest.get: This doesn’t work since it’s blocking and thus ncompatible with asyncio
  • uaiohttpclient: Gives errors that I can’t get rid of. I also tried to modify uaiohttpclient.py to my needs (non-standard port) or just use parts of that code since I don’t need a reply, basically calling the webhook and discarding the response would work, but no)
  • try to code my own http get request with asyncio.open_connection… but well, the gap between coding skills needed and my actual coding skills just widens, no success there.
  • I also tried to set up regular interrupts with urequests calling the webhooks, that works for a while but gives error messages on each status change and also just completely halts the pico after some time.

So… is there any working uPython-library for a request.get with asyncio?

2 Likes

Hi Joachim.

I’d check out @Liam120347 's HomeStation project for a look in at how you can get live sensor data to a webpage: HomeStation - A Pico W powered webpage dashboard - #4 by Liam120347

While async tasks would be the best practice way of handling a project like this the Pico W is super fast and will happily serve up new sensor data on repeat

PS: All of the sensor refreshing happens from the webpage side, pushing the new content into a dedicated div

Liam

1 Like

Hi all,
I managed to set up the project up and running and it worked for a while. Note that I did a significant variation…my garage motor is too old (or I could not figure out how to wire it) so I bought a small remote fob and get a servo motor hooked to the pico so I can still open the garage door with the phone. Why? Well, I do not like carrying more keys/fobs so there is that…
The issue is that, at least, once a week, the server stops responding and the website does not load. I thought it was an issue with the dynamic IP (meaning if you add devices to the network or if you unplug it and plug it again, the IP address may change), but this is not the issue, I managed to create a static IP and yesterday I could not open the garage door. Once I plugged it to the computer through Thonny it worked fine without any change in the code. Any idea what can be happening in regards to why the server may stop working? I also used an iphone app to scan the network and the picoW was shond “inactive” although it was connected.
Oh, I also used the Siri shortcuts so I can open the garage door whith my voice.

1 Like

Welcome Daniel!!

The code in the guide is great if you have a stable network connection but doesn’t ensure that the Pico is constantly connected.
To solve this you could setup a new asyncio task to check if the Pico is connected and re-connect if it isnt.