District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Moderator: leecollings

freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by freijn »

Remko, what type of meter are you using?
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

I use a multical 601
jonathan12
Posts: 25
Joined: Sunday 31 December 2017 17:30
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by jonathan12 »

Nice project. I will also try to get the data out of my heating box.

What kind of dummy sensor do we have to create?
waino
Posts: 2
Joined: Thursday 28 September 2017 15:18
Target OS: Linux
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by waino »

remko2000 wrote: Friday 09 November 2018 10:13 ah you are right. My mistake. When I use:
sudo python /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB1 60 21

I get:
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/pyKamstrup_single.py", line 243, in <module>
value = int(value * 1000)
TypeError: unsupported operand type(s) for *: 'NoneType' and 'int'
This just means that the multical box didn't answer at all ie. there is no active communication.
I currently have the same problem with my multical 602 box. No matter what I do, it stays silent.
Pressing the "play" button doesn't seem to work either. Still it looks like to me that the connector
plug "passes" all the recommended tests.
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

Almost a year later I tried it once. I've fresh install of my raspberry so I thought let's try.
I f I type:

Code: Select all

sudo python /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB1 60 23
Now I get no error but a value: 156290 (!!)

If I remove the sensor I get a error so it's receive something!

It really doesn't matter which last two digits I type in the command the value is always: 156290
Is this a good thing and what does this digit mean? What can I do next?
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

I also see that the value is rising; it's now: 156320.
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by freijn »

Hey Remko

please dump your complete script here and a dump of your output.

Can you find these lines in your output?

Code: Select all

#print ("=======================================================================================")
#print ("Kamstrup M402 serial optical data ontvangen op: %s" % heat_timestamp)
#print ("Meter fabrikant/type: Kamstrup M402")
#print ("---------------------------------------------------------------------------------------")

#for i in kamstrup_402_var:
#    x,u = foo.readvar(i)
#    print("%-25s" % kamstrup_402_var[i], x, u)

#print ("---------------------------------------------------------------------------------------")
#print ("Einde Dataontvangst: %s" % heat_timestamp)
#print ("=======================================================================================")
Remove the # from every line and check if you see more output when running the command from the cli.

I do not have this kampstup type, so can't test it locally...
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

My complete script is:

Code: Select all

                                                    
!/usr/bin/python
#
# ----------------------------------------------------------------------------
# "THE BEER-WARE LICENSE" (Revision 42):
# <[email protected]> wrote this file.  As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return.   Poul-Henning Kamp
# ----------------------------------------------------------------------------
#
# Modified for Domotics and single request.
#
# Usage: __file__ <ComPort> <KMP_Command_Decimal> <Domoticz_IDX>
#



from __future__ import print_function

# You need pySerial 
import serial
import math
import sys
import json
import urllib2


kamstrup_601_var = {
    0x003C: "Verwarming verbruik",
    0x0054: "Warm waterverbruik",
}

#######################################################################
# Units, provided by Erik Jensen

units = {
    0: '', 1: 'Wh', 2: 'kWh', 3: 'MWh', 4: 'GWh', 5: 'j', 6: 'kj', 7: 'Mj',
    8: 'Gj', 9: 'Cal', 10: 'kCal', 11: 'Mcal', 12: 'Gcal', 13: 'varh',
    14: 'kvarh', 15: 'Mvarh', 16: 'Gvarh', 17: 'VAh', 18: 'kVAh',
    19: 'MVAh', 20: 'GVAh', 21: 'kW', 22: 'kW', 23: 'MW', 24: 'GW',
    25: 'kvar', 26: 'kvar', 27: 'Mvar', 28: 'Gvar', 29: 'VA', 30: 'kVA',
    31: 'MVA', 32: 'GVA', 33: 'V', 34: 'A', 35: 'kV',36: 'kA', 37: 'C',
    38: 'K', 39: 'l', 40: 'm3', 41: 'l/h', 42: 'm3/h', 43: 'm3xC',
    44: 'ton', 45: 'ton/h', 46: 'h', 47: 'hh:mm:ss', 48: 'yy:mm:dd',
    49: 'yyyy:mm:dd', 50: 'mm:dd', 51: '', 52: 'bar', 53: 'RTC',
    54: 'ASCII', 55: 'm3 x 10', 56: 'ton x 10', 57: 'GJ x 10',
    58: 'minutes', 59: 'Bitfield', 60: 's', 61: 'ms', 62: 'days',
    63: 'RTC-Q', 64: 'Datetime'
}

