Kamstrup city heating - Domoticz Python script on Home Assistant

I have a Kamstrup meter for my hot water and heating.
On the internet i found a project to read these devices:
IR-øje til Kamstrup og andre målere [Hal9k's wiki] (it’s in danish, Google translate works).

I have ordered some PCB’s in china, and assembled these.

On Github i found a python script to read the device, i only have no idea how to implement this into my HA.

PyMultical/pymultical.py at master · tvwerkhoven/PyMultical · GitHub

The script uses MQTT, so integration should not be that hard i guess?
Is there anybody that can help me or give me some pointers?

P.s. For those who want, i have some (10pcs) pcb’s left over. Send me a PM if interested (only postal cost from The Netherlands)

As far I can see, python script on each run get the value, and store it in InfluxDB if line before last is uncommented, and publish it to MQTT if last line is uncommented.
Simplest solution will be run script periodically via cron, and get value from MQTT sensor.

Thank you Igor,

The whole Python / cronjob is new to me. How to add to the cron?
I am running HASS, the device is connected to /dev/ttyUSB1.

Modifying the script i can do myself :slight_smile:

Ok, i made some modifications to the script,

Changed rule 162 from
def init(self, serial_port):

to
def init(self, serial_port = “/dev/ttyUSB1”):

So the port is fixed, and not have to be set on commandline…

I found out i can run scripts for testing from developer tools > services. When i run the script i will get a error:

Logger: homeassistant.components.python_script
Source: components/python_script/__init__.py:154
Integration: Python Scripts ([documentation](https://www.home-assistant.io/integrations/python_script), [issues](https://github.com/home-assistant/home-assistant/issues?q=is%3Aissue+is%3Aopen+label%3A%22integration%3A+python_script%22))
First occurred: 6:34:05 PM (2 occurrences)
Last logged: 6:48:18 PM

Error loading script kamstrup.py: Line 357: "__name__" is an invalid variable name because it starts with "_"

Line 357:
if name == “main”:

Hi Ivan,

I cannot offer help in writing a script, but if you’re also content with a ready solution see
GitHub - golles/ha-kamstrup_403: Kamstrup 403 integration for Home Assistant

2 Likes