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
//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 = '
[email protected]';
//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 = '
[email protected]';
//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.
Answers
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 !
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?
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).
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'll give it a shot.
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.
@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.
"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?
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
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 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!?
> 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 ?