xKing Posted February 7, 2017 Share Posted February 7, 2017 Well, I extracted my appID about a few months ago? Probably they updated it again and you have the most recent one now Sent from my iPhone using Tapatalk Link to comment
lsibarra Posted February 7, 2017 Share Posted February 7, 2017 Hi einstein.42 Thank you for your reply yesterday and appreciate your thorough explanations. I will keep it the way I have it since it is now working. In the event, you want me to test anything (ie: the new api you have) just let me know. Thanks, Larry Link to comment
lsibarra Posted February 14, 2017 Share Posted February 14, 2017 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_main2017-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 login2017-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 json2017-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 loads2017-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 decode2017-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_decode2017-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.scanner2017-02-13 20:29:51,440 ERROR .2017-02-13 20:29:51,441 ERROR JSONDecodeError2017-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
xKing Posted February 14, 2017 Share Posted February 14, 2017 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 1 Link to comment
lsibarra Posted February 14, 2017 Share Posted February 14, 2017 Hi xKing, Thanks for your reply and for your help. Could you please guide me how I can use the script you provided above. Is that something I add to einstein.42 myq srcript? I am not really sure what I need to do as I am a novice in python scripts. Thanks again, Larry Link to comment
xKing Posted February 14, 2017 Share Posted February 14, 2017 Attached the modified file. I did not test it since I use my own script, but I think it should work. I can create a pull request of course if Mr. Einstein 42 would like myq-garage.zip 1 Link to comment
einstein.42 Posted February 14, 2017 Author Share Posted February 14, 2017 Sorry haven't had time to look at it. xKing you are more than welcome to send a pull request. Thanks! Link to comment
xKing Posted February 14, 2017 Share Posted February 14, 2017 Ok I see that you actually support a few different brands in the config.ini so I'll need to adjust my changes to account for that, will try to find some time this week. 1 Link to comment
brbeaird Posted February 14, 2017 Share Posted February 14, 2017 Yeah, try something like this xKing - you rock, dude! Thanks to you, I was able to fix my integration with SmartThings. Thanks for taking the time to figure it out and post here. 1 Link to comment
xKing Posted February 14, 2017 Share Posted February 14, 2017 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
lsibarra Posted February 14, 2017 Share Posted February 14, 2017 Thanks xKing. You are awesome! 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
einstein.42 Posted February 14, 2017 Author Share Posted February 14, 2017 Merged. Thanks xKing. Link to comment
xKing Posted February 14, 2017 Share Posted February 14, 2017 (edited) Thanks xKing. You are awesome! 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 February 14, 2017 by xKing Link to comment
lsibarra Posted February 14, 2017 Share Posted February 14, 2017 Thank you so much xKing. I will give this a try when I get home. I will keep you posted. You and einstein.42 are the best! Thanks for all your work! 1 Link to comment
lsibarra Posted February 15, 2017 Share Posted February 15, 2017 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
xKing Posted February 15, 2017 Share Posted February 15, 2017 (edited) until next time they change the API Edited February 15, 2017 by xKing 3 Link to comment
einstein.42 Posted February 15, 2017 Author Share Posted February 15, 2017 Sent from my iPhone using Tapatalk Link to comment
lsibarra Posted February 25, 2017 Share Posted February 25, 2017 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_main2017-02-14 23:49:33,186 ERROR print(doorname + ' not found in available doors.')2017-02-14 23:49:33,187 ERROR UnboundLocalError2017-02-14 23:49:33,187 ERROR :2017-02-14 23:49:33,187 ERROR local variable 'doorname' referenced before assignment Link to comment
xKing Posted February 25, 2017 Share Posted February 25, 2017 Does the status work for you? [andrey@penguin ~/src/GitHub/Einstein42/myq-garage]$ ./myq-garage.py status Garage Door is Closed. Last changed at Sat 25 Feb 2017 10:33:04 Link to comment
lsibarra Posted February 25, 2017 Share Posted February 25, 2017 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
xKing Posted February 25, 2017 Share Posted February 25, 2017 (edited) 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 February 25, 2017 by xKing Link to comment
lsibarra Posted February 25, 2017 Share Posted February 25, 2017 Hi xKing, The /home/pi/node/logs/myq-garage.log is on 0644 permission. Should I change that to 0755? Thanks,Larry Link to comment
lsibarra Posted February 25, 2017 Share Posted February 25, 2017 Also, the group and owner on /home/pi/node/logs/myq-garage.log is set to root [0]. Should I change that to pi [1000] for both group and owner? Link to comment
xKing Posted February 26, 2017 Share Posted February 26, 2017 yeah, change to pi (chown -R pi:pi /home/pi/node) I don't see the need to run anything as root Link to comment
lsibarra Posted February 26, 2017 Share Posted February 26, 2017 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_main2017-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_token2017-02-25 17:59:45,570 ERROR self.login()2017-02-25 17:59:45,570 ERROR File "./myq-garage.py", line 277, in login2017-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_token2017-02-25 17:59:45,571 ERROR f = open(self.tokenfname,"w")2017-02-25 17:59:45,571 ERROR IOError2017-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
Recommended Posts