Pull data from my.currentcost.com or xivley.com into EmonCMS

Hello All,

Still fairly new to EmonCMS but keen to know if its possible to get energy usage data from the Current Cost Envir into EmonCMS via the cloud? I know someone did it by hacking the hardware/firmware of a CCEnvir but i was hoping it might be easy enough to knock up a script or plugin to suck the data from xivley or even better currentcost.com into a more customisable EmonCMS dashboard.

Be glad of any assistance :)

 

Thanks in advance!

TrystanLea's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

Hello Bert, Im not very familiar with currentcost, but I know xively has a good API, Can you access your data on xively? How much data do you need to transfer? Emoncms's import functionality is a little limited at the moment, its something that I need to look at

bert386's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

Thanks Tristan,

Yes Xivleys API allows yuo to read data and write data. See here:

https://personal.xively.com/dev/docs/api/quick_reference/api_resources/

I think it would be really nice for Emon CMS to be able to pull data from data repositories such as Xivley as it would allow users to manipulate and display data exactly as they wish without limitation.

 

bert386's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

Nobody else got any clues on this? I thought that one of two ways would be ideal:

Option 1 - a standalone, scheduled perl script that ran on the emoncms server that used a READ json and pulled relevant data from personal.xively.com and then used a WRITE to post the data on emoncms

Option 2 - a plugin for emon cms that allowed you to input your Xivley API key and feed id and assign that to a feed in emoncms

Can anyone point me in the direction of an accomplished emoncms coder that might be interested in deving this for a fee?

 

fversteegen's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

I don't know how to accomplish this Bert, but I suspect you use a CurrentCost Envir. If you want to have a script to feed data from the Envir to Emoncms, then have a look here: http://openenergymonitor.org/emon/node/1418

firefox7518's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

Hi

I gave up using clouds and other stuff and did it with a tiny bananpi connected via the usb/serial cable to the current cost.

I found a running PERL script here but it has some flaws so I enhanced it and I'm using it for several IAMs at the moment.

I also use this script to send the data to pvoutput.org so that I have the data also there where my PV setup will send the data to. I always have the data on my emoncms installation and pvoutput.org :-)

Here is the script I've enhanced:

#!/usr/bin/perl -w
# Reads data from a Current Cost device via serial port on a Raspi or bananapi or other linux machine

use strict;
use warnings;
use Device::SerialPort qw( :PARAM :STAT 0.07 );
use LWP::UserAgent;
use Time::Piece;
use Time::Local;

my $emon_ua = LWP::UserAgent->new;

my $emoncmskey  = "place your emoncmskey here";
my $pvoutpukey = "place your pvoutputkey here";
my $pvoutputsid = "place your pvoutput sid here";
my $host = "place the emoncms host adress here";
my $node = "1";
my $PORT = "/dev/ttyUSB0";
my $meas = 0;
my $sumwatts_sensor0 = 0;
my $sumwatts_sensor1 = 0;
my $sumwatts_sensor2 = 0;
my $sumwatts_sensor3 = 0;
my $sumwatts_sensor4 = 0;
my $sumwatts_sensor5 = 0;
my $sumTemp = 0;
my $sensor_count0 = 0;
my $sensor_count1 = 0;
my $sensor_count2 = 0;
my $sensor_count3 = 0;
my $sensor_count4 = 0;
my $sensor_count5 = 0;
my $count_limit = 6;
# my $date = strftime "%Y%m%d", localtime;
# print $date;

my $ob = Device::SerialPort->new($PORT)  || die "Can't open $PORT: $!\n";
$ob->baudrate(57600);
$ob->write_settings;

open(SERIAL, "+>$PORT");
while (my $line = <SERIAL>) {
    #print $line;
    
    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>0</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
        my $watts = $2;
        my $temp = $1;
        print "SUCCESS (Sensor0) $meas: ... $watts, $temp\n";
        $meas++;
        $sensor_count0++;
        $sumwatts_sensor0 += $watts;
        $sumTemp += $temp;
    }
    
    # extra if statements to get watts for IAMs, change the sensorname to reflect this
    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>1</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
        my $watts_sensor1 = $2;
        print "SUCCESS IAM (Sensor1) $meas: ... $watts_sensor1\n";
        #$meas++;
        $sensor_count1++;
        $sumwatts_sensor1 += $watts_sensor1;
    }
    
    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>2</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
        my $watts_sensor2 = $2;
        print "SUCCESS IAM (Sensor2) $meas: ... $watts_sensor2\n";
        $sensor_count2++;
        $sumwatts_sensor2 += $watts_sensor2;
    }