#######################################################################
# Byte values which must be escaped before transmission
#

escapes = {
    0x06: True,
    0x0d: True,
    0x1b: True,
    0x40: True,
    0x80: True,
}

#######################################################################
# And here we go....
#
class kamstrup(object):

    def __init__(self, serial_port):
        self.debug_fd = open("/tmp/_kamstrup", "a")
        self.debug_fd.write("\n\nStart\n")
        self.debug_id = None

        self.ser = serial.Serial(
            port = serial_port,
            baudrate = 1200,
            timeout = 2.0)

    def debug(self, dir, b):
        for i in b:
            if dir != self.debug_id:
                if self.debug_id != None:
                    self.debug_fd.write("\n")
                self.debug_fd.write(dir + "\t")
                self.debug_id = dir
            self.debug_fd.write(" %02x " % i)
        self.debug_fd.flush()
        
    def debug_msg(self, msg):
        if self.debug_id != None:
            self.debug_fd.write("\n")
        self.debug_id = "Msg"
        self.debug_fd.write("Msg\t" + msg)
        self.debug_fd.flush()

    def wr(self, b):
        b = bytearray(b)
        self.debug("Wr", b);
        self.ser.write(b)

    def rd(self):
        a = self.ser.read(1)
        if len(a) == 0:
            self.debug_msg("Rx Timeout")
            return None
        b = bytearray(a)[0]
        self.debug("Rd", bytearray((b,)));
        return b

    def send(self, pfx, msg):
        b = bytearray(msg)
                b.append(0)
        b.append(0)
        c = crc_1021(b)
        b[-2] = c >> 8
        b[-1] = c & 0xff

        c = bytearray()
        c.append(pfx)
        for i in b:
            if i in escapes:
                c.append(0x1b)
                c.append(i ^ 0xff)
            else:
                c.append(i)
        c.append(0x0d)
        self.wr(c)

    def recv(self):
        b = bytearray()
        while True:
            d = self.rd()
            if d == None:
                return None
            if d == 0x40:
                b = bytearray()
            b.append(d)
            if d == 0x0d:
                break
        c = bytearray()
        i = 1;
        while i < len(b) - 1:
            if b[i] == 0x1b:
                v = b[i + 1] ^ 0xff
                if v not in escapes:
                    self.debug_msg(
                        "Missing Escape %02x" % v)
                c.append(v)
                i += 2
            else:
                c.append(b[i])
                i += 1
        if crc_1021(c):
            self.debug_msg("CRC error")
        return c[:-2]
def readvar(self, nbr):
        # I wouldn't be surprised if you can ask for more than
        # one variable at the time, given that the length is
        # encoded in the response.  Havn't tried.

        self.send(0x80, (0x3f, 0x10, 0x01, nbr >> 8, nbr & 0xff))

        b = self.recv()
        if b == None:
            return (None, None)

        if b[0] != 0x3f or b[1] != 0x10:
            return (None, None)

        if b[2] != nbr >> 8 or b[3] != nbr & 0xff:
            return (None, None)

        if b[4] in units:
            u = units[b[4]]
        else:
            u = None

        # Decode the mantissa
 x = 0
        for i in range(0,b[5]):
            x <<= 8
            x |= b[i + 7]

        # Decode the exponent
        i = b[6] & 0x3f
        if b[6] & 0x40:
            i = -i
        i = math.pow(10,i)
        if b[6] & 0x80:
            i = -i
        x *= i

        if False:
            # Debug print
            s = ""
            for i in b[:4]:
                s += " %02x" % i
            s += " |"
            for i in b[4:7]:
                s += " %02x" % i
            s += " |"
            for i in b[7:]:
                s += " %02x" % i

            print(s, "=", x, units[b[4]])

        return (x, u)
            

