The Twine forums are now archived. If you need help, please visit http://help.supermechanical.com

Idea for Temperature Monitoring App

I'm keen to see the temperature to monitor an environment at a quick glance.

How about an app that has a badge on it. Much like the iOS Messages and Mail apps that have a badge number displaying how many unread messages there are in the app.

The Twine Temperature app could have a badge that is a live view of the current temperature of your Twine. No need to ever go into the app.

If you did go into the app perhaps it could allow you to select which Twine you're monitoring should you have more than one.

Just an idea. As I don't have any of the abilities to make that happen.

Best Answer

  • 11 Comments sorted by Votes Date Added
  • Gary,
    I've done something similar to what you are asking, using a bash shell script, ThingSpeak.com and Airgramapp's push notification service.

    Here is how it works:

    1.  Use the twine.sh script from this post, with some slight modifications (checks every 5 minutes using cron):

    2.  The modifications to the script will send the first two digits of the temperature to a ThingSpeak.com channel.

    3.  Using the "apps" on ThinkSpeak, I have the React App checking the temperature at a 10 minute interval for general temps, or immediately when new data is posted for temps above a certain range (means the A/C is out when temps get too high), and then triggers a specific ThingHTTP event.  ThingHTTP will then send a broadcast message to the AirgramApp API channel, so all subscribers receive it.  The message is just a notification of what the current temperature is.

    My Twine's ThingSpeak channel showing the current temp at 5 minute intervals:


    AirgramApp is free and is available for iOS and Andriod.  http://airgramapp.com/

    Here is my modified twine.sh script (running on a FreeBSD 9.1 server):

    ----

    #!/bin/sh
    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --keep-session-cookies --save-cookies cookies.txt --no-check-certificate --post-data="email=<email>&password=<password>" https://twine.supermechanical.com/login
    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.supermechanical.com/rt/<twineID>?cached=1

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

    #first two digits of the temp are stored in T1
    T1=`echo $TEMP | cut -c1-2`

    #uncomment have the 3rd and 4th digits of the temp stored in T2
    #T2=`echo $TEMP | cut -c3-4`
    #this will format the temp as XX.YY
    #TEMP2=`echo $T1.$T2`

    TEMP2=`echo $T1`

    #replace with your own ThingSpeak API key and field that you want the temperature stored at.
    TSDATA="http://api.thingspeak.com/update?key=<API KEY>&field1=$TEMP2"

    /usr/local/bin/wget --quiet -O /tmp/temp.txt $TSDATA

Answers

  • Great idea. Would be very useful.
  • This is awesome. But really sorry to sound stupid but do you put twine.sh on a server online and just get the twine to HTTP request the url?
  • edited February 2013 Vote Up-1Vote Down
    question about this part of the script:

    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --load-cookies cookies.txt --no-check-certificatehttps://twine.supermechanical.com/rt/<twineID>?cached=1

    What is my twineID?  Is it the name given to the twine?  In my case I just called it 'Phil's Twine' - is that problematic because of the space in the name?

    Edit:  I tried this as the URL:
    ...but that gets a page not found.  So I'm guessing that the <twineID> is a number.
  • Gary, you can put it on a server anywhere in the world.  The twine
    doesn't do anything with the script, it only reports the temperature to
    the Supermechanical.com site.  The script is run via a cron job and scrapes the twine's status and
    then uploads the information to the Thingspeak.com channel you setup. 
    Using the trigger mechanism of the apps, Thingspeak.com takes care of
    the sending the temp notifications via airgramapp.


    Phil, your
    twine id is that large string that appears in the URL of your browser
    when you visit twine.supermechanical.com and select your twine.  (It
    would show up where <twineID> is in the below URL).

    https://twine.supermechanical.com/<twineID>/ruleset




  • I think I missed the bit about my Twines ID. Oops.

    Will try again.

    Stacy, what rule do you have set specifically. For the Twine to trigger the HTTP request of the .sh script?

    I'm struggling to get my Twine to want to apply a rule for any more than 1 instance and that is when it's powered on.

    I now have it USB powered with no batteries to be constant with your tweaked code.
  • Stacy - thanks for the script. Works beautifully. I've tweaked it to support two Twines, and also convert the temperatures to celsius:

    temp3=$(echo "scale=2;(5/9)*($T1-32)"|bc)

    Gary, this isn't rule-based. What Stacy's script does is call a 'hidden' URL, read a JSON packet, and grab the temperature from it. This URL may or may not be supported by Supermechanical in the future though...

    Will
  • Ok, the URL I had used above, taken from the original post, will no longer work.  You will need to change the line in the script that pulls the JSON data to:

    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.supermechanical.com/<twineID>/rt?cached=1

    In the past few days, the old URL stopped working and will now return an error.  This new URL makes sense, since it seems to conform to the URL for pulling anything else down for your twine.

    So, the script should now read:

    #!/bin/sh
    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --keep-session-cookies --save-cookies cookies.txt --no-check-certificate --post-data="email=<email>&password=<password>"https://twine.supermechanical.com/login
    /usr/local/bin/wget -o /tmp/log.txt --quiet -O /tmp/temp.txt --load-cookies cookies.txt --no-check-certificate https://twine.supermechanical.com/<twineID>/rt?cached=1

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

    #first two digits of the temp are stored in T1
    T1=`echo $TEMP | cut -c1-2`

    #uncomment have the 3rd and 4th digits of the temp stored in T2
    #T2=`echo $TEMP | cut -c3-4`
    #this will format the temp as XX.YY
    #TEMP2=`echo $T1.$T2`

    TEMP2=`echo $T1`

    #replace with your own ThingSpeak API key and field that you want the temperature stored at.
    TSDATA="http://api.thingspeak.com/update?key=<API KEY>&field1=$TEMP2"

    /usr/local/bin/wget --quiet -O /tmp/temp.txt $TSDATA


    -Stacy
  • For those who have a Vera 3 from MiCasaVerde, I just created a plugin for the unit that will poll the twine.  It saves the values in variables that can be retrieved later, and you can also request for a value to be returned when the polling function returns.

    See here for info:

    http://forum.micasaverde.com/index.php/topic,15617.0.html


  • URL https://twine.supermechanical.com/rt/<twineID>?cached=1 seems not to work any longer.
    anybody got a clue how to adapt the above script?

    regards,
    matthias
Sign In or Register to comment.