Page 1 of 1

Kamstrup Multical 402

Posted: Saturday 17 March 2018 16:38
by RvdM
Hi all,

I have a Kamstrup Multical 402 and wanted to monitor the Heat Energy in domoticz.
To accomplish this i've found a script, posted on this forum, but I can't get it to work fully.
When I execute the script several parameter values are defined as "None None".

Code: Select all

=======================================================================================
Kamstrup M402 serial optical data ontvangen op: 2018-03-17 16:27:24
Meter fabrikant/type: Kamstrup M402
---------------------------------------------------------------------------------------
MaxPower_Y                21.1 kW
MinPowerDate_Y            None None
MinPower_Y                0.0 kW
Volume                    None None
Temp1                     57.9 C
Temp1xm3                  None None
Flow                      14.0 l/h
MaxFlow_M                 None None
MinFlowDate_M             180301.0 yy:mm:dd
MinFlow_M                 None None
MaxPowerDate_M            180307.0 yy:mm:dd
MaxPower_M                None None
MinPowerDate_M            180301.0 yy:mm:dd
MinPower_M                None None
AvgTemp1_Y                74.0 C
AvgTemp2_Y                None None
AvgTemp1_M                73.0 C
AvgTemp2_M                None None
Temp2                     56.21 C
Tempdiff                  None None
Power                     0.0 kW
Heat Energy (E1)          None None
HourCounter               44310.0 h
Temp2xm3                  None None
Infoevent                 0.0 
MaxFlowDate_M             None None
MaxFlowDate_Y             180220.0 yy:mm:dd
MaxFlow_Y                 None None
MinFlowDate_Y             180115.0 yy:mm:dd
MinFlow_Y                 None None
MaxPowerDate_Y            180220.0 yy:mm:dd
---------------------------------------------------------------------------------------
Einde Dataontvangst: 2018-03-17 16:27:24
=======================================================================================
However, when I limit the list of parameters to only Heat Energy and some others the value: None None is replaced by the actual value.
It seems like some kind of limit (array to small?) but the code (reading the IR information) for me is to complex to understand/debug.

Code: Select all

kamstrup_402_var = {                # Decimal Number in Command
 0x003C: "Heat Energy (E1)",        #60
 0x0056: "Temp 1",                  #86
 0x0057: "Temp 2",        	    #87
 0x004A: "Flow",                    #74
 0x0044: "Volume",                  #68
}

Code: Select all

=======================================================================================
Kamstrup Multical 402 serial optical data received: 2018-03-17 16:09:26
Meter vendor/type: Kamstrup M402
---------------------------------------------------------------------------------------
Volume                    1303.9 m3
Flow                      None None
Heat Energy (E1)          185.4 Gj
Temp 1                    57.61 C
Temp 2                    None None
---------------------------------------------------------------------------------------
End data received: 2018-03-17 16:09:26
=======================================================================================
Does anyone else have an idea why this happens?

Re: Kamstrup Multical 402

Posted: Saturday 17 March 2018 19:50
by freijn
Ronald,

Looking at your output the following happens

1 is on then the next 1 is none

On the last entry I still see none values. So size of the array is not the issue. ( and Python is doing that all for you as well :-) )

Still trying to find a clue..

What is your call to the script? Are you trying the get the values 1 by 1 so for each value you run the script again?
Is that my corect understanding?

Re: Kamstrup Multical 402

Posted: Saturday 17 March 2018 20:41
by RvdM
Just updated my own script. It can be downloaded here: https://github.com/RvMp/multical402-4-domoticz

My goal is to be able to update multiple virtual devices in one run (want to prevent a battery replacement each week :))

Output of my script confirms your theory that one shows value and the other shows None (cycle repeats).

Code: Select all

# `which python3` /usr/local/sbin/multical402-4-domoticz/multical402-4-domoticz.py /dev/ttyUSB2 324:60:2:323,325:60:2:323,325:60:2:323,326:60:2:323,327:60:2:323,322:60:1:323,323:60:0
=======================================================================================
Kamstrup Multical 402 serial optical data received: 2018-03-17 21:34:58
Meter vendor/type: Kamstrup M402
---------------------------------------------------------------------------------------
Volume                    1304.73 m3
Flow                      None None
Heat Energy (E1)          185.56 Gj
+ F2 Submit value 2.57 to 'Heat usage (monthly)' (idx: 324)
+ F2 Submit value 0.28 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 0.28 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 0.92 to 'Heat usage (weekly)' (idx: 326)
+ F2 Submit value 12.84 to 'Heat usage (yearly)' (idx: 327)
+ F1 Submit value 0.0 to 'Heat usage (20 min)' (idx: 322)
+ F0 Submit value 185.56 to 'Heat usage (total)' (idx: 323)
Temp 1                    65.75 C
Temp 2                    None None
---------------------------------------------------------------------------------------
End data received: 2018-03-17 21:34:58
=======================================================================================

