Author Topic: Chamberlain/Liftmaster MyQ Plugin  (Read 99270 times)

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin [WIP]
« Reply #15 on: April 24, 2014, 06:04:01 pm »
I think I've tried to digest too much far too quickly and now I just have a thousand yard stare
I'm going to step away from this for a bit but will get back to it in a week (or sooner if I can't help myself)
I think most parts are there and it should work -- I just need to take a view from afar

I can't thank you enough guessed with your help and pointers -- all you guys that make these plugins should have a tab at your local watering hole paid for in advance! This is truly what makes Vera such an awesome product, it's a shame that MCV doesn't step up with their documentation and has such limited interaction on the forum

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin [WIP]
« Reply #16 on: April 25, 2014, 12:33:14 pm »
Well, I'm a glutton for punishment and I did some more work.
The code is getting pretty messy but I'm getting closer to an actual solution.
I'm still using the DoorLock devices and managed to get some code working that sets each doors status
I have not handled any failures with SecurityTokens expiring or the URL not being there.. to do later
The good news is that I can poll the door status (currently at 90 seconds) and update the Locked or Unlocked state on the Door Lock.
I've done a bit of testing and watch the UI update as I change the state of my doors - so the state update appears to be working -- cool!

So, I'm at what is the last piece: Hooking up code to respond to clicks on the DoorLock UI and here I'm stumped
I click on it now and get "No implementation."
So, hmmm, there's a way for me to create my own implementation and intercept the click events?
One last step to have a below alpha version ready.

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin [WIP]
« Reply #17 on: April 25, 2014, 12:50:18 pm »
Getting closer. defined services in my D_LiftMasterOpener.xml:

Code: [Select]
<service>
<serviceType>urn:schemas-micasaverde-com:service:DoorLock:1</serviceType>
<serviceId>urn:micasaverde-com:serviceId:DoorLock1</serviceId>
<SCPDURL>S_DoorLock1.xml</SCPDURL>
</service>
<service>
<serviceType>urn:schemas-micasaverde-com:service:HaDevice:1</serviceType>
<serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
<SCPDURL>S_HaDevice1.xml</SCPDURL>
</service>

and in my I_LiftMasterOpener.xml, I have:

Code: [Select]
<actionList>
     <action>
       <serviceId>urn:micasaverde-com:serviceId:DoorLock1</serviceId>
       <name>SetTarget</name>
       <run>
     luup.log("This is a direct call")
   </run>
</action>
   </actionList>

and I now wrote out to the log from my function above

so..........
now need to determine which child device the click came from and which button was clicked, respond and set status


macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin [WIP]
« Reply #18 on: April 25, 2014, 12:58:33 pm »
it's all visible, child device that called and what it set:

Code: [Select]
     luup.log("This is a direct call, you appear to be: " .. lul_device .. " with a setting of " .. lul_settings.newTargetValue )

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin [WIP]
« Reply #19 on: April 25, 2014, 04:03:37 pm »
and for what it's worth, a pre- pre- pre- pre- pre-alpha plugin that kind of works

guessed, care to take a look? Still needs a lot of cleanup (and a huge refactoring) but..

It polls each child garage door opener every 90 seconds to check on its status
The Lock and Unlock buttons on the garage door opener devices work -- you can remotely open and close your garage doors through Vera!

Anyone have one of these devices and care to try it?
I'll provide some detailed instructions on setup but this is really early and done by someone who just tried learning LUA/LUUP in the last week or two  :o

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #20 on: April 26, 2014, 06:53:00 pm »
from a bit of reading it appears that a token is good for 15 minutes, if a request is done with the current token, the expiration time is another 15 minutes. So, I'll make a change to this

One odd thing I noticed is that while I can control the doors individually when I put them in a scene ( I have 2 ) only 1 closes..

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #21 on: April 30, 2014, 05:12:47 pm »
Ok, finally had some time to try it out.

I ran into a problem with it's [Lua] Library depends, since JSON isn't one of the standard libs.  It took me a while to work that out, so before I dove into it I made a few changes:

a) Reformatted entire code & XML to a single style/convention
b) Refactored a little to put the "base" URL into everything
c) Tweaked the error handling for when Username/Password details weren't present
d) Used url_encode across the board "just in case"
e) Created a Localized copy of the dkjson.lua library, with a unique name, so the app can be free-standing
f) Added a bunch of [pseudo] constants for various things.

I was able to validate that it created a Lock child device, and that I can open/close my garage door with this mod.


Congrats, this is a great milestone for your efforts!


There are a bunch more things that need to be done to it, but the core is working reasonably at this time.


Changed attached.

