Page 1 of 4

[154] - CurrentCost Envir support

Posted: Sunday 06 April 2014 19:06
by Niekoesj
Hi All,

I really would appreciate if Domoticz should support the Envir (Current Cost) devices. http://www.currentcost.com
Before i used Domoticz, i used measureit (Python script) to read the XML from the USB port. (Envir is connected trough USB/COM port to the Raspberry).
Some sourcecode is allready availble at: https://code.google.com/p/measureit/downloads/list

Is there a way to make this work with Domoticz? The current Measureit datagrabber (Python) works very wel! But i can't get apache+mysql-server installed on my Domoticz Raspberry. :(
The Current Cost devices are worldwide sold (Also here in The Netherlands at some hardware stores like; Praxis and Gamma).
I use this device because it won't require network and power supply in your electrical cabinet at you home/

These packages get received every 5 seconds from the Envir device on the USB-Comport:

<msg> start of message
<src>CC128-v0.11</src> source and software version
<dsb>00089</dsb> days since birth, ie days run
<time>13:02:39</time> 24 hour clock time as displayed
<tmpr>18.7</tmpr> temperature as displayed
<sensor>1</sensor> Appliance Number as displayed
<id>01234</id> radio ID received from the sensor
<type>1</type> sensor Type, "1" = electricity
<ch1> sensor channel
<watts>00345</watts> data and units
</ch1>
<ch2>
<watts>02151</watts>
</ch2>
<ch3>
<watts>00000</watts>
</ch3>
</msg> end of message

For more technical detail see: http://www.currentcost.com/cc128/xml.htm

I'am also wondering if more people here on this forum uses Current Cost devices :)

Re: [154] - CurrentCost Envir support

Posted: Wednesday 09 April 2014 23:19
by Gambit
improved CC modules

http://www.domoticz.com/forum/viewtopic ... &hilit=edf

if could be setup as a new hardware device and to poll via JSON or something

Re: [154] - CurrentCost Envir support

Posted: Wednesday 16 July 2014 9:03
by tommysharp
Would love to see support for these devices added as I have one too!

Re: [154] - CurrentCost Envir support

Posted: Sunday 28 September 2014 0:15
by steef84
Just curious... any progress on this? These are cheap on sale now in local stores (gamma). 70 % discount. Maybe it has a reason [WHITE SMILING FACE]

Re: [154] - CurrentCost Envir support

Posted: Sunday 28 September 2014 2:40
by Dnpwwo
There is some more info here: http://www.domoticz.com/forum/viewtopic.php?f=31&t=2854 (including possible ways to set up Domoticz devices), don't know if JC38 ever got his Perl working though.

If you already have a Python script to do the XML parse then you are almost there, you just need to create a device in Domoticz and post the data to it using http, you shouldn't need to install anything.

In Python just do this (assuming the script is running on the same machine as Domoticz):

Code: Select all

import urllib
domDevice=25     # your device number
...
dataValue =      # find the bit of script that has a meter reading
...
httpresponse = urllib.urlopen("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + str(domDevice) + "&nvalue=0&svalue=" + dataValue )
httpresonse.read() will tell you what happened afterwards.

If you get it to work you may want to post the script to help other people out.

Re: [154] - CurrentCost Envir support

Posted: Sunday 16 November 2014 15:54
by steef84
I've currently integrated the EnviR in Domoticz by installing MeasureIt on the same PI as Domoticz. I've installed the MeasureIt PI image (wheezy) and compiled Domoticz alongside from source. MeasureIt uploads the data to pvoutput, and Domoticz on its turn will import the data from pvoutput. Its working fine for a week now, but im trying to finetune some things.

The data currently updates every 5 min. I like to get the current used energy to be updated more regular.

When running MeasureIt responses like
  • [{"sensor":{"x":"0","sensor_id":"0","sensor_title":"Sensor 0","sensor_clamp":"0","position_id":"1","position_time":"2014-10-05 14:39:56","position_description":"start position","position_sensor":"0","measure_history":"365","measure_currency":"Euro","measure_sensor":"0","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"0","measure_type":"0","measure_pvoutput_id":"33187","measure_pvoutput_api":"","measure_scale_factor":"1.00","measure_lower_limit":"0","positions":{"1":{"position":"1","time":"2014-10-05 14:39:56","description":"start position"}}},"tmpr":"19.7","watt":"134","daily":"3.705 Kwh
    0.8","hourly":"0.158 Kwh
    0.03","weekly":"24.252 Kwh
    5.27","monthly":"30.544 Kwh
    6.64"}
The significant data is displayed bold. The data behind Kwh is the costs in euros.I know that its possible to to add this data to a dummy switch with json, only I dont have a clue how. Ive been reading http://domoticz.com/forum/viewtopic.php ... son#p25739 and many Wiki's, but I just don't see it.

Are there any bright eyes who can help me to import this data into Domoticz without pvoutput.

Re: [154] - CurrentCost Envir support

Posted: Monday 24 November 2014 13:48
by markk
Hi. Just wondered if anyone had made any progress with this? I notice that gas monitoring is now possible with these which is interesting. I might even get one and use PVOutput to retrieve the data into Domoticz.

Re: [154] - CurrentCost Envir support

Posted: Thursday 25 December 2014 22:42
by Rene
Hello everyone, A friend of my has the same device. It should not be hard to program a driver in LUA..So I will keep you posted on the progress..

Re: [154] - CurrentCost Envir support

Posted: Tuesday 30 December 2014 19:59
by steef84
Looking forward to see your lua script!

Re: [154] - CurrentCost Envir support

Posted: Sunday 04 January 2015 19:54
by Rene
steef84 wrote:Looking forward to see your lua script!
I tried the Lua script but I failed in opening the com port, so then I made something REALLY simple in Python. I am running this script on my Beagle Bone Back with Domoticz installed.

All that needs to be done is to create two Virtual Sensors in Hardware. One Temperature and one Electric (Instant+Counter).
Then get the Idx numbers out of the Devices tab and replace the numbers in the script together with the IP address.
Then run the script in the background with python <filename.py> &

The pyserial driver might not be installed enter the

Code: Select all

sudo apt-get update
sudo apt-get install python-serial
sudo apt-get install python-requests
to install on Debian or Ubuntu

Good luck. P.S. this is a very basic script that will only read one sensor and is far from perfect..

Code: Select all

#!/usr/bin/env python
#
#	Script to parse Current Cost data to Domoticz
#   
#		(C)reated 2014 by Rtm-soft
#

import serial
import os
import requests

#Constants

COMPORT = "/dev/ttyUSB22"
COMPORT_BAUD = 57600
DOMOTICZ_URL = "http://192.168.9.31:8080"	#http://<username:password@>domoticz-ip<:port>
TEMP_IDX = "94"					#Domoticz index Dummy THR128/138, THC138
METER_IDX = "53"				#Domoticz index Dummy Energy meter CM119/CM160

#Variables

kwh	= "0"		#Last Months total
#watts	= "0"		#Current watts
#tmpr	= "0"		#Current temperature

# connect to the CurrentCost meter

ser = None
try:
    ser = serial.Serial(port=COMPORT, baudrate=COMPORT_BAUD, timeout=30)
except serial.SerialException, msg:
    print("Failed to connect to CurrentCost meter :: " + str(msg))
    exit(1)


print ("Connected to "+COMPORT+" at "+str(COMPORT_BAUD)+" Baud!")


while True:

	line = ser.readline()	# read a line of XML from the CurrentCost meter
	#print line
	if line.find("hist")==-1 : 		#No history packet, read temperature and current watts
		pos = line.find("tmpr") 	#Find current temperature
		if  pos !=-1 :
			tmpr = line[pos+5:pos+9]
			url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+TEMP_IDX+"&nvalue=0&svalue="+tmpr
			requests.get(url)
		pos = line.find("watts")	#Find current watts
		if  pos !=-1 :
			watts = line[pos+6:pos+11]
	else :
		pos = line.find("sensor>0<")		#Looking for last days total for sensor 0
		if  pos !=-1 :
			pos2 = line.find("d001",pos)	#Find lastsday total only for sensor 0
			if pos2 !=-1 :
				tmpkwh = line[pos2+5:pos2+11] #Use temp value so that it can be modified
				kwh = tmpkwh.replace(".","")	#Remove dot out of string. Domoticz wants Wh
	url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+METER_IDX+"&nvalue=0&svalue="+watts+";"+kwh
	#print url
	requests.get(url) 
exit(0)

Re: [154] - CurrentCost Envir support

Posted: Sunday 25 January 2015 12:33
by steef84
hmmm, never saw this reply.... :(

Thanks for this script!! Im trying it on my pi, however running into troubles.

Code: Select all

pi@raspberrypi ~/scripts $ python envir.py
Traceback (most recent call last):
  File "envir.py", line 10, in <module>
    import requests
ImportError: No module named requests
I've installed pyserial driver.

Re: [154] - CurrentCost Envir support

Posted: Tuesday 27 January 2015 10:16
by tommysharp
steef84 wrote:Thanks for this script!! Im trying it on my pi, however running into troubles.
I am a fellow newbie trying to get Domoticz on my Raspberry Pi talking to my CurrentCost meter using USB. And openly admit I have no real clue what I'm doing when it comes to Linux etc etc...

To get past the error you are getting I did some searching on Google and figured out I had to SSH to the Raspberry Pi and then ran...

sudo apt-get update
sudo apt-get install python-requests

This got me past that error, but now I get.....

Failed to connect to CurrentCost meter :: could not open port /dev/ttyUSB22: [Errno 2] No such file or directory: '/dev/ttyUSB22'

Any tips for a complete novice?

UPDATE : Okay I got a little further... Running the following command gave me a list of a whole bunch of devices with one at the bottom that look very similar...

ls -l /dev/tty*

I changed the python script and updated this part...

COMPORT = "/dev/ttyUSB0"

Now at least it runs but I still get an error...

File "/home/pi/domoticz/scripts/CurrentCost.py", line 36, in <module>
print ("Connected to "+COMPORT+" at "+COMPORT_BAUD+" Baud!")
TypeError: cannot concatenate 'str' and 'int' objects

UPDATE : Okay a bit further... Changed that line in the script so that it converts the COMPORT_BAUD to a string...

print ("Connected to "+COMPORT+" at "+str(COMPORT_BAUD)+" Baud!")

This seems to work and now when I run the python script I get...

Connected to /dev/ttyUSB0 at 57600 Baud!

But not much else happens, nothing in Domoticz gets updated... Any ideas?

Re: [154] - CurrentCost Envir support

Posted: Wednesday 28 January 2015 1:29
by Rene
I think you are almost there.
Did you create the 2 devices needed in Domoticz? They are not created on their own. And when you create them you will get a new IDX value, you will have to replace the 2 IDX values in the script with yours..Then it should update..Keep checking back here I might modify the script to create its own device, but at this moment I am trying to get my Open Energy Monitor to work first..

Rene

Re: [154] - CurrentCost Envir support

Posted: Wednesday 28 January 2015 12:23
by hendrik6073
hi,

i trying to get this to work. running the script i get the output:

Code: Select all

root@raspberrypi:/scripts# python domo_measure.py
Connected to /dev/ttyUSB0 at 57600 Baud!
than nothing, looks like the script hangs, when i beak out of the script i get

Code: Select all

^CTraceback (most recent call last):
  File "domo_measure.py", line 41, in <module>
    line = ser.readline()   # read a line of XML from the CurrentCost meter
  File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 442, in read
    ready,_,_ = select.select([self.fd],[],[], self._timeout)
KeyboardInterrupt
i changed the value watts to watt because it is called the way in the output (http://192.168.2.27/php/measureit_funct ... mary_start):

Code: Select all

{"0":{"sensor":{"x":"","sensor_id":"0","sensor_title":"optisense","sensor_clamp":"0","position_id":"2","position_time":"2013-10-14 18:36:12","position_description":"optisense","position_sensor":"0","measure_history":"365","measure_currency":"Euro","measure_sensor":"0","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"2","measure_type":"0","measure_pvoutput_id":"0","measure_pvoutput_api":"","positions":{"2":{"position":"2","time":"2013-10-14 18:36:12","description":"optisense"}}},"tmpr":"20.8","watt":"104","daily":"9.858 Kwh
0","hourly":"0.432 Kwh
0","weekly":"72.135 Kwh
0","monthly":"368.029 Kwh
0"},"1":{"sensor":{"x":"","sensor_id":"1","sensor_title":"stroomtangen","sensor_clamp":"0","position_id":"4","position_time":"2013-10-14 19:39:49","position_description":"stroomtangen","position_sensor":"1","measure_history":"365","measure_currency":"Euro","measure_sensor":"1","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"2","measure_type":"0","measure_pvoutput_id":"0","measure_pvoutput_api":"","positions":{"4":{"position":"4","time":"2013-10-14 19:39:49","description":"stroomtangen"}}},"tmpr":"20.8","watt":"455","daily":"12.854 Kwh
0","hourly":"0.599 Kwh
0","weekly":"87.251 Kwh
0","monthly":"403.289 Kwh
0"},"11":{"sensor":{"x":"","sensor_id":"11","sensor_title":"fase1","sensor_clamp":"0","position_id":"3","position_time":"2013-10-14 19:38:40","position_description":"fase1","position_sensor":"11","measure_history":"365","measure_currency":"Euro","measure_sensor":"11","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"2","measure_type":"0","measure_pvoutput_id":"0","measure_pvoutput_api":"","positions":{"3":{"position":"3","time":"2013-10-14 19:38:40","description":"fase1"}}},"tmpr":"20.8","watt":"174","daily":"3.957 Kwh
0","hourly":"0.176 Kwh
0","weekly":"27.799 Kwh
0","monthly":"137.913 Kwh
0"},"21":{"sensor":{"x":"","sensor_id":"21","sensor_title":"fase2","sensor_clamp":"0","position_id":"6","position_time":"2013-10-14 19:41:13","position_description":"fase2","position_sensor":"21","measure_history":"365","measure_currency":"Euro","measure_sensor":"21","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"2","measure_type":"0","measure_pvoutput_id":"0","measure_pvoutput_api":"","positions":{"6":{"position":"6","time":"2013-10-14 19:41:13","description":"fase2"}}},"tmpr":"20.8","watt":"75","daily":"2.333 Kwh
0","hourly":"0.17 Kwh
0","weekly":"16.929 Kwh
0","monthly":"74.725 Kwh
0"},"31":{"sensor":{"x":"","sensor_id":"31","sensor_title":"fase3","sensor_clamp":"0","position_id":"7","position_time":"2013-10-14 19:41:42","position_description":"fase3","position_sensor":"31","measure_history":"365","measure_currency":"Euro","measure_sensor":"31","measure_range":"","measure_timeframe":"0","measure_timezone":"GMT0","measure_timezone_diff":"2","measure_type":"0","measure_pvoutput_id":"0","measure_pvoutput_api":"","positions":{"7":{"position":"7","time":"2013-10-14 19:41:42","description":"fase3"}}},"tmpr":"20.8","watt":"206","daily":"6.604 Kwh
0","hourly":"0.264 Kwh
0","weekly":"42.87 Kwh
0","monthly":"192.297 Kwh
0"}}
i see no values in my virtual domoticz devices, i added the idx value.

could this script also be used from a remote raspbeyry bij connecting the URL ?

thanks

Re: [154] - CurrentCost Envir support

Posted: Wednesday 28 January 2015 21:17
by tommysharp
I kept at this a bit more but decided to try and do it on my windows server rather than the raspberry pi. Only because I'm more comfortable with windows...

I Installed Python 3.4 on my windows 2008 server. I had to use PIP.exe to install the "serial" and "requests" modules.

I actually have a 1st Gen CurrentCost device and by making the script print (line) I was able to see the raw XML it was trying to decode, the 1st Gen device is a bit different so I had to tweak to code.

After a bit of this and that I actually got it working :-)

This is the script I'm now currently using on the Windows box, and I'm pretty sure I could probably get it up and running on the Raspberry Pi too... I did put quite a few "print" commands in there to help me work out what was going on at each stage, you're welcome to take them out.

Code: Select all

#!/usr/bin/env python
#
#   Script to parse Current Cost data to Domoticz
#   
#      (C)reated 2014 by Rtm-soft
#

import serial
import os
import requests

#Constants

COMPORT = "COM4"
COMPORT_BAUD = 9600
DOMOTICZ_URL = "http://192.168.1.95:8080"   #http://<username:password@>domoticz-ip<:port>
TEMP_IDX = "37"               #Domoticz index Dummy THR128/138, THC138
METER_IDX = "36"            #Domoticz index Dummy Energy meter CM119/CM160

#Variables

kwh2   = "0"      #Yesterdays total
#watts   = "0"      #Current watts
#tmpr   = "0"      #Current temperature

# connect to the CurrentCost meter

ser = None
try:
    ser = serial.Serial(port=COMPORT, baudrate=COMPORT_BAUD, timeout=30)
except serial.SerialException:#, msg:
    print("Failed to connect to CurrentCost meter :: " + str(msg))
    exit(1)


print ("Connected to "+COMPORT+" at "+str(COMPORT_BAUD)+" Baud!")
print (ser.name)

print ("Trying to read lines now....")

while True:
   line = str(ser.readline())   # read a line of XML from the CurrentCost meter
   #print (line) # Uncomment out this row if you want to see the raw XML
   if line.find("hist")==-1 :       #No history packet, read current watts
      print ("Reading a normal line....")
      pos = line.find("<ch1><watts>")   #Find current watts for Channel 1
      if  pos !=-1 :
         watts = line[pos+12:pos+17]
         url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+METER_IDX+"&nvalue=0&svalue="+watts+";"+kwh2
         print (str(url))
         requests.get(url)
   else : # history packet, read temperature, current watts and kWh
      print ("Reading a history line....")
      pos = line.find("tmpr")    #Find current temperature
      if  pos !=-1 :
         tmpr = line[pos+5:pos+9]
         url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+TEMP_IDX+"&nvalue=0&svalue="+tmpr
         print (str(url))
         requests.get(url)
      pos = line.find("<ch1><watts>")   #Find current watts
      if  pos !=-1 :
         watts = str(int(float(line[pos+12:pos+17])))
         pos = line.find("<days><d01>")      #Looking for last days total kwh
         if  pos !=-1 :
            kwh = line[pos+11:pos+15]
            kwh2 = str(int(float(kwh)) * 1000) # Domoticz seems to divide the value by 1000 so we'll multiply it by 1000
         url= DOMOTICZ_URL+"/json.htm?type=command&param=udevice&idx="+METER_IDX+"&nvalue=0&svalue="+watts+";"+kwh2
         print (str(url))
         requests.get(url) 
exit(0)

Re: [154] - CurrentCost Envir support

Posted: Thursday 29 January 2015 21:26
by hendrik6073
thanks, this look good !, only have to split the code because i have more than 1 sensors, so have to select one sensor, get the value and go to the next.....

Code: Select all

http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00498;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00127;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00498;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00137;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00498;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00138;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00498;0
Reading a normal line....
http://192.168.2.27:8080/json.htm?type=command&param=udevice&idx=7&nvalue=0&svalue=00128;0
Reading a normal line....
Reading a normal line....

Re: [154] - CurrentCost Envir support

Posted: Saturday 31 January 2015 19:32
by steef84
Good. Got this running now a few hours. Thanks for all the tips!

Re: [154] - CurrentCost Envir support

Posted: Monday 09 February 2015 23:38
by JC38
I've got also a CC 128 managing 4 devices.
With a Perl script, I've got the watt values, but the Kwh values are not updated because I only read the xml live values not the summarized ones.
Also, the virtual device is not in the good type, i would like to have a type = Usage, Electric but it's not possible to create a virtual device like this. The only solutions are Electrical (instant + counter) or Counter.
I have chosen the Electrical but only the first graph is ok.
So, I would like to know if you get better results than I, and if your solution is also working with multiple devices behind the CC128 Appliance.

Re: [154] - CurrentCost Envir support

Posted: Friday 06 March 2015 20:13
by Rene
JC38 wrote:I've got also a CC 128 managing 4 devices.
With a Perl script, I've got the watt values, but the Kwh values are not updated because I only read the xml live values not the summarized ones.
Also, the virtual device is not in the good type, i would like to have a type = Usage, Electric but it's not possible to create a virtual device like this. The only solutions are Electrical (instant + counter) or Counter.
I have chosen the Electrical but only the first graph is ok.
So, I would like to know if you get better results than I, and if your solution is also working with multiple devices behind the CC128 Appliance.
No it does not deal with multiple devices. Also does not keep track of kwh history so far. But python is a easy and powerful scripting language . It is easy to modify and does not need compiling. Also I read someone else that had multiple devices ln this forum, maybe he can post his modified code.

Cheers Rene

Re: [154] - CurrentCost Envir support

Posted: Monday 27 April 2015 4:11
by asjmcguire
For info - this is my script.

Code: Select all

#!/usr/bin/perl -w

# Reads data from a Current Cost device via serial port.

use strict;
use Device::SerialPort qw( :PARAM :STAT 0.07 );

my $PORT = "/dev/electric";
my $dom_server = "192.168.2.12";
my $dom_port = "8080";
my $idx = 607;

my $ob = Device::SerialPort->new($PORT);
$ob->baudrate(57600);
#$ob->parity("none");
#$ob->databits(8);
#$ob->stopbits(1);
$ob->write_settings;

my $prev_counter = 0;
my $new_counter = 0;
my $p1 = 0;
my $p2 = 0;
my $p3 = 0;
my $etotal = 0;
my $temp = 0;

 my $STALL_DEFAULT=35; # how many seconds to wait for new input

 my $timeout=$STALL_DEFAULT;

 $ob->read_char_time(0);     # don't wait for each character
 $ob->read_const_time(1000); # 1 second per unfulfilled "read" call

 my $chars=0;
 my $buffer="";
 while ($timeout>0) {
        my ($count,$saw)=$ob->read(10); # will read _up to_ 255 chars
        if ($count > 0) {
                $chars+=$count;
                $buffer.=$saw;
                print $saw;

                if ($buffer =~ m!<tmpr> *([\-\d.]+)</tmpr>.*<ch1><watts>0*(\d+)</watts></ch1><ch2><watts>0*(\d+)</watts></ch2><ch3><watts>0*(\d+)</watts></ch3>!) {
        $temp = $1;
        $p1 = $2;
        $p2 = $3;
        $p3 = $4;
        $etotal = $p1 + $p2 + $p3;
        last;
        }
        }

else {
                $timeout--;
        }
 }

 if ($timeout==0) {
        print $buffer ."\n";
        die "Waited $STALL_DEFAULT seconds and never saw what I wanted\n";
 }

open (my $cfh, '<', "/home/a-jones/electric_counter.txt");
while (my $cline = <$cfh>) {
chomp $cline;
$prev_counter = $cline;
}
close $cfh;

print "Instant Reading: \n";
print "Phase1: $p1, Phase2: $p2, Phase3: $p3\n";
print "Total: $etotal\n";
print "\nPrevious Counter: $prev_counter KWh\n";
my $kwh = ($etotal / 60);
print "KWh: $kwh\n";
$new_counter = $prev_counter + $kwh;
print "New Counter: $new_counter\n";
print "----------------------\n";

open (my $efh, '>', "/home/a-jones/electric.txt");
print $efh "$p1,$p2,$p3,$etotal,$temp";
close $efh;

open (my $ncfh, '>', "/home/a-jones/electric_counter.txt");
print $ncfh "$new_counter";
close $ncfh;

my $dom_url = "http://$dom_server:$dom_port/json.htm?type=command&param=udevice&idx=$idx&nvalue=0&svalue=$etotal;$new_counter";

use LWP::Simple;
my $content = get $dom_url;
die "Couldn't get $dom_url" unless defined $content;

print "Return from Domoticz: \n";
print "$content";
This script figures out kWh since Domoticz needs / needed this value when this script was created.