Re: Kamstrup Multical 402

Posted: Sunday 18 March 2018 15:40
by RvdM
Good news. I've managed to solve the problem by setting bytesize, parity and stopbits.

In my version of the script this was not set so i'm guessing bytesize, parity and/or stopbits were set by another script I executed a couple of days ago.

Code: Select all

        self.ser = serial.Serial(
            port = serial_port,
            baudrate = 2400,
            timeout = 20,
            bytesize = serial.EIGHTBITS,
            parity = serial.PARITY_NONE,
            stopbits = serial.STOPBITS_TWO)
#            xonxoff = 0,
#            rtscts = 0)
#           timeout = 20
https://github.com/RvMp/multical402-4-d ... 34d7d14672

Now this is the output of the script

Code: Select all

=======================================================================================
Kamstrup Multical 402 serial optical data received: 2018-03-18 20:15:45
Meter vendor/type: Kamstrup M402
---------------------------------------------------------------------------------------
MaxPower_Y                21.1 kW
MinPowerDate_Y            180101.0 yy:mm:dd
MinPower_Y                0.0 kW
Volume                    1305.82 m3
Temp1                     78.46000000000001 C
+ F0 Submit value 78.46000000000001 to 'Heat Temp1' (idx: 329)
Temp1xm3                  90387.0 m3xC
Flow                      157.0 l/h
+ F0 Submit value 157.0 to 'Heat Flow' (idx: 332)
MaxFlow_M                 334.0 l/h
MinFlowDate_M             180301.0 yy:mm:dd
MinFlow_M                 1.0 l/h
MaxPowerDate_M            180307.0 yy:mm:dd
MaxPower_M                18.5 kW
MinPowerDate_M            180301.0 yy:mm:dd
MinPower_M                0.0 kW
AvgTemp1_Y                74.0 C
AvgTemp2_Y                31.0 C
AvgTemp1_M                73.0 C
AvgTemp2_M                31.0 C
Temp2                     32.59 C
+ F0 Submit value 32.59 to 'Heat Temp2' (idx: 330)
Tempdiff                  45.87 K
+ F0 Submit value 45.87 to 'Heat TempDiff' (idx: 331)
Power                     8.200000000000001 kW
+ F0 Submit value 8.200000000000001 to 'Heat Power' (idx: 328)
Heat Energy (E1)          185.75 Gj
+ F2 Submit value 2.76 to 'Heat usage (monthly)' (idx: 324)
+ F2 Submit value 0.38 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 0.38 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 1.11 to 'Heat usage (weekly)' (idx: 326)
+ F2 Submit value 13.03 to 'Heat usage (yearly)' (idx: 327)
+ F1 Submit value 0.0 to 'Heat usage (20 min)' (idx: 322)
+ F0 Submit value 185.75 to 'Heat usage (total)' (idx: 323)
HourCounter               44338.0 h
Temp2xm3                  44887.0 m3xC
Infoevent                 0.0 
MaxFlowDate_M             180307.0 yy:mm:dd
MaxFlowDate_Y             180220.0 yy:mm:dd
MaxFlow_Y                 378.0 l/h
MinFlowDate_Y             180115.0 yy:mm:dd
MinFlow_Y                 0.0 l/h
MaxPowerDate_Y            180220.0 yy:mm:dd
---------------------------------------------------------------------------------------
End data received: 2018-03-18 20:15:45
=======================================================================================
Now it would be great if I could submit the usage via API to a "P1 Smart Meter" like Device in Domoticz instead of all those seperate virtual devices

Re: Kamstrup Multical 402

Posted: Monday 19 March 2018 9:37
by Chakkie
Hi guys

Could you tell me which optical USB reader I have to use to read the data from the Kamstrup? Can you provide me the link as well? I have been trying to build one my own using adruino but without any luck.

The unit for my City heating is Kamstrup 401 and my Domoticz is running on the RPI 2

Thanks

Re: Kamstrup Multical 402

Posted: Monday 19 March 2018 14:16
by RvdM
Could you tell me which optical USB reader I have to use to read the data from the Kamstrup? Can you provide me the link as well? I have been trying to build one my own using adruino but without any luck.
It depends on the IEC standard the Multical 401 is using.
I'm using the Optical Probe IEC 1107 IEC 61107 and if I recall correctly it uses the same standard as the 402

Re: Kamstrup Multical 402

Posted: Monday 19 March 2018 14:59
by Chakkie
RvdM wrote: Monday 19 March 2018 14:16
Could you tell me which optical USB reader I have to use to read the data from the Kamstrup? Can you provide me the link as well? I have been trying to build one my own using adruino but without any luck.
It depends on the IEC standard the Multical 401 is using.
I'm using the Optical Probe IEC 1107 IEC 61107 and if I recall correctly it uses the same standard as the 402
I have just googled it but I could not find a shop which sell the cable. Do you happen to know where I can purchase this optical cable. Thanks

