HOWTO: Accessing your twine status programmatically from your (Android) phone
  • My twine is setup to email me if the garage door has been open for more than 30min. After some initial email delivery hiccups this is now working well.

    I also wanted to write a program for my Android phone so that I could query the garage door's status directly. Yes, I know I can bookmark the twine's page but that's not as fun as writing a program that pops up a simple "OPEN" or "CLOSED" alert panel :-)

    If you're interested in doing the same thing, here are some tips...

    On my Android 4.1 Jellybean phone (Nexus S) StartCom, the CA for twine.supermechanical.com, isn't trusted. When I hit my twine's page with a browser I get a certificate error. It's easy enough to hit "Continue" in the browser, but more annoying to deal with this programmatically.

    So I downloaded the following certs to root directory my phone and then imported them with System Settings -> Security ->Install from storage:
    https://www.startssl.com/certs/ca.cer
    https://www.startssl.com/certs/sub.class1.client.ca.crt
    (You may only need the second one but I loaded both to be sure)

    Once completed you should no longer get certificate errors in your browser.

    The next step is getting your twine's status. I used Firefox + Live HTTP Headers to watch the http traffic when I load the twine's page and isolate the call the retrieves the JSON-encoded twine status.

    My JSON status URL looks something like this:
    https://twine.supermechanical.com/rt/<1>?cached=1&_=<2>
    <1> is the twine's id # (long number that's in your twine's status page URL
    <2> is another long number, I assume a timestamp, I haven't played with this, just grabbed it verbatim from the HTTP request. Maybe one of the Twine team members can comment?

    The other item you want from that request is your user_id cookie. You'll need to supply it when your program makes a GET request.

    Parsing the JSON is easy, I just look for a substring of "top" or "front" which, on my twine, maps to the garage door being "CLOSED" or "OPEN".

    I used Tasker to write the program itself. A very handy tool for quick prototyping, writing productivity apps, or customizing your phone's behavior. If you have an Android phone and have read this far, my guess is that you'll find it useful! :-)

    http://tasker.dinglisch.net/

    Hope this helps, have fun!

    -Paul.
  • 11 Comments sorted by
  • What other APIS are planned. How about a simple http request? REST like.
  • So you are saying is if I trap the GET request from my twine and get the <1> value of my twine I can hit that URL to make a JSON query to the device instead of waiting for push notification?
  • Unfortunately not. He's talking about getting information from the supermechanical server.
  • Ah... but still I can make a programmatic query instead of waiting for the notification push. Even if it's not a direct to the device query, it still allows me to query the last known state of the device instead of waiting for the push.
  • @YoYo Pete: Yes, that's right. As long as you include the user_id cookie, you can get the JSON-encoded status of your twine. Not from the twine directly, but the last known status from the server.

    I've been using this for a week now and it's working fine. Haven't had to renew the user_id cookie and regular tests have all matched with actual garage door state :-)

    BTW, that same JSON structure also gives you voltage, temperature, last poll, etc.
  • When I view the source of my Twine page, I found the ID. It's found in a list item:

    < li>
    < a href="/ruleset/00001a111a111a11">YoYo-Twine< /a>
    < /li>

    I changed numbers to 1 and letters to a for the example. YoYo-Twine is what I renamed the device to on that web page. I also added a space into the HTML above to get it to display correctly.

    Then I just used this URL: https://twine.supermechanical.com/rt/00001a111a111a11

    The ?cached=1 part of the URL will used a cashed query, or removing (or changing it to a zero will actually force it to poll your twine, but that may take like 60 seconds after the call is made.

  • I can only access that page if I'm logged into my Twine-account. But how can I access that page, if I'm not logged in? https://twine.supermechanical.com/rt/1111111111111111?cached=1 and what else? Thanks for your help!
  • Here's how I did it using IE in windows and scripting: https://github.com/YoYo-Pete/Twine/blob/master/JSON-Status/getStatus.vbs

    I'm still working on the winHTTP version, but stuck and not really spending the time to work past it.

    Instead going to try to build a server with google cloud messaging and have that do push notifications to my client, probably leverage the http get first.   But....   Maybe once you register your device/account I can have it scrape the current twine JSON.

    What I want to know is if you are authenticated already and use that JSON page with another twine ID, will it show you or not?

    Anyone want to PM me a twine ID to do some testing like that?

    More so I wish there was a dev roadmap so we dont waste time for a solution that's already in the works.  (But I feel like they are more working on the twine internals instead of the cloud infrastructure)
  • I'm trying to do that in Python now, so I can use the Twine JSON with my Raspberry Pi.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!