Offline jeff3lo

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-0
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #22 on: April 30, 2014, 07:43:26 pm »
I'm eager to test this out.  Can you help me with some instruction on how to set this up please?

I am guessing;
1. I need to upload the 6 files via "Luup files" menu
2. I need to create a device (but I am not sure what to put in each text box).

Any help is greatly appreciated.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #23 on: April 30, 2014, 08:18:01 pm »
To load @macrho's plugin, you upload all 6x files to Vera.
Then use:
     Apps -> Develop Apps -> Create Device

In that UI, I only fill in:
  Description = LiftMaster Garage Opener and;
  Upnp Device Filename = D_LiftMasterOpener.xml

Then (Create Device) followed by (Save/Reload)

Once it comes up, open it's dialog, select the [Advanced] tab, and enter values for
  Username = your MyQ email address and;
  Password = your MyQ password

Another (Save/Reload) operation, and the child Garage Door Opener device should appear

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #24 on: May 01, 2014, 04:38:36 pm »
Thank you so much, @guessed!

It has been quite a bit of work and I need to do quite a bit more but at least there's a functional prototype thanks to your help  :)

I believe the refreshTokens method is not needed as the token stays alive if it's used within 15 minutes of being given out. Since I'm checking door status every 90 seconds (probably should be user configurable), I figure I can just check the return status and if I get a 33, I can reauthenticate.

I need to try and implement the task method so I can write messages if I can't connect to the myQ service or if I get something unexpected back (Like from the paragraph above)

I should also probably be using getStatus instead of inspectDevices in the refreshDoors function [function method, I keep mixing them up]

I'm also thinking it should be called "MyQ Gateway"

I'm thinking it might be 80% of the way there!


Ok, finally had some time to try it out.

I ran into a problem with it's [Lua] Library depends, since JSON isn't one of the standard libs.  It took me a while to work that out, so before I dove into it I made a few changes:

a) Reformatted entire code & XML to a single style/convention
b) Refactored a little to put the "base" URL into everything
c) Tweaked the error handling for when Username/Password details weren't present
d) Used url_encode across the board "just in case"
e) Created a Localized copy of the dkjson.lua library, with a unique name, so the app can be free-standing
f) Added a bunch of [pseudo] constants for various things.

I was able to validate that it created a Lock child device, and that I can open/close my garage door with this mod.


Congrats, this is a great milestone for your efforts!


There are a bunch more things that need to be done to it, but the core is working reasonably at this time.


Changed attached.

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #25 on: May 01, 2014, 04:42:47 pm »
@jeff3lo - did guessed directions work for you?
This is very much a work-in-progress and my first attempt at Lua/LUUP
I plan on eventually writing detailed instructions on how to use but I think guessed covered it all

I'm eager to test this out.  Can you help me with some instruction on how to set this up please?

I am guessing;
1. I need to upload the 6 files via "Luup files" menu
2. I need to create a device (but I am not sure what to put in each text box).

Any help is greatly appreciated.

Offline jeff3lo

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-0
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #26 on: May 01, 2014, 06:32:06 pm »
I tried but it did not work for me on my UI5.

So I followed the steps and a new device was created, but I noticed 2 issues:
1. The device always has "Lua startup failed"
2. Inside the advance tab, I only saw a "username" but no "password" text box

Thanks.

macrho

  • Guest
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #27 on: May 01, 2014, 06:34:01 pm »
Hmm, try rebooting your vera again. I had noticed that not all fields show up in the advanced tab and a reboot or two would help.

Offline guessed

  • Master Member
  • *******
  • Posts: 5294
  • Karma: +90/-22
  • Release compat is not a bolted-on afterthought
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #28 on: May 01, 2014, 07:12:18 pm »
2. Inside the advance tab, I only saw a "username" but no "password" text box
That's my bad.  I introduced some error reporting changes to give better feedback to the user.  In the process, it "stops" after creating the Username field.

If you enter give it a value, save/reload, then the Password field will appear... where you can enter a value and save/reload to get it going again.

This is easy to fix.

Offline jeff3lo

  • Full Member
  • ***
  • Posts: 108
  • Karma: +1/-0
Re: Chamberlain/Liftmaster MyQ Plugin
« Reply #29 on: May 01, 2014, 07:31:56 pm »
Thanks for the tips, guys!

New observation:  So I ran through the whole Create Device exercise again, and this time I kept adding new variables and after numerous tries, I was able to create a "Username" and a "Password".

But after multiple saving/reloading, my device is still showing a "startup lua failed" and as a result, I don't see any Child Device being created.  The "Last Update" on my parent device is always empty, and "CommFailure" = 1.