How I got my Twine to report the Temperature to me via email with actual value
  • I wanted to monitor the temperature of my Twine live by having it post a live temperature to a server that could be displayed on a page designed for display on a mobile device. That was the end goal but before I had time to do that I went for the device to notify me every 15 minutes (excessive) of its temperature.

    Essentially this is a very simple PHP emailer script modified to calculate the Fahrenheit value into Celsius and report both values to me via email.


    TWINE RULE:
    WHEN temperature rises above 0...
    Trigger after 0 seconds...
    Reset 900 seconds after this has been triggered... (900 seconds is 15 minutes, adjust as required.)


    THEN http request
    http://yourdomain.com/twine/twine_temp.php?f=[temperature]

    Obviously you need somewhere to host the PHP script which is below and modify it as required to send messages to you.

    PHP CODE OF twine_temp.php

    <?php<br />//Read the Fahrenheit value from the URL
    $f=$_GET['f'];

    //Convert Fahrenheit into Celsius
    $c=intval((5/9)*($f-32));

    //Email address to send notification to
    $to = 'youremail@address.com';

    //Subject of the Email
    $subject = 'Twine Temperature is: '.$f.'f / '.$c.'c';

    //Message body of the Email
    $message = 'Hello from your Twine. I am currently sitting on '.$f.'f or '.$c.'c.';

    //Who you want the Email to appear from (make sure it is not blocked by SPAM filter)
    $from = 'no-reply@your.twine';

    //Usual PHP Email Code
    $headers = 'From:' . $from;
    mail($to,$subject,$message,$headers);

    //Display a message to anyone viewing the page that a message with values has been sent
    echo 'Update Twine Temperature Mail Sent with values F='.$f.' and C='.$c.'.';
    ?>


    The conversion of Fahrenheit into Celsius is required as it seems even though my Twine was set to Celsius it would only post Fahrenheit values.

    This was very simple to get up and running and having tested it seems to work fine.

    Now I'm onto making it post a real temperature value every 5 minutes to a page.

    Hope this has helped people. I've found the information people are posting on here really really great.
  • 18 Comments sorted by
  • Hi Gary,

    I will try and let you know. If it works with my Twine, you're a star (I did not manage to make my Twine work yet). I will try to see as well if it's possible to feed a Google Sheet using your PHP code and the Google Drive (or Google Fusion) API

    Thanks !
  • Sounds simple, except: "Obviously you need somewhere to host the PHP script ..."

    How does one begin to set this up? Is it easy to do or do I have to pay for a hosting service just for this?

  • Hi Bill, in fact it's not working on my side. The Twin device only sends one notification (i.e. is calling the website only one time) when I save the rule... however in one night my batteries went low.
    I am currently checking with Twine support whether it's linked to my device or if it's a general issue (I hope it's not).
  • Nicolas what you've suggested with Google sounds great.

    I've progressed to getting the Twine to update a server side .txt file with the temperature and then have the temperature displayed on a web page suitable for mobile devices. Unfortunately I can't get the PHP to update with when the file was last modified. I get an error message saying that this date/time can not be relied on.

    Bill unfortunately you do need to be able to host the PHP files somewhere to trigger them. I'm happy to host one for you if you don't have hosting. No charge as it's a ridiculously small piece of code.

    As with everyone else after longer use I've found that the code only seems to work when uploaded to the Twine. It doesn't trigger after the set amount of time set in the rule. So I am having all the same issues as others.

    However I did receive the odd email during the night triggering the rule and emailing. Sporadic is all that comes to mind.

    Thanks for the comments guys.
  • I don't know PHP very well, but it sounds like I would just create a Twine page on my website and add the code there?
    I'll give it a shot.
  • Very nice Gary. Thanks and works perfectly.
  • Apologies if this is a dumb question, but: why is it not possible for Twine to push a temperature value via text or email? Why does it have to be via HTTP?

    As a follow up: is it possible to trigger on a state rather than a transition? If, for example, I were to mount Twine on my (overhead opening) garage door, I'd like to get a text reporting temperature inside only if the door is closed.
  • @Andreas, yes that should work fine as long as the host supports php and not just html.

    @Michael, thanks.

    @Chris, I personally choose to have it post via HTTP so that I could see when I wanted to rather than have a constant flow of emails I wasn't interested in. With regard to your garage door question I can't help with that sorry.
  • I wrote a nearly identical script for the same purpose, and found that my Twine only sends the first query and then stops. My ruleset says:

    "When rise about 0 deg C, trigger after 0.1, reset 20 seconds after this has been triggered"

    My expectation is that the Twine detects it's above freezing (here in Perth, WA, that's always the case) and hits the URL 0.1 seconds after detecting the temperature. I also expect that it'll reset the state after 20 seconds and trigger again 0.1 seconds later.

    Am I understanding the "reset 20 seconds after this has been triggered" correctly?
  • @Matt i have the same problem, it did the very first post but then never again... seams like the service is broken... very disappointing!
  • Gary-
    Thanks for the PHP script. I just got a Twine for Christmas and have it emailing me the temperature whenever the moisture sensor gets wet. This Twine will go very nicely with the collection of AVRs and sensors (tiny Arduinos basically) that I put together whenever I have free time.
    -Mark
  • On your twine page you log into, if you read the how rules work you will see why even if your rule is set for x amount it doesn't trigger as they have set it up so that it isn't going off all the time. Which is pretty stupid for a rules based system?
  • I think it is only posting when it crosses the threshold again.

    i.e. it doesn't post until it has gone less than 0 and then crosses the 0 threshold to more than 0 for more than 0.1 seconds.
  • I'll be honest, I haven't read the various manuals and was purely reporting what I expected to happen.
  • They have been clear in early responses to posts here that the rules trigger only on threshold events. So if you have a "fire if temp rises above 50" rule, it will fire ONLY if the temperature goes from 50 to 51. If it then goes from 51 to 52 and stays at or above 51, it will never fire again. We're all hoping that they'll add more rules options.
  • Just read the responses. Lots of great replys.
    I have to admit I hadn't read any manuals. I didn't even see them.

    Agree with what Grant said about how the system is triggered "pretty stupid for a rules based system".

    So for those of us that want a constant stream of data what do we do!?
  • I think it's stupid as well. I can read: "They have been clear in early responses to posts here that the rules trigger only on threshold events"
    > in fact on my side, with 16 rules set, it is trigger only one time when I put batteries, plug the external power supply or when the Twine device is restarted.... so only one trigger
    This must be a bug otherwise I cannot see the value of this sensor.
    Did you encounter the same issues ?
  • Hi all, sorry to bring back such an old topic... BUT... is it me or the last change in twine pretty much broke this?
    I tried it and I only got the first report... The problem seems to be with the "untriggering" logic... Since the temperature never falls below 0, it never untriggers so it never re-triggers either... I think they changed from a "reset after xxx seconds" logic to a "reset after threshold is unhold" logic... :(
    So...
    Is there a potential workaround for this? I would really like to have an easy way to get an hourly-report of temperature, not just when it goes through a threshold... :(

Howdy, Stranger!

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