• We talked briefly last year about an API. My company develops the Indigo home automation software for the Mac. We would love to see an Indigo plugin for the Twine. We would prefer some way to directly catch status updates whenever something changes on the Twine. Is that going to be possible?
  • 50 Comments sorted by
  • Yup, a robust API is essential if these things are going to go anywhere. Handcuffing developers to the Supermechanical website won't grow anything. We need direct access to and interaction with our Twines. Until then, they're sort of proof-of-concept toys.
  • another approach: ended up writing a shell script that logs in, grabs current temp, writes to a log and posts to a google sheet (need to grab form key and form element name from source of form submit page on google). i set up in cron to run every 10 mins and log through stdout to a file

    you get back good JSON from the supermechanical website (like: {"gs_version": "Oct 3 2012-11:35:08", "age": 10.875224113464355, "ts": 1357246592.0, "values": [["00004999f257830700", "1.1.4"], ["00004999f257830701", 2600], ["00004999f257830703", "bottom"], ["00004999f257830705", 2615144], ["00004999f257830706", 0], ["00004999f257830707", 0]], "last_poll": 1357245824.0, "rssi": 178} )

    see twine.sh below:

    wget -o log.txt --quiet -O temp.txt --keep-session-cookies --save-cookies cookies.txt --no-check-certificate --post-data="email=REPLACE_WITH_YOUR_LOGIN&password=REPLACE_WITH_YOUR_PASSWORD" https://twine.supermechanical.com/login

    wget -o log.txt --quiet -O temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.supermechanical.com/rt/REPLACE_WITH_YOUR_TWINE_ID?cached=1

    DATE=`date`

    TEMP=`cat temp.txt | awk -F"," '{print $7}' | awk -F"]" '{print $1}' | tr -d ' '`

    echo "$DATE|$TEMP"

    GSHEET='https://docs.google.com/spreadsheet/formResponse?formkey=REPLACE_WITH_YOUR_FORM_KEY&REPLACE_WITH_YOUR_FORM_ELEMENT_NAME='$TEMP

    wget --quiet -O temp.txt $GSHEET
  • Oh, right, the Q/A format. Short answer: yes, possible, but how we'll prioritize a thoughtful API is another question. In the near term, we will listen to what people want. I understand that if you want to simply collect data regardless of triggering events, we don't have a good solution at the moment.
  • I'd love to just graph my Twine's temperature over time. An API to query it (polling), or alternatively a push API that sends an HTTP request when a change happens (interrupt style) would be great.
  • +1 for an API that I could access and tinker with. Like Kit and Derek (above), I'm a Rails developer who was (a little) disappointed to learn that my interaction with Twine is limited to the rules and HTTP get requests from the official Twine app.

    I understand that shipping thousands of Twines is the priority right now, but empowering the developer community to build software/apps that run on top of the the Twine platform has to be a close second, no? My guess is that the really interesting and innovative (read: marketable) Twine use-cases will come from folks who have access to a robust API.
  • This is indeed very disappointing. I have been waiting for the Twine for weeks and was hoping to install a service on my computer that polled the device in regular intervals for current temp and humidity. Right now I can only define a rule and the humidity is only digital yes/no. I never saw it anywhere that the humidity sensor was non-analog.
  • I can only agree with Holger. Simple logging was one thing i certainly expected
  • Several of you have come up with very clever workarounds to fill in the current holes. (If you actually do a piezo sensor+drinking bird, video please!) I can't respond to every thread (you'd rather have me working on the features, right?), but we listen. David and I have a long to-do list.

    We don't make a humidity sensor at this point, but the moisture sensor detects the presence of liquid, yes. Technically, it's tuned for liquid conductivity but even oily skin will work. We've used it as a punch clock.
  • The URL listed above to pull the data down will no longer work.. To get the JSON data, you need to use:


    This just changed. The old method above will give you an error.
  • had the same issue my data logging stopped between 19:30 and 19:45 PST last night (March 25) - cause the url format changed exactly as Stacy indicates.  "rt" is now after the twine id as opposed to before.
  • they changed the url formulations.  i also started logging 3 twines for different experiments for interactions between different zones ( results: https://docs.google.com/spreadsheet/ccc?key=0As0IK0j_MojzdFVLemRNVS1kNmpIR0JQWC01UmtXOFE&usp=sharing - note the lack of data for it was busted :).  here's the updated shell script - i run it every 30 mins now:

    wget -o log.txt --quiet -O temp.txt --keep-session-cookies --save-cookies cookies.txt --no-check-certificate --post-
    data="email=REPLACEWITHYOUREMAIL&password=REPLACEWITHYOURPASS" https://twine.cc/login 

    wget -o log.txt --quiet -O temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.cc/REPLACETWINE1_ID/rt?cached=1

    DATE=`date`

    TEMP=`cat temp.txt | awk -F"," '{print $7}' | awk -F"]" '{print $1}' | tr -d ' '`

    TEMP=${TEMP:0:2}

    wget -o log.txt --quiet -O temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.cc/REPLACETWINE2_ID/rt?cached=1

    TEMP2=`cat temp.txt | awk -F"," '{print $7}' | awk -F"]" '{print $1}' | tr -d ' '`

    TEMP2=${TEMP2:0:2}

    wget -o log.txt --quiet -O temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.cc/REPLACETWINE3_ID/rt?cached=1

    TEMP3=`cat temp.txt | awk -F"," '{print $7}' | awk -F"]" '{print $1}' | tr -d ' '`

    TEMP3=${TEMP3:0:2}

    echo "$DATE|$TEMP|$TEMP2|$TEMP3"

    single='$TEMP'&entry.1.single='$TEMP2'&entry.3.single='$TEMP3

    wget --quiet -O temp.txt $GSHEET
  • After playing around with mine for a bit today, it doesn't look possible given the current tools to get the temp/direction into Indigo whenever it changes. At least, not without creating a rule for every possible temperature. I suppose it would be possible for orientation changes since there are only a fixed number of those.

    We'd really be interested in working with you guys to enable a better integration with home automation software. The regular 1 minute update interval that the twine website gets would be awesome if we could configure the twine to update another URL with values that frequently. Just thinking out-loud here.
  • Jay, we've got it on our to-do list - after shipping a couple thousand boxes, of course! You can currently output the temperature in a HTTP action.
  • Yep, and that's great, but limited to only when one of the rules fires. The rule definitions don't allow you to fire whenever a temperature changes regardless of the value (which seems like a really good "when temperature" rule: "when temperature changes"). As I mention above, you could create a rule for every possible temperature but that's not a very practical hack.

    Keep up the good work!
  • I couldn't really decide whether to accept or reject the answer - the first sentence I suppose answers the question, but the last question seemed to be a proposal for a workaround but I don't think it's a practical workaround.

    If you want to change the answer to accepted that's fine.
  • Gary, that's possible now. Just make sure your rule's "level" is beyond where you want to start collecting (above or below some threshold). You can tell it to post the data to a URL now.
  • I'm trying to do something similar. I have a Rails app set up to collect HTTP gets to record the temperature from my Twine: http://twine-temp.herokuapp.com/ (code is here if you're interested: https://github.com/derekeder/twine-temp)

    I've been able to trigger a recording manually by setting an orientation rule and flipping my Twine over, but I'd like to set my Twine to record at regular intervals. Once an hour is more than fine.

    Would setting 'reset after' to 3600 seconds do the trick? Is the specific logic for these settings documented anywhere?

  • No, and we do need to take the time to document. The reset time is the time before the condition can be triggered again. For example, if I put a magnetic switch on a swinging door, I might set the reset time to 10 seconds so that the rule isn't triggered as the door swings back and forth on one push.
  • Dang...I just did what Derek has already done. That's what I get for not perusing these discussions again. I have mine running in OpenShift, and its a lighter weight Sinatra app - pumping the data into Mongo. I'll post the code shortly.

    If I understand what Derek is stating about the reset time, wouldn't the rule trigger right after the reset time - if the condition is true? So...just set the temp to is above 0, or something and then the reset to 300 - to get an update every 5 mins?
  • The condition is true when it _crosses_ that temperature. Twine watches for the event. The reset value is the amount of time after an event that the condition can be evaluated again.
  • Ok - I'll watch this thread and wait for updates.

    Until then, I set a bunch of 'rises above' and 'falls below' rules within 65-80 deg F.

    Based on some of the other comments, it sounds like some kind of 'regular interval' rule would be very popular.
  • I am a long-time Indigo user, and a new Twine owner. I'd love to see integration between the two.
  • Twine will push data out using the RBS. But what if we have a way to poll twine for current metrics. Poll it any maybe it returns a JSON array with what all connected/integrated sensors are reading.
  • It seems like there are really two desires in this post. THere isn't a PULL style API yet, but there is a PUSH via http. As for updating anytime the temperature changes, I was extremely disappointed that it didn't with this myself. It's a software update, so lets hope. For me, it's the only useful intent I currently have, so to rig to to do more or less what I want, I'm getting the most sensitive piezo sensor here....

    https://www.sparkfun.com/categories/143?sort_by=price_asc&per_page=50

    and I'm rigging it on the breakout with two rules - on wiggle (on) send me the current temp. on on (stop wiggle) send me the current temp. Then i'm going to place it precariously somewhere that has vibrations. It wont be consistent, but it'll get me through until they add it. Or add movement begin/movement end on the accelerometer.
  • Jesse, you need one of those 'drinking birds' to tap the sensor. http://en.wikipedia.org/wiki/Drinking_bird
  • Hey guys,
    I have found myself running into the same issue. I am trying to setup my Twine to post data to Cosm. And my code is working fine but there doesn't seem to be any good way to force an update. Perhaps I can use my breakout board with a 555 timer. Has there been any talk of being able to publish data to cosm or similar services?
  • If it's just to poll, I've thought about whipping something up in Python, using Beautiful Soup, to scrape the Twine data off the web site. Just don't poll too often (no point in more often than once per minute), that'd be rude....
  • My Twine is offline again, i.e. i took out the batteries. Even the simple rule set I had defined would stop firing. I always got one notification per event, but then the Twine simply went quiet. The temperatures changed, the events should have been triggered, nothing happened. When I connected to the web interface I got the message that my Twine last updated data hours ago. The only way to "get in touch" with it was to actually turn it over a couple of times. That is not making any sense as I want to use it to monitor something I do not get to on a regular basis (e.g. my attic or spaces in the cellar). Having to turn the device over to get it out of sleep is not an option.
  • +1 on allowing the device to push each update (regardless of rules) to a configurable external service. Assuming the push API were openly document, it would be just a simple matter of changing the configurable endpoint address?

    The hardware is great, but freeing the data for use with any external service would really generate an explosion of innovative uses. Right now I feel the Twine is somewhat limited by what functionality is present on the hosted software side of the Super Mechanical site.
  • I agree with the comments here. I put together a COSM bridge triggered via HTTP but it isn't firing regularly except for first time and test URL.
    A built in bridge to COSM would be nice as you could use the data from COSM in a variety of ways, however, the problem is the triggering - i.e. it isn't happening the way we'd all like it to.
  • Thanks for sharing Jay, that scripts works great!
  • I've taken the twine.sh script above and have the temperature (just the first two digits, since it temp is returned as a four digit number) sent to a channel on ThingSpeak. 

    I then have React and ThingHTTP setup to use the Airgram push service (like Prowl but free and works on Android), to alert me if a certain temperature is reached.

  • Hey guys - 5 months since my last post. Any update on an API?
  • Looks like the link to fetch the JSON data from your twine is now dead.
  • Hmm, never mind.  The URL I had was different.  Strange.
  • An API for collecting data from the Twine would certainly be useful. The current 30 action per hour limit is very restrictive, and the current rule capabilities are trivial. Let's say i want to know if the temperature in my freezer goes above a certain limit *and stays above for 30 minutes* (because during a defrost cycle the temperature can exceed the limit, but i don't care). Or maybe i really care about the trending pattern in the sensor history in a custom way. Squwk.com can handle stuff like this, so it would be nice to be able to tell twine to deliver data there (while also checking the twine site for firmware upgrades and such).
  • Hmm, I wonder if something changed again. Just noticed that the wget is returning most of the information except everything in the values section is blank.

    Any ideas?
  • Ok, you have to change the url to use twine.cc for it to report the items properly again.

  • Is there any kind of data dictionary for the JSON that is returned here? 
    I'm trying to figure out the abbreviations and the difference between some of these fields. What does 

    {"gs_version": "Oct 31 2012-08:21:10", "age": 107688.28125, "ts": 1372774784.0, "values": [["0000b41e7bfd804900", "2.0.2"], ["0000b41e7bfd804901", 7100], ["0000b41e7bfd804903", "top"], ["0000b41e7bfd804905", 2687181], ["0000b41e7bfd804906", 0], ["0000b41e7bfd804907", 0], ["0000b41e7bfd804904", 0], ["0000b41e7bfd804902", 0]], "rssi": 198, "ruleset_id": "35075", "last_poll": 1372774528.0}

    Obviously 0000b41e7bfd8049 is my Twine ID. 
    I'm guessing age is the amount of time that's passed since the last reading in seconds.
    "top" would be the orientation of the Twine. 
    "7100" is the temperature with an implied decimal. 

    What are the rest? Is this documented anywhere outside this thread?

    Thanks,
    Tom

  • OK. To answer my own question, I found this other thread with input from John Kestner: 

    That explains all of the values. 

    I'm still unsure on gs_version, age, ts and last_poll. Any help?

    Thanks,
    Tom
  • gs_version = radio firmware version date  (hover over your twine, the date here will match that shown in radio version)
    age = how long it has been since the twine last submitted an update
    ts = ?? possibly a timestamp for something?
    last_poll = ?

  • Anybody had problems with the values coming back blank when calling from wget, curl. I get values when querying https://twine.cc/zzz/rt?cached=1 from the browser

    Fixed - Found I needed to use cookies in order to get the values
  • Jay Erickson,

    Thanks for your script.

    I ended up butchering it for my own use.

    One bit I ended up changing was the method for changing the 5-digit temperatures to 2-digit.

    Your truncation breaks for temperatures over 100°F.

    Initially, since the temperature of the external sensor I am using was always over 100°, I simply truncated at three digits. Imagine my surprise when it dipped below 100° - instantly my graph peaked to 997!

    In any case, I replaced:
    TEMP=${TEMP:0:2}

    With:
    let TEMP="TEMP/100"

    That seems to work as intended.
  • does anyone have a (near) complete list of (undocumented, unofficial, subject-to-change) API calls?

    i know about

    https://twine.cc/ID/rt?cached=1

    what i would like to know is how i can get the list of IDs associated with my login, and a list of sensors identifiers associated (i.e.., do i just care about the last octet, e.g., 7b=moisture, d6=magswitch,a6=breakout, or is there some other mapping involved)

    any pointers?

    thanks!
  • Take a look at the post several replies up.

    I've gone ahead and written a plugin for my Vera 3 ZWave Home Automation controller that lets me poll the twine and use things like its temperate in applications.

    Just another hack along the same lines as the script above.

    You can find information about it here (and get the Lua code for the plugin):


  • many thanks... i suspect i'll be asking you a question or two (-;
  • Some days has past and I want to know if there is something new to say to the API? Still no way to get data directly from twine device?
  • Is an API in the work or is this a dead prospect? Should I retire my Twine and move on to an Raspberry Pi + temperature options?
  • I also had blank values with the https://twine.cc/ID/rt?cached=1 URL, but fixed it by adding the access_key parameter.

Howdy, Stranger!

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