Jump to content

Python control of MyQ Garage Doors


einstein.42

Recommended Posts

Hi Einstein.42,

Sorry to bother you again with this. However, the script stopped working again. Below is the error log. Could this be the API again?

 

Thanks for any help.

 

2017-02-13 20:29:51,035 INFO     ==================================STARTED==================================
2017-02-13 20:29:51,434 ERROR    Traceback (most recent call last):
2017-02-13 20:29:51,434 ERROR      File "/home/pi/node/myq-garage.py", line 361, in <module>
2017-02-13 20:29:51,435 ERROR    gdoor_main()
2017-02-13 20:29:51,435 ERROR      File "/home/pi/node/myq-garage.py", line 327, in gdoor_main
2017-02-13 20:29:51,436 ERROR    myq = MyQ()
2017-02-13 20:29:51,436 ERROR      File "/home/pi/node/myq-garage.py", line 217, in __init__
2017-02-13 20:29:51,436 ERROR    self.login()
2017-02-13 20:29:51,436 ERROR      File "/home/pi/node/myq-garage.py", line 228, in login
2017-02-13 20:29:51,437 ERROR    res = req.json()
2017-02-13 20:29:51,437 ERROR      File "/usr/lib/python2.7/dist-packages/requests/models.py", line 793, in json
2017-02-13 20:29:51,438 ERROR    return json.loads(self.text, **kwargs)
2017-02-13 20:29:51,438 ERROR      File "/usr/lib/python2.7/dist-packages/simplejson/__init__.py", line 505, in loads
2017-02-13 20:29:51,438 ERROR    return _default_decoder.decode(s)
2017-02-13 20:29:51,439 ERROR      File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 370, in decode
2017-02-13 20:29:51,439 ERROR    obj, end = self.raw_decode(s)
2017-02-13 20:29:51,439 ERROR      File "/usr/lib/python2.7/dist-packages/simplejson/decoder.py", line 400, in raw_decode
2017-02-13 20:29:51,440 ERROR    return self.scan_once(s, idx=_w(s, idx).end())
2017-02-13 20:29:51,440 ERROR    simplejson.scanner
2017-02-13 20:29:51,440 ERROR    .
2017-02-13 20:29:51,441 ERROR    JSONDecodeError
2017-02-13 20:29:51,441 ERROR    :
2017-02-13 20:29:51,441 ERROR    Expecting value: line 1 column 1 (char 0)
 

Link to comment

Yeah, try something like this

 

diff --git a/myq-garage.py b/myq-garage.py
index 568bf82..00af49e 100755
--- a/myq-garage.py
+++ b/myq-garage.py
@@ -207,8 +207,12 @@ class MyQ:
         self.baseurl = SERVICE
         self.username = USERNAME
         self.password = PASSWORD
-        self.headers = { "User-Agent": "Chamberlain/2786", "MyQApplicationId": self.appid }
-        self.authurl = self.baseurl+"/api/user/validatewithculture"
+        self.headers = { "User-Agent": "Chamberlain/3.73",
+                         "BrandId": "2",
+                         "ApiVersion": "4.1",
+                         "Culture": "en",
+                         "MyQApplicationId": self.appid }
+        self.authurl = self.baseurl+"/api/v4/User/Validate"
         self.enumurl = self.baseurl+"/api/v4/userdevicedetails/get"
         self.seturl  = self.baseurl+"/api/v4/DeviceAttribute/PutDeviceAttribute"
         self.geturl  = self.baseurl+"/api/v4/deviceattribute/getdeviceattribute"
@@ -218,8 +222,8 @@ class MyQ:
 
 
     def login(self):
-        payload = { "appId": self.appid, "username": self.username, "password": self.password, "culture": "en" }
-        req=self.session.get(self.authurl, headers=self.headers, params=payload)
+        payload = { "username": self.username, "password": self.password }
+        req=self.session.post(self.authurl, headers=self.headers, json=payload)
 
         if (req.status_code != requests.codes.ok):
             print "Login err code: " + req.status_code
  • Like 1
Link to comment

Got the pull request done (I'm pretty new to git, using SVN at work) so please review. I've also added my "token caching" functionality so authentication is not done on each request, token is now cached in the temporary file for the amount of minutes configured in the TOKENTTL variable. That should reduce load to MyQ Auth server and mimic the real app better, plus people should be able to pull the door status more frequent (but I still agree that 5 minutes is a good interval, if realtime update is desired - use door sensor instead).

Link to comment
Thanks xKing. You are awesome!  :-P

 

I will let you know as soon as I entered all the needed information to integrate with my ISY. I am using io_guy's nodelink relay server. So the config.ini doesnt work for me.

 

This might be a dumb question. Is the ChamberAPPID still this --> NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx or your modified script automatically pulls the new APPID?

 

Sorry for being a newbie :)

 

Larry

Link to comment

 

Thanks xKing. You are awesome!  :-P
 
I will let you know as soon as I entered all the needed information to integrate with my ISY. I am using io_guy's nodelink relay server. So the config.ini doesnt work for me.
 