Re: Kamstrup Multical 402

Posted: Tuesday 20 March 2018 1:18
by RvdM

Re: Kamstrup Multical 402

Posted: Tuesday 25 September 2018 19:50
by Dynamic
RvdM wrote: Sunday 18 March 2018 15:40 Good news. I've managed to solve the problem by setting bytesize, parity and stopbits.

In my version of the script this was not set so i'm guessing bytesize, parity and/or stopbits were set by another script I executed a couple of days ago.

Code: Select all

        self.ser = serial.Serial(
            port = serial_port,
            baudrate = 2400,
            timeout = 20,
            bytesize = serial.EIGHTBITS,
            parity = serial.PARITY_NONE,
            stopbits = serial.STOPBITS_TWO)
#            xonxoff = 0,
#            rtscts = 0)
#           timeout = 20
https://github.com/RvMp/multical402-4-d ... 34d7d14672

Now this is the output of the script

Code: Select all

=======================================================================================
Kamstrup Multical 402 serial optical data received: 2018-03-18 20:15:45
Meter vendor/type: Kamstrup M402
---------------------------------------------------------------------------------------
MaxPower_Y                21.1 kW
MinPowerDate_Y            180101.0 yy:mm:dd
MinPower_Y                0.0 kW
Volume                    1305.82 m3
Temp1                     78.46000000000001 C
+ F0 Submit value 78.46000000000001 to 'Heat Temp1' (idx: 329)
Temp1xm3                  90387.0 m3xC
Flow                      157.0 l/h
+ F0 Submit value 157.0 to 'Heat Flow' (idx: 332)
MaxFlow_M                 334.0 l/h
MinFlowDate_M             180301.0 yy:mm:dd
MinFlow_M                 1.0 l/h
MaxPowerDate_M            180307.0 yy:mm:dd
MaxPower_M                18.5 kW
MinPowerDate_M            180301.0 yy:mm:dd
MinPower_M                0.0 kW
AvgTemp1_Y                74.0 C
AvgTemp2_Y                31.0 C
AvgTemp1_M                73.0 C
AvgTemp2_M                31.0 C
Temp2                     32.59 C
+ F0 Submit value 32.59 to 'Heat Temp2' (idx: 330)
Tempdiff                  45.87 K
+ F0 Submit value 45.87 to 'Heat TempDiff' (idx: 331)
Power                     8.200000000000001 kW
+ F0 Submit value 8.200000000000001 to 'Heat Power' (idx: 328)
Heat Energy (E1)          185.75 Gj
+ F2 Submit value 2.76 to 'Heat usage (monthly)' (idx: 324)
+ F2 Submit value 0.38 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 0.38 to 'Heat usage (daily)' (idx: 325)
+ F2 Submit value 1.11 to 'Heat usage (weekly)' (idx: 326)
+ F2 Submit value 13.03 to 'Heat usage (yearly)' (idx: 327)
+ F1 Submit value 0.0 to 'Heat usage (20 min)' (idx: 322)
+ F0 Submit value 185.75 to 'Heat usage (total)' (idx: 323)
HourCounter               44338.0 h
Temp2xm3                  44887.0 m3xC
Infoevent                 0.0 
MaxFlowDate_M             180307.0 yy:mm:dd
MaxFlowDate_Y             180220.0 yy:mm:dd
MaxFlow_Y                 378.0 l/h
MinFlowDate_Y             180115.0 yy:mm:dd
MinFlow_Y                 0.0 l/h
MaxPowerDate_Y            180220.0 yy:mm:dd
---------------------------------------------------------------------------------------
End data received: 2018-03-18 20:15:45
=======================================================================================
Now it would be great if I could submit the usage via API to a "P1 Smart Meter" like Device in Domoticz instead of all those seperate virtual devices
Because the energy company changed my meter, i had to replace my script. I used your script, but all values return als 'none'. Is there a way to check if the meter responds at all?

Re: Kamstrup Multical 402

Posted: Thursday 27 September 2018 21:05
by freijn
Dynamic

There is a windows programm. if connected to the sensor you make several tests and detect if the kamstrup is responding.

PB me your emial adres if you are interested

Frank

Re: Kamstrup Multical 402

Posted: Sunday 03 February 2019 15:17
by jonathan12
Hi All, I amd trying to get this nice script working with my city heating.

I bought the sensor from: https://wiki.hal9k.dk/projects/kamstrup

I created 3 sensors in Domoticz: (I am not sure if this is Right)
Stadsverwarming1 General Custom Sensor 0 GJ IDX 42
Stadsverwarming2 General Custom Sensor 0 GJ IDX 43
Stadsverwarming3 General Custom Sensor 0 GJ IDX 44