if __name__ == "__main__":

    import time

    comport = sys.argv[1]
    command = int( sys.argv[2], 0)
    index = int( sys.argv[3], 0)

    foo = kamstrup( comport )

    value,unit = foo.readvar( command )

    # We're sending an integer value to Domoticz, so with two digits, muliply by 100
    # Use Domiticz setting to devide by 100 again.
    value = int(value * 1000)

    print( int(value) )

If I type

Code: Select all

sudo python /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB1 60 24
in my (mac)terminal I get only back: 156320

If I type

Code: Select all

sudo python /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB1 84 25
in my terminal I get only back: 0

That's all the output I get in my terminal. Is there an other way to get more info in my terminal to see what commands do and how?
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

I'm a little further now. I get values back on the follow registers:
68- 1064400
60-156420
72-1039950
86-58770
87-36120
88-180000
89-22650
97-79048000
98-101000

Image

Which fails me to sent for example value 60 to domoticz. I switch the print rule in my pyKamstrup_single.pyscript for

Code: Select all

requestPost = urllib2.Request( "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + str(index) + "&svalue=" + str(value) )
    resultPost = json.load(urllib2.urlopen(requestPost))
I only change in this part only the IP tot the IP of my domoticzserver. Nothing else. I also made one rule in crontab:

Code: Select all

1 1 * * * /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB1 60 23
The IDX (23) and sensor-USB-adress are correct. In domoticz I made a dummyswitch(IDX23) of the type: gas. Is this correct?
Attachments
IMG_6592.jpg
IMG_6592.jpg (366 KiB) Viewed 3341 times
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by freijn »

First of all, did you allow a local login without a user_id and password?
Below the url's from my system to post the values into domoticz.

you must map the registers into the device idx to make this work.

requestPost=urllib.request.urlopen("http://192.168.1.155:8080/json.htm?type ... olume*100))
requestPost=urllib.request.urlopen("http://192.168.1.155:8080/json.htm?type ... ergy*1000))
requestPost=urllib.request.urlopen("http://192.168.1.155:8080/json.htm?type ... olume*100))
requestPost=urllib.request.urlopen("http://192.168.1.155:8080/json.htm?type ... ergy*1000))
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

you must map the registers into the device idx to make this work.
After some reading I guessing this has something to do with a bash script. Is this correct? So I made a simple bashscript:

Code: Select all

#!/bin/bash
#
# Simple script to batchrun the commands for the Kamstrup 601 Meter.
#
# Normal Command Usage: python3 kamstrup_single.py [USB device] [Decimal Command] [IDX]
#

# Heat Energy (verbruik) [60] [148]
python3 /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB0 60 28
So I've now a script called: pyKamstrup_single.py (I only changed the IP in the end)
I've a crontabtask: 1 1 * * * /home/pi/domoticz/scripts/pyKamstrup_single.py /dev/ttyUSB0 60 28
And I've a bash script called: kamstrup.sh (made it executable)

If I type: ' sh kamstrup.sh' in my terminal I get the follow error:
Traceback (most recent call last):
File "/home/pi/domoticz/scripts/pyKamstrup_single.py", line 20, in <module>
import serial
ModuleNotFoundError: No module named 'serial'
What can be the problem?

I've installed pyserial 3.4-4.
My domoticzlog says it's use Python version 3.7.3.
Strange thing is if I type ' python --version' in my terminal it says I've version Python 2.7.16.
remko2000
Posts: 165
Joined: Thursday 28 December 2017 14:38
Target OS: Raspberry Pi / ODroid
Domoticz version:
Location: Broek op Langedijk
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by remko2000 »

Finally I get it work. Some mistakes in copy this into my script

Code: Select all

requestPost = urllib2.Request( "http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + str(index) + "&svalue=" + str(value) )
    resultPost = json.load(urllib2.urlopen(requestPost))
Another problem was two versions of python (2 and 3) which uses different urllib(2)libraries.

I also have to set persistant USB-devices because the USB-adresses were changing when I restarted my RB.

But now I can conform that this script is working with a Multical 601 and IR-eye.
ProudElm
Posts: 4
Joined: Tuesday 24 December 2019 12:34
Target OS: -
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by ProudElm »

I've got the same heater. I managed to get it working with mysensors en domiticz.

Just got one question regarding the way domoticz can handle the value. MS does not have a 'GJ' value as far as i can see, but i would like it. Is there a trick i can use to at least let domoticz display it as GJ?
freijn
Posts: 536
Joined: Friday 23 December 2016 16:40
Target OS: Raspberry Pi / ODroid
Domoticz version: Stable
Location: Netherlands Purmerend
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by freijn »

Hi Elm

As far as I know this is not possible :-(
ProudElm
Posts: 4
Joined: Tuesday 24 December 2019 12:34
Target OS: -
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by ProudElm »

ah thats to bad.. :-(

For now im just happy it works. But yeah, i would like to display eventually my power meter and water meters also. But if domoticz cant handle GJ's, i will try perhaps some other tool..
Scarebus
Posts: 3
Joined: Saturday 16 April 2022 10:07
Target OS: OS X
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by Scarebus »

Hi folks,

I know this is an old topic, but I've read through this topic with great interest and can't wait to get started integrating my heating and hot water meter into my smart home. Regarding the software, I think I have plenty to go on from this topic, but I'm getting stuck a little before even getting there, because I can't really figure out what IR cable/transceiver to buy.

Can anyone point me in the right direction for either a USB-cable to plug into a Raspberry Pi, or a cable I can solder onto an ESP32 (or any microcontroller)? Either concrete product links or just better keywords to Google for would be greatly appreciated ("IR transceiver cable" gives me a gazillion IR relays which doesn't seem helpful).

Thanks a lot in advance :)
ProudElm
Posts: 4
Joined: Tuesday 24 December 2019 12:34
Target OS: -
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by ProudElm »

Wow.. long time ago indeed :)

I got it working now with and ESP running ESPHOME in Home Assistant. I could not get my other systems working in here.
I bought mine via:
https://wiki.volkszaehler.org/hardware/ ... b-lesekopf

But that was in 2014 already, so not sure if they are still selling. Good luck!
Scarebus
Posts: 3
Joined: Saturday 16 April 2022 10:07
Target OS: OS X
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by Scarebus »

Thanks a lot! Unfortunately they don't seem to sell anymore, I've ordered this one, hope that works 😬

https://de.elv.com/elv-bausatz-lesekopf ... iec-155523

(I will try to remember to report back here to share if it works, just in case the next lost soul comes here wondering what to buy)
ProudElm
Posts: 4
Joined: Tuesday 24 December 2019 12:34
Target OS: -
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by ProudElm »

Looks good. Hope it works!
Scarebus
Posts: 3
Joined: Saturday 16 April 2022 10:07
Target OS: OS X
Domoticz version:
Contact:

Re: District Heating / City Heating (Stadsverwarming) Mysensor IR sender/Receiver

Post by Scarebus »

So, for anyone coming here, trying to figure out what IR transceiver to buy, the one I linked before works great, *BUT* requires some assembly. I quickly skimmed over the page before purchasing and totally missed that it said "Bausatz", which means as much as "kit".

https://de.elv.com/elv-bausatz-lesekopf ... iec-155523

It seemed a little intimidating at first, but was actually very easy and straightforward (there's a German booklet included, which is easily translated by pointing the camera at it in the Google Translate app).

You need to solder two things (5 pads for the USB cable, 4 wires plus shielding, and the IR emitter), and optionally you can add the debug LEDs for transmitting and receiving (I did), which also requires drilling two 3mm holes in the case in premarked locations.

The kit as it came out of the box:
Image

The IR-emitter just before soldering in:
Image

The cable soldered on and the debug LEDs attached:
Image

It does come with a magnet which attaches easily to the Kampstrup Multical 601 (make sure to check the polarity of the ring magnet, I had to open the thing up again because I got it facing the wrong way).

If you have done any soldering before, you're absolutely not going to have any problems with this.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests