Garage Door Opener - mkrcek/home GitHub Wiki
User story:
- As a car driver, I want to use iPhone to open and close my Garage Door
- I want to say "Hey Siri - Open the Garage"
- Configure and control the Garage Door over HTTP GET and POST
Do you want to see DEMO video ? Haha - it is the first. I need to record new one :-)
How does it work?
I was thinking how to measure the distance the best way. So, this is my result: measure distance on the top-rail.
- Arduino with an Ultrasonic Sensor on the Garage engine (Plastic housing for D600 operator). The direction is toward to the Door - so, it is not moving.
- Put/Attache a little "paperboard" on the Door side /on the rail (Drive carriage). When Door is opened, Paperboard is near to Arduino (minimum distance), when the door is closed, Paperboard is on the other side (maximum distance).
Ingredients:
- iPhone: with HomeKit
- Device: Arduino + Relay + Ultrasonic Sensor(HYSRF05) + SW (garage-door-opener.ino)
- Server: HW (RPi, PC with win, mac, linux, Synology ...) + SW in GoLang (garage-door-opener.go)
- Garage: with Door & Engine :-) (I have FAAC D600)
Device: Arduino
Ingredients:
- Arduino: WiFi D1 R2 ESP 8266
- Relay: to switch (press) the Garage Door engine
- Ultrasonic Sensor (HYSRF05)
0)Device scheme & HW configuration:
ARDUINO pins
- PIN[5] - Relay
- PIN[6] - Ultrasonic echo
- PIN[7] - Ultrasonic trigger
**HW: Connect garage Engine to Arduino **
Now you need to connect Relay + Garage Engine. In my case FAAC D600.
- Just remove the rear door
- And connect to relay
- cable from (OPEN A) Command device with N.O. contact
- cable from (-) Negative for OPEN A and STOP devices
and connectors
1)Device setup:
You get the configuration when you call HTTP GET of your Arduino, e.g.
GET http://192.168.100.22/door/config
and you receive JSON:
{"DoorMaxCm":100,"DoorMinCm":10,"setDoorDelay":1000}
- DoorMaxCm: is the maximum distance of your garage door, when it is close
- DoorMinCm: is the minimum distance of your garage door, when it is close
- setDoorDelay: how often the distance is measured (in milliseconds)
1a) Change DoorMaxCm
-
SW measures the distance automatically. Just to do following steps:
-
Close the garage traditional way (max Length from ultrasonic sensor)
-
send to Arduino HTTP POST , e.g.
POST http://192.168.100.22/door/config
with message
{"setDoorMax":true, "setDoorMin":false, "setDoorDelay":1000}
1b) Change DoorMinCm
- Open the garage traditional way (min Length from ultrasonic sensor)
- send to Arduino HTTP POST , e.g. 192.168.100.22/door/config with message {"setDoorMax":false, "setDoorMin":true, "setDoorDelay":1000}
1c) Change setDoorDelay
- If you think you want to change the speed od "measurement" - change the parameter.
- send to Arduino HTTP POST , e.g. 192.168.100.22/door/config with message {"setDoorMax":false, "setDoorMin":false, "setDoorDelay":1000}
Check the setup / configuration with HTTP GET 192.168.100.22/door/config and you can see more actual parameters e.g. {"DoorMaxCm":258,"DoorMinCm":4,"setDoorDelay":1000}
2)GET Current Door Position
Super Easy, just to call HTTP GET
GET http://192.168.100.22/door
and you get message like:
{"door":0,"CurrentDoorState":1,"TargetDoorState":1,"TargetDoorOpen":100,"ObstructionDetected":false}
- door : is the doorPosition in percentage. 0 is close, 100 is open 100%
- CurrentDoorState: Actual activity of the door like Open = 0; Closed = 1; Opening = 2; Closing = 3; Stopped = 4;
- TargetDoorState: Target position of the door like Open = 0; Closed = 1;
- TargetDoorOpen: Target position in percentage (not implemented yet) like Open 40 %
- ObstructionDetected: "true" when Door is stoped by any reason between 0-100, "false" - no problem
3)POST Target Door Position
Super Easy too :-) Send HTTP POST
POST http://192.168.100.22/door
with message :
{"TargetDoorState":1,"TargetDoorOpen":0}
- TargetDoorState: Target position of the door like Open = 0; Closed = 1;
- TargetDoorOpen: Target position in percentage (not implemented yet) like Open 40 %
Server
Ingredients:
- HW: Personally I use Raspberry Pi zero, but you can use any platform for GO (Go lang) e.g. Microsoft Windows, Apple Mac OS X, Linux... Synology... you can use Docker WiFi D1 R2 ESP 8266
- SW: written in Go (GoLang): garage-door-opener.go
SW configuration
-
First, you need to know the IP address of your Arduino Garage Device. You can see it in Arduino Serial Monitor - when you compile your Arduino file. For example
http://192.168.100.22
-
Then you run Go program with command-line argument, like
go run garage-door-opener.go -ip=http://192.168.100.22
Now, you can see similar results on your screen:
Arduino IP adress is : http://192.168.100.22
HomeKit pairing Code (pin) is : 32344322
HomeKit Port is : 12345
HomeKit Path is : ./dbgarage
HomeKit Server Port is : :9090
INFO 2017/11/16 22:54:01 Accessory IP is 192.168.0.18
-
If you run more then 1 HomeKit server (bridge), you need to change some more parameters
go run garage-door-opener.go -ip=http://192.168.100.22 -pin=92344322 -port=12344 -path=./kitfolder -serverport=.9091
where:
-pin: unique pairing code /PIN/ for this server (bridge)
-port: unique port, where server runs
-path: folder for storing HomeKit configuration & temp files
-serverport: new HomeKitServer Port
And it is done!
SW cross platforms
All platforms, already compiled, you can find in main code-directory files
Update: 2017-11-28 MacOS
- 78cefc0699cbbde9bcccd62533656300d8911d0e garage-door-opener MacOS
Raspberian : Raspberry Pi 2 Model B
- 4a5bc64a1ac86e3275bd2ddde166f113d4fc7b3b garage-door-opener-rpi RPi
Windows AMD64: (sometime cannot pair)
- c312e7e7fb1d6d602d2102d6203daefa344ec1d5 garage-door-opener-amd64.exe Windows
iPhone with HomeKit
Add an accessory
- Open the Home app and tap Add Accessory or tap (+)
- Tap on "Don't have a Code or Can't scan?"
- And add code (HomeKit pairing Code (pin) ) 32344322 (default value of this program)
And it is done. You can use the HomeKit Application or just say "Hey Siri - Open the Garage"