Change the script with the IP of Domoticz and port 8080.
domoip = "192.168.1.250"
domoport = "8080"
debug = 1

I installed Python 3 because it was not working with the defaul version of Python.
Installed Pyserial

I run the script with this command:
python3 multical402-4-domoticz.py /dev/ttyUSB1 42:60:2:44,43:60:1:44,44:60:0

Output:

pi@raspberrypi:~ $ python3 multical402-4-domoticz.py /dev/ttyUSB1 42:60:2:44,43:60:1:44,44:60:0
Parameter specified:
+ 42:60:2:44
+ 43:60:1:44
+ 44:60:0
=======================================================================================
Kamstrup Multical 402 serial optical data received: 2019-02-03 15:11:07
Meter vendor/type: Kamstrup M402
---------------------------------------------------------------------------------------
MaxPower_Y 17.5 kW
MinPowerDate_Y 190110.0 yy:mm:dd
MinPower_Y 0.2 kW
Volume 764.77 m3
Temp1 66.58 C
Temp1xm3 52239.0 m3xC
Flow 10.0 l/h
MaxFlow_M 336.0 l/h
MinFlowDate_M 190201.0 yy:mm:dd
MinFlow_M 21.0 l/h
MaxPowerDate_M 190201.0 yy:mm:dd
MaxPower_M 15.9 kW
MinPowerDate_M 190203.0 yy:mm:dd
MinPower_M 0.2 kW
AvgTemp1_Y 68.0 C
AvgTemp2_Y 40.0 C
AvgTemp1_M 69.0 C
AvgTemp2_M 37.0 C
Temp2 30.1 C
Tempdiff 36.480000000000004 K
Power 0.4 kW
Heat Energy (E1) 67.88 Gj
Traceback (most recent call last):
File "multical402-4-domoticz.py", line 340, in <module>
device_data = json.load(reader(urllib.request.urlopen(requestGet)))
File "/usr/lib/python3.5/urllib/request.py", line 163, in urlopen
return opener.open(url, data, timeout)
File "/usr/lib/python3.5/urllib/request.py", line 472, in open
response = meth(req, response)
File "/usr/lib/python3.5/urllib/request.py", line 582, in http_response
'http', request, response, code, msg, hdrs)
File "/usr/lib/python3.5/urllib/request.py", line 510, in error
return self._call_chain(*args)
File "/usr/lib/python3.5/urllib/request.py", line 444, in _call_chain
result = func(*args)
File "/usr/lib/python3.5/urllib/request.py", line 590, in http_error_default
raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 401: Unauthorized


The sensors in Domoticz are not updated. What is going wrong? :)

Re: Kamstrup Multical 402

Posted: Monday 25 February 2019 17:42
by jonathan12
The script is working!!! Joy joy!

The solution: At 127.0.0.1 to the settings in Domoticz: Local Networks (no username/password):

Re: Kamstrup Multical 402

Posted: Saturday 13 April 2019 15:54
by stefxx
Great script, thanks for that!

How often are you running the script? Should I worry about the battery? And what happens if the battery is drained?

Re: Kamstrup Multical 402

Posted: Wednesday 24 April 2019 21:53
by freijn
I run it every 10 min, and yes worried for the battery as well but some time ago ( when we had unwanted water) I asked the guy how they
feel about it. He was just interesed in my Graphs and results of for example the incoming water temp during the day :-)

Re: Kamstrup Multical 402

Posted: Wednesday 21 October 2020 17:23
by rikm44
How did you connect the sensor from hal9k to the pi?
As it does not have a usb chip, I thought it only worked via the arduino...

-edit-
Was thinking in the wrong direction... the PI also has a serial port on the GPIO pins.

Re: Kamstrup Multical 402

Posted: Friday 30 October 2020 21:43
by freijn
Hi Guys

Anybody got the Kamstrup 403 working?

Re: Kamstrup Multical 402

Posted: Sunday 15 November 2020 19:56
by SunnyBoy
freijn wrote: Friday 30 October 2020 21:43 Hi Guys

Anybody got the Kamstrup 403 working?
I got the Kamstrup Multical 403 working via USB (on an Intel NUC, should work on any machine), I documented my findings here. The TL;DR:
  • Get head from using the hal9k.dk reader head (archive) then solder together (22 EUR including shipping in EU, a bargain :) Best to pay with PayPal because banks apparently charge a ridiculous amount to transfer money across currencies.)
  • Connect to an FTDI USB TTL reader (e.g. at tinytronics)
  • Use either use this python script to read out the sensor and push to domoticz, or use my fork to push to InfluxDB or MQTT. Note that the original script seems to use more battery than required (see issue on GitHub repo)
Useful background info on the Kamstrump Multical meter sensor here (archive) and here (archive).