This might be a dumb question. Is the ChamberAPPID still this --> NWknvuBd7LoFHfXmKNMBcgajXtZEgKUh4V7WNzMidrpUUluDpVYVZx+xT4PCM5Kx or your modified script automatically pulls the new APPID?
 
Sorry for being a newbie :)
 
Larry

 

 

 

 

Well, find the line

config.read('config.ini')

and change it to the absolute path like

config.read('/home/pi/myq-garage/config.ini')

so you could still use the config.ini 

 

App ID is still the same and there is no way to figure it out automatically rather than trace what real iOS or Android app sends.

 

P.S. Please use "git pull" to fetch the updated version from the git hub, disregard the zip file please.

Edited by xKing
Link to comment

Hi xKing and einstein.42,

I just want to update both of you that the new file from github works perfectly.

 

@xKing, thank you for letting me know how to use the config file. It works now as long as I include the full path.

 

Guys, I've learned a lot from your codes. Thanks again for sharing this.

 

Great work!

Link to comment
  • 2 weeks later...

Hi,

 

I started getting this error again on 02/14/2017. Anyone have any idea? Sorry again for constantly reporting issues on this. Thanks in advance for any help/guidance.

 

2017-02-14 23:49:32,719 INFO     ==================================STARTED==================================
2017-02-14 23:49:33,185 ERROR    Traceback (most recent call last):
2017-02-14 23:49:33,185 ERROR      File "/home/pi/node/myq-garage.py", line 407, in <module>
2017-02-14 23:49:33,186 ERROR    gdoor_main()
2017-02-14 23:49:33,186 ERROR      File "/home/pi/node/myq-garage.py", line 396, in gdoor_main
2017-02-14 23:49:33,186 ERROR    print(doorname + ' not found in available doors.')
2017-02-14 23:49:33,187 ERROR    UnboundLocalError
2017-02-14 23:49:33,187 ERROR    :
2017-02-14 23:49:33,187 ERROR    local variable 'doorname' referenced before assignment
 

Link to comment

Hi xKing,

This is what I get:

pi@raspberrypi:~/node $ ./myq-garage.py status
Traceback (most recent call last):
  File "./myq-garage.py", line 401, in <module>
    LOGGER = setup_log('myq-garage')
  File "./myq-garage.py", line 108, in setup_log
    HANDLER = logging.handlers.TimedRotatingFileHandler(LOG_FILENAME, when="midn         ight", backupCount=30)
  File "/usr/lib/python2.7/logging/handlers.py", line 171, in __init__
    BaseRotatingHandler.__init__(self, filename, 'a', encoding, delay)
  File "/usr/lib/python2.7/logging/handlers.py", line 64, in __init__
    logging.FileHandler.__init__(self, filename, mode, encoding, delay)
  File "/usr/lib/python2.7/logging/__init__.py", line 911, in __init__
    StreamHandler.__init__(self, self._open())
  File "/usr/lib/python2.7/logging/__init__.py", line 936, in _open
    stream = open(self.baseFilename, self.mode)
IOError: [Errno 13] Permission denied: '/home/pi/node/logs/myq-garage.log'
Link to comment

sounds like a permissions problem? how does /home/pi/node/logs/myq-garage.log file permissions/ownership look like?

 

could it be that you've run it as root one day so the log is root owned and can't be written by the "pi" user?

Edited by xKing
Link to comment

Hi xKing,

I changed the permission owner and group to pi per your instruction as well as the permission to 0755. Below is the error message from the log.

 

2017-02-25 17:59:45,567 ERROR    Traceback (most recent call last):
2017-02-25 17:59:45,567 ERROR      File "./myq-garage.py", line 407, in <module>
2017-02-25 17:59:45,568 ERROR    gdoor_main()
2017-02-25 17:59:45,568 ERROR      File "./myq-garage.py", line 373, in gdoor_main
2017-02-25 17:59:45,568 ERROR    myq = MyQ()
2017-02-25 17:59:45,569 ERROR      File "./myq-garage.py", line 224, in __init__
2017-02-25 17:59:45,569 ERROR    self.read_token()
2017-02-25 17:59:45,569 ERROR      File "./myq-garage.py", line 250, in read_token
2017-02-25 17:59:45,570 ERROR    self.login()
2017-02-25 17:59:45,570 ERROR      File "./myq-garage.py", line 277, in login
2017-02-25 17:59:45,570 ERROR    self.save_token()
2017-02-25 17:59:45,570 ERROR      File "./myq-garage.py", line 240, in save_token
2017-02-25 17:59:45,571 ERROR    f = open(self.tokenfname,"w")
2017-02-25 17:59:45,571 ERROR    IOError
2017-02-25 17:59:45,571 ERROR    :
2017-02-25 17:59:45,572 ERROR    [Errno 13] Permission denied: '/tmp/myqtoken.json'
 

Link to comment
Guest
This topic is now closed to further replies.

×
×
  • Create New...