Thursday, January 14, 2010

Twitter update your energy usage using a TED 5000

The Energy Detective 5000 has an API that can be polled for data using this simple perl script that I wrote.

You can find my Twitter feed here:

Order your own TED 5000 here.

If you are running Debian Linux you will need to install a few dependencies:
sudo apt-get install libxml-simple-perl libwww-curl-perl

And you can automate the execution of this script with an hourly cron job:
Run: crontab -e
and then add this line (assuming you put my script in ~/bin/:
0 * * * * ~/bin/


# Written by Jason Garland @

my $twitter_user="jgarland79power";
my $twitter_password="super_secret_password";

my $ted_ip="";

# use module
use XML::Simple;
#use Data::Dumper;
use WWW::Curl::Easy;

sub write_callback {
 my ($chunk,$variable)=@_;
 # store each chunk/line separately
 # This should be faster than using $$varable .= $chunk;
 push @{$variable}, $chunk;
 return length($chunk);

my $curl = WWW::Curl::Easy->new();

my @body;
$curl->setopt(CURLOPT_WRITEFUNCTION, \&write_callback);
$curl->setopt(CURLOPT_FILE, \@body);
$curl->setopt(CURLOPT_URL, "http://$ted_ip/api/LiveData.xml");
my $body=join("",@body);

# create object
$xml = new XML::Simple;

# parse XML
$data = $xml->XMLin($body);

my $PowerTDY=$data->{Power}->{Total}->{PowerTDY};

$status="used $PowerTDY watt hours of #electricity since midnight today. Find out more here:";

print $status,"\n";
$curl->setopt(CURLOPT_URL, "" );
$curl->setopt(CURLOPT_POST, 1 );
$curl->setopt(CURLOPT_POSTFIELDS, "status=$status" );
$curl->setopt(CURLOPT_USERPWD, "$twitter_user:$twitter_password" );


jgarland79 said...

T.E.D. linked to this article!

wanikajagodzinski said...

Yamagami has denied he dedicated the crime because of|as a outcome of} he was against Abe's political views, in accordance with the police. The Japan Times further reported, "There had been no stories of bother from the manufacturer . But in April this year, Yamagami told the dispatch firm that he wanted to stop because of|as a outcome of} he was 'drained, and he left the job the next month." The Japan Times reported that Yamagami didn't appear to be politically energetic, citing a source from his former firm. It added that Yamagami attended a public high school in Nara and wrote in his commencement yearbook that he "didn’t have a clue" what he wanted to be sooner or later. Tetsuya Yamagami, 41, is the suspect arrested for shooting and killing former Japanese Prime Minister Shinzo Abe.

2e6gs23ncy said...

Our Facility is a program machine store specializing in Aero house manufacturing. CNC is a collective of people working beneath a House Shoes for Women household owned enterprise that upholds the required highest commonplace of quality to ensure precision. Our service is with the shopper in thoughts and to supply one of the best. This contains laser cutters, lathes, water jet cutters, and even embroidery machines.