Page 1 of 1

Power meter appliance support (EnviCC 128)

Posted: Monday 07 July 2014 12:14
by JC38
Hello,

I’m using Domoticz with a Windows 2008 R2 server. Behind this server, I’ve got a small appliance USB connected with a dongle, emulating a COM port. This appliance, an Envi CC128 from Current Cost send thru the USB cable, some power consumption information transferred by radio from a meter clamp.
Here is a link of the technical specification for the data received. http://www.currentcost.com/cc128/xml.htm

Example below is what I get, using a simple .cmd command connected to the COM port :
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:04:27</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01136</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:04:33</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01129</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:04:45</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01151</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:04:58</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01141</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:04</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01129</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:16</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01166</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:28</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01133</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:40</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01138</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:46</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01137</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:05:58</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01135</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:04</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01131</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:11</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01135</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:17</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01144</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:23</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01141</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:29</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01140</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:47</time><tmpr>23.5</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01130</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:06:53</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01135</watts></ch1></msg>
<msg><src>CC128-v0.11</src><dsb>01520</dsb><time>16:07:06</time><tmpr>23.4</tmpr><sensor>0</sensor><id>00617</id><type>1</type><ch1><watts>01130</watts></ch1></msg>

Is it possible to get this device monitored by Domoticz ? In case of acceptance, please, don’t take care of the time value sent by the device, mine for example has a regular deviance from real time, so using the Domoticz time is a better idea.
Drivers for the dongle exist for Windows and I think they are also available for Linux.

Best regards.

JC

Re: Power meter appliance support (EnviCC 128)

Posted: Friday 11 July 2014 4:31
by Dnpwwo
I've think I have something similar (http://rainforestautomation.com/wp-cont ... i_r127.pdf) which monitors my house power. It also is a USB stick that presents itself as a COM port and spits out XML, it connects to my meter using Zigbee.

I use a python script (on Linux) to post http updates into Domoticz mapped to a virtual device and it is very reliable. COM port handling is very straight forward in Python, if you have any scripting skills I can post my script to get you started. Python is available on Windows so it may be useful.

Re: Power meter appliance support (EnviCC 128)

Posted: Friday 11 July 2014 15:26
by JC38
Thank you Dnpwwo for your answer.
I'm very interested in your python script so if you can post it somewhere, it would be nice of you.

Don't hesitate also to post some screenshots from Domoticz, regarding the virtual device you use.
Today, I only know how to create a switch for a virtual hardware but maybe it's possible doing the same for other kind of devices.

Re: Power meter appliance support (EnviCC 128)

Posted: Saturday 12 July 2014 1:37
by Dnpwwo
In Domoticz my devices looks like this, one shows current usage and one shows summary for the day:
Untitled.png
Untitled.png (26.02 KiB) Viewed 4677 times
The script is run from a cron job every 5 minutes and exits if another process is already running it. This auto starts it at boot time and also handles any restarts if required. The logging holds 10MB of log data in 10 files and rotates when they are full, that is controlled in the .conf file where you can also set the log level. Changing it from INFO to DEBUG will make it dump the XML to the log which is probably what you will need.

Runs under Python 2 on the same machine as Domoticz.

Credit where its due, I started from this script https://github.com/frankp/python-raven/ ... _script.py which publishes the data to MQTT.

Re: Power meter appliance support (EnviCC 128)

Posted: Saturday 12 July 2014 18:21
by JC38
Thank you for all this information. I will study it.

Re: Power meter appliance support (EnviCC 128)

Posted: Wednesday 16 July 2014 9:02
by tommysharp
I have a very similar device so would be interested to see how you get on with this. Although I've pretty much got zero experience with python so it might be too difficult for me...

Re: Power meter appliance support (EnviCC 128)

Posted: Friday 18 July 2014 22:39
by JC38
Here is my first version of the script running Under Windows with Perl and sending the values to a Domoticz running on a Raspberry.

The script has to be adapted if more than one device are monitored thru the EnviCC (it supports ten sensors, sensor 0 is the global)
On the last line
#500 is a value in kWH, I need to calculate it but don't know how for now, so for sending a value, I put something...

Code: Select all

use warnings;
use strict;
my $PortObj;

#Change settings below to your server
my $PortName = "COM4";
my $IP="192.168.0.37";
my $PORT="8080";

# print "OS : $^O \n";
if ( $^O =~ m/Win32/ ) {
     require Win32::SerialPort;
     $PortObj = new Win32::SerialPort ($PortName) or die "Can't open $PortName: $!\n";
}
else {
    require Device::SerialPort;
    $PortObj = new Device::SerialPort ($PortName) or die "Can't open $PortName: $!\n";
}

