xKing Posted July 5, 2015 Posted July 5, 2015 (edited) Hi guys! My Garage opener broke (little gear on top sheared off) and I had to get a replacement, so I've got one of these Chamberlain models with MyQ and no way to control it via the normal contact closure. I know about soldering to the spare visor remote button but thought I'l try the software way first. So there is the simple python script that meant to be placed to /usr/lib/cgi-bin on your Pi (don't forget to do chmod +x) and called from ISY like this: To close: http://1.1.1.1/cgi-bin/myq-cgi.py?user=user@example.com&pass=secret1&cmd=close To open: http://1.1.1.1/cgi-bin/myq-cgi.py?user=user@example.com&pass=secret1&cmd=open If you want to test the script: http://1.1.1.1/cgi-bin/myq-cgi.py?user=user@example.com&pass=secret1&cmd=status It currently does not support 2 openers on the same account but that is fairly easy to add if there is a demand for it (I have a 2 car garage but it's only one door). Script is based on this one Many thanks to this topic for API description and a sample code, all I had to do is to re-write it in Python. My script does save a token to the temporary file and it would re-use that token within 1 hour of it's creation or until authentication fails (whatever comes first). Please let me know if you are interested in supporting multiple openers and Happy 4th! P.S. I think I can re-write it as a Node Server as well, but wondering what would be the best way to update the door status? Pulling it like every 15 minutes? I read my own door status via DSCLinc (just as a zone) so I did not add anything like that into the current version of this script. myq-cgi.zip Edited July 5, 2015 by xKing
Michel Kohanim Posted July 5, 2015 Posted July 5, 2015 Hello xKing, Thanks so very much for sharing. May I include this in our Wiki? With kind regards, Michel
xKing Posted July 6, 2015 Author Posted July 6, 2015 Does it require cloud connectivity to work? Yes, it talks to the MyQ cloud server. I know it's kind of odd to go to the cloud to close your own garage door, but MyQ Internet gateway does not seem to have anything locally accessible. If you don't want could - your only way would be soldering to the remote or wall button
eyaniv Posted October 2, 2015 Posted October 2, 2015 Thank you xKing for the myq script. In order to update the garage door status, I use ISY network resource to initiate an update, instead of polling. Basically, ISY will call a network resource, that will initiate your script, pull the status and update an ISY variable. Can ISY do the same thing with node server, eliminating the need to poll? here's my script, exposed as a network resource: #!/bin/bash echo "Content-Type: text/html" echo "" echo "<!DOCTYPE html><html><body>" ga=$(curl -s "http://rpi/automation/myq.cgi?user=MYQUSER&pass=MYQPASS&cmd=status" | grep Status | awk '{print $3;}') echo "updating ISY with status $ga<br />" curl -u ISYUSER:ISYPASS http://isy/rest/vars/set/1/VAR/$ga echo "</body></html>"
xKing Posted October 2, 2015 Author Posted October 2, 2015 eyaniv, thank you for your feedback! Unfortunately I'm not aware of a way to "subscribe" to MyQ so I can have an always up to date status. There is what I can do: 1) Have the script update ISY automatically when you invoke "status" - that would eliminate the need for the bash script. 2) Re-write it as a "server" in NODE.JS so it would run all the time and poll the MyQ server periodically (with configurable interval) and update ISY when needed (update won't be instant of course). Node server would be similar to option 2, but with the same limitation - I'm not aware of the way to "subscribe" to the MyQ. I personally have a magnetic contact on my garage door tied to my security system so I know door status from it instantly.
MWareman Posted October 2, 2015 Posted October 2, 2015 The app (on a phone) updates very quickly when the garage opens or closes. I wonder if they use a websocket for this, and if it can be tapped into. The api does not appear to give details though.
paulbates Posted October 2, 2015 Posted October 2, 2015 Could that be 'wiresharked' if connected the local WLAN?
MWareman Posted October 2, 2015 Posted October 2, 2015 Could that be 'wiresharked' if connected the local WLAN?Probably not very easily... The api is served over SSL. I'm going to try using an intercepting SSL forward proxy to see if I can see what's going on, but if the app uses certificate pinning this will fail.
xKing Posted October 2, 2015 Author Posted October 2, 2015 you think the MyQ app subscribes to the updates? Not just polling it?..
MWareman Posted October 2, 2015 Posted October 2, 2015 you think the MyQ app subscribes to the updates? Not just polling it?..I don't know. It seems to update too quickly to be polling. Maybe it's using Android device messaging though...
xKing Posted October 2, 2015 Author Posted October 2, 2015 Would be cool to find out Like for my Nest "Node Server" I just use Firebase and getting all updates on line.
eyaniv Posted October 2, 2015 Posted October 2, 2015 It is only polling, I just checked my iPhone myQ client with an SSL proxy. The client will fire a new request to https://myqexternal.myqdevice.com/api/v4/DeviceAttribute/PutDeviceAttributeevery 10 seconds.
MWareman Posted October 2, 2015 Posted October 2, 2015 It is only polling, I just checked my iPhone myQ client with an SSL proxy. The client will fire a new request to https://myqexternal.myqdevice.com/api/v4/DeviceAttribute/PutDeviceAttributeevery 10 seconds. That's a shame....
eyaniv Posted October 3, 2015 Posted October 3, 2015 That's a shame.... Agree, but at least we can assume that myQ is capacity tested for a status hit every 10-15 seconds
xKing Posted December 17, 2015 Author Posted December 17, 2015 It looks like MyQ changed the API a little, so there is a very quick fix in order for it to work with that new /api/v4 myqcgi.zip
Recommended Posts