#    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>3</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
#        my $watts_sensor3 = $2;
#        print "SUCCESS IAM (Sensor3) $meas: ... $watts_sensor3\n";
#        $sensor_count3++;
#        $sumwatts_sensor3 += $watts_sensor3;
#    }
    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>4</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
        my $watts_sensor4 = $2;
        print "SUCCESS IAM (Sensor4) $meas: ... $watts_sensor4\n";
        $sensor_count4++;
        $sumwatts_sensor4 += $watts_sensor4;
    }
    if ( $line =~ m!<tmpr>*([\-\d.]+)</tmpr><sensor>5</sensor>.*<ch1><watts>0*(\d+)</watts></ch1>! ) {
        my $watts_sensor5 = $2;
        print "SUCCESS IAM (Sensor5) $meas: ... $watts_sensor5\n";
        $sensor_count5++;
        $sumwatts_sensor5 += $watts_sensor5;
    }
    
    if ( ($meas >= $count_limit) && ($sensor_count0 > 0) && ($sensor_count1 > 0) && ($sensor_count2 > 0) && ($sensor_count4 > 0) ) {
        my $avg_temp = $sumTemp/$sensor_count0;
        print "AVERAGE temp: $avg_temp\n";
        
        my $avg_watts_sensor0 = $sumwatts_sensor0/$sensor_count0;
        my $avg_watts_sensor1 = $sumwatts_sensor1/$sensor_count1;
        my $avg_watts_sensor2 = $sumwatts_sensor2/$sensor_count2;
#        my $avg_watts_sensor3 = $sumwatts_sensor3/$sensor_count3;
        my $avg_watts_sensor4 = $sumwatts_sensor4/$sensor_count4;
#        my $avg_watts_sensor5 = $sumwatts_sensor5/$sensor_count5;
        print "AVERAGE watt: $avg_watts_sensor0\n";
        print "AVERAGE watt: $avg_watts_sensor1\n";
        print "AVERAGE watt: $avg_watts_sensor2\n";
#        print "AVERAGE watt: $avg_watts_sensor3\n";
        print "AVERAGE watt: $avg_watts_sensor4\n";
#        print "AVERAGE watt: $avg_watts_sensor5\n";
        
        # Additional line for each sensor, note that meas increases 2 times in the cases of 1 additional IAM, so watt readings need to be divided by meascount/sensoramount
        my $emon_url = "http://$host/input/post.json?apikey=$emoncmskey\&node=$node\&json={house_power:$avg_watts_sensor0,room_temp:$avg_temp,heatpump_power:$avg_watts_sensor1,buero_power:$avg_watts_sensor2,foodcenter_power:$avg_watts_sensor4}";
        print "$emon_url\n";
        my $emon_response = $emon_ua->get($emon_url);
        
        my $date = localtime->strftime('%Y%m%d');
        print "Heute ist $date\n";
        my $time = localtime->strftime('%H:%M');
        print "Jetzt ist $time\n";
        # Line below is because I upload readings to 2 sites in parallel as backup
        my $pvoutput_url = "http://pvoutput.org/service/r2/addstatus.jsp?key=$pvoutpukey&sid=$pvoutputsid&d=$date&t=$time&v4=$avg_watts_sensor0&v5=$avg_temp";
# {power:$avg_watts_sensor0,temp:$avg_temp,sensor1:$avg_watts_sensor1}";
        my $pvoutput_response = $emon_ua->get($pvoutput_url);
        print "$pvoutput_url\n";
        
        # Do not forget to reset the sum for an additional sensor   
        $meas = 0;
        $sumwatts_sensor0 = 0;
        $sumwatts_sensor1 = 0;
        $sumwatts_sensor2 = 0;
        $sumwatts_sensor3 = 0;
        $sumwatts_sensor4 = 0;
        $sumwatts_sensor5 = 0;
        $sumTemp = 0;
        $sensor_count0 = 0;
        $sensor_count1 = 0;
        $sensor_count2 = 0;
        $sensor_count3 = 0;
        $sensor_count4 = 0;
        $sensor_count5 = 0;
print "Wait 60s to repeat\n";
sleep(60);
    }

}

To use it for all sensors you have to add the sensorcount to the following line:

  if ( ($meas >= $count_limit) && ($sensor_count0 > 0) && ($sensor_count1 > 0) && ($sensor_count2 > 0) && ($sensor_count4 > 0) ) {

You also have to add the missing sensors to the existing parameters in the link:

 my $emon_url = "http://$host/input/post.json?apikey=$emoncmskey\&node=$node\&json={house_power:$avg_watts_sensor0,room_temp:$avg_temp,heatpump_power:$avg_watts_sensor1,buero_power:$avg_watts_sensor2,foodcenter_power:$avg_watts_sensor4}";

I think you will get it :-)

 

It's working here: http://swiss-solar-log.ch:85/firefox/Hausverbra

[Duplicate post deleted. Please read this. Moderator - RW]

bert386's picture

Re: Pull data from my.currentcost.com or xivley.com into EmonCMS

@firefox7158 

Thanks! that is a solid looking script. Appreciate you sharing it here. I will keep this bookmarked in my list of tools to try if my cloud solution fails to get off the ground!

 

 

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.