$PortObj->baudrate(57600) || die "fail setting baud";
$PortObj->parity("none");
$PortObj->databits(8);
$PortObj->stopbits(1);
$PortObj->write_settings || die "no settings"; 
undef $PortObj;

open(SERIAL, "<$PortName") or die "Can't open COM4: $!";
while (my $line = <SERIAL>) {
	if ($line =~ m!<tmpr> *([\-\d.]+)</tmpr>.*<sensor>(\d+)</sensor>.*<watts>0*(\d+)</watts>!) {
		my $temp = $1+2.3; # I add 2.3 to the temp because my EnviCC doesn't get the right temperature
		my $sensor = $2;
		my $watts = $3;
		print "Capteur : $sensor - Puissance : $watts W - Temp.: $temp\n";
		`curl -s "http://$IP:$PORT/json.htm?type=command&param=udevice&idx=160&svalue=$temp"` ;
		`curl -s "http://$IP:$PORT/json.htm?type=command&param=udevice&idx=161&svalue=$watts;500"`; 
	}
}

Re: Power meter appliance support (EnviCC 128)

Posted: Saturday 19 July 2014 9:44
by epierre
if you want to parse the xml, have a look at xml::simple, some example in the perl for domoticz wiki page.

Re: Power meter appliance support (EnviCC 128)

Posted: Saturday 19 July 2014 21:21
by JC38
Hello

You mean this url http://www.domoticz.com/wiki/Perl_for_Domoticz ?
Searching for the word xml doesn't find anything...

Anyway, for this job with the Envi, for accessing the data, the problem was only the management of the COM port wich is different between Linux and Windows. Without this line( undef $PortObj; ) in the Windows version, it hangs opening the SERIAL on the next line.

Now, my problem with the Envi is how to find the good algorithm for pushing the kWr value, as the Envi regularly sends watt data (power) and not energy (kwh) data.

Re: Power meter appliance support (EnviCC 128)

Posted: Monday 21 July 2014 22:21
by JC38
@Dnpwwo

I tried to understand your code, not easy for me.
You have 2 devices, 1 called domDevice, the left one (CM119/CM160)in the capture and the second (RFXMeter) is domTotalDevice (at the right).
Both have the same kwh values, so why don't you keep the first one only ?

I see that you summarize something as the second parameter (kwh) for the s.value.
Do you directly get kwh from your appliance or only watt that you "transform" to get kwh ?

Re: Power meter appliance support (EnviCC 128)

Posted: Thursday 24 July 2014 2:41
by Dnpwwo
@JC38

The script posts 2 values to Domoticz, Instantaneous Demand & Summary (total Kwh). Initially I wasn't sure the best device type to map these to so I played around and ended up with two that seemed useful. You are correct that they are fundamentally same but the graphing options are different and one shows current usage while the other shows usage today. I don't actively use them for anything yet so left them both until I could see which long term charts were the most useful.

The summary code is a slight hack. My meter delivers summary data formatted to three decimal places but actually only reports to the 1/10 of a Kwh so the Domoticz summary updates were a bit infrequent. I made the code generate an interpolated value to smooth things out a bit. I think you can rip that bit out.

Would it be useful if I created a simplified version with all logic ripped out that just dumps out the XML?

Re: Power meter appliance support (EnviCC 128)

Posted: Thursday 24 July 2014 12:51
by JC38
@Dnpwwo

I understand that your Appliance sends watts and and kwh values.
Mine only sends watt values (in real time), I could get some kwr values but the way to get them would be different http://www.currentcost.com/cc128/xml.htm). That is my main problem.

Before coding anything, I have to find a method to get a kwh value starting from watt and time. If it's possible...

Re: Power meter appliance support (EnviCC 128)

Posted: Monday 06 April 2015 11:04
by benbiais
@Dnpwwo
I would be very interested in studying your script mentionned in your post of 12th july 2014 0:37.
I succeed to get in Domoticz the KW from a CurrentCost Envir with a very simple Python script. However I am lost for getting the KWh. As your result is confirmed ok by your second RFX counter, your script would be very useful for me to see how you got this KWh value, and more generally to help me with new ideas .
Would it be posible to send it to me. Thanks in advance.

Re: Power meter appliance support (EnviCC 128)

Posted: Saturday 26 December 2015 20:14
by JC38
I would like to thanks the developper who starts to integrate the Current Cost appliance as an hardware device.
I've just discovered this option by chance. Nothing is listed into the history file or into the Wiki.
I set it into my Dz running onto a Windows 2012 Server.
What i can say for now is that only one measure is monitored (and the temperature around the device also).
It also seems that the device can't be seen from another Dz (My main Dz is running onto a Rpi2, far away from the Current Cost)