City heating (stadsverwarming) Kamstrup values into Energy Dashboard

I think I’ll try with arduino as well, to put the optical device on the arduino and try to read from there, see if I get a different result

Hi all,

In the past I used a Rpi with USB-IR to read out my Kamstrup 603 meter.
Since my Pi died I want to do this with an ESP. (And preferred ESPHome)

This should be possible with KMP (Kamstrup Meter Protocol [KMP] - ESPHome - Smart Home Made Simple)

Kitlist:

First I hoped that I could read my USB device through the second USB-C port of the ESP32-S3.
This wasn’t working that well. That’s the reason I bought the serial IR-eye.

The IR-eye is connected to the ESP32-S3 by the following:
DCD – 5v
RXD – GPIO17
TXD – GPIO18
GND – GND

I see light in the eye of the IR-device when I check with my phone camera.
Of course I already switch TXD and RXD for testing.
Also other baud rates are tested.
The error I get is :
Received invalid message (prefix mismatch received 0x80, expected 0x40)

If I do debug on the UART, I get the following response:

[17:10:41][D][uart_debug:158]: >>> "\x80?\x10\e\xF9\x00<\x00D\x00c\x00q\x03\xE9\x03\xEC\x1A\xAA\r"
[17:10:42][D][uart_debug:158]: <<< "\x80?\x10\e\xF9\x00<\x00D\x00c\x00q\x03\xE9\x03\xEC\x1A\xAA\r"

The ESP-Home config is the following:

uart:
  - id: uart_bus
    tx_pin: GPIO17
    rx_pin: GPIO18
    baud_rate: 1200
    parity: NONE
    stop_bits: 2

sensor:
  - platform: kamstrup_kmp
    heat_energy:
      name: Heat Energy
    power:
      name: Heat Power
    temp_diff:
      name: Heat Temperature Difference
    flow:
      name: Heat Flow
    custom:
      - name: Custom Heat Energy
        command: 0x003C
      - name: Custom Heat Power
        command: 0x0050
    update_interval: 10s

I do something wrong over here. But I don’t know what.
Have you guys got any idea?

I also tried to transform serial to IP (GitHub - oxan/esphome-stream-server: Stream server (serial-to-wifi bridge) for ESPHome),
and then read out the values with HA-Kamstrup_403 (ha-kamstrup_403/README.md at e6a717a62ff9f94be3619f7d2981ec0c4f0465cf · golles/ha-kamstrup_403 · GitHub)
This had no effect and resulted in the same logging.
Config for that one is:

external_components:
  - source: github://oxan/esphome-stream-server

stream_server:
   uart_id: uart_bus
   port: 1234

It seems like the solution with ESP-Home is not working with the MC603.
I found this solution: GitHub - mickkn/ESPxSerialBridge: Serial Bridge for Kamstrup 403 Home Assistents Integration

And integrated with this solution: GitHub - golles/ha-kamstrup_403: Custom component that integrates the Kamstrup 403 heating system into Home Assistant. This component does also support a few other heating systems

Works flawless

Here am I again :slight_smile:

I was wondering why the other solution was working well, and this one didn’t.
Key-part is that RX buffer size is needed at the value of 1024.
Maybe this is something that can be added to the page of the integration?

I also have added the full config with all options.
Credits to @golles where I found alot of info in his coding for getting this complete.
The dates are not imported correctly from the date-objects, those are getting a date in 1970 or something. I think it is the format which need to be changed.

The kit of @cfeenstra is still not working. Maybe the issue are the IR-LED and the photo-LED, but I used the 940nm ones. So it should be right.
https://nl.aliexpress.com/item/1005005371811048.html
If someone knows if these are wrong, please let me know and I order others to test. In the mean-time I use another reading head from AliExpress.
https://nl.aliexpress.com/item/1005005630726621.html?gatewayAdapt=glo2nld

Hereby the full ESP-Home config:

uart:
  baud_rate: 1200
  stop_bits: 2
  tx_pin:
    number: GPIO15
    inverted: true
  rx_pin: 
    number: GPIO13
    inverted: true
  rx_buffer_size: 1024

sensor:
  - platform: kamstrup_kmp
    heat_energy:
      name: Heat Energy
      device_id: kamstrup
      icon: "mdi:radiator"
      device_class: "energy"
      state_class: "total_increasing"
    power:
      name: Heat Power
      device_id: kamstrup
      icon: "mdi:flash"
    temp_diff:
      name: Heat Temperature Difference
      device_id: kamstrup
      icon: "mdi:thermometer"
    flow:
      name: Heat Flow
      icon: "mdi:water"
      device_id: kamstrup
    custom:
      - name: Heat Energy (E1)
        device_id: kamstrup
        command: 0x003C
        unit_of_measurement: "GJ"
        icon: "mdi:radiator"
        device_class: "energy"
        state_class: "total_increasing"
      - name: Heat Energy to Gas
        device_id: kamstrup
        command: 0x003C
        unit_of_measurement: "m³"
        icon: "mdi:gas-burner"
        device_class: "gas"
        state_class: "total_increasing"
      - name: Cooling Energy
        device_id: kamstrup
        command: 0x003F
        icon: "mdi:snowflake"
        device_class: "energy"
        state_class: "total_increasing"
        unit_of_measurement: "GJ"
      - name: Custom Heat Power
        device_id: kamstrup
        command: 0x0050
        icon: "mdi:flash"
        device_class: "power"
        state_class: "measurement"
        unit_of_measurement: "kW"
      - name: Temp1
        device_id: kamstrup
        command: 0x0056
        icon: "mdi:thermometer"
        device_class: "temperature"
        state_class: "measurement"
        unit_of_measurement: "°C"
      - name: Temp2
        device_id: kamstrup
        command: 0x0057
        icon: "mdi:thermometer"  
        device_class: "temperature"
        state_class: "measurement" 
        unit_of_measurement: "°C" 
      - name: Tempdiff
        device_id: kamstrup
        command: 0x0059  
        icon: "mdi:thermometer" 
        device_class: "temperature"
        state_class: "measurement" 
        unit_of_measurement: "°C"
      - name: Flow
        device_id: kamstrup
        command: 0x004A
        icon: "mdi:water"
        state_class: "measurement" 
        unit_of_measurement: "l/h"
      - name: Volume
        device_id: kamstrup
        command: 0x0044  
        icon: "mdi:water"  
        state_class: "total_increasing"
        unit_of_measurement: "m³"
      - name: MinFlow_M
        device_id: kamstrup
        command: 0x008D 
        icon: "mdi:water"   
        state_class: "measurement"  
        unit_of_measurement: "l/h"        
      - name: MaxFlow_M
        device_id: kamstrup
        command: 0x008B
        icon: "mdi:water"
        state_class: "measurement" 
        unit_of_measurement: "l/h"
      - name: MinPower_M
        device_id: kamstrup
        command: 0x0091  
        icon: "mdi:flash" 
        device_class: "power"
        state_class: "measurement" 
        unit_of_measurement: "kW"
      - name: MaxPower_M
        device_id: kamstrup
        command: 0x008F 
        icon: "mdi:flash" 
        device_class: "power"
        state_class: "measurement" 
        unit_of_measurement: "kW" 
      - name: AvgTemp1_M
        device_id: kamstrup
        command: 0x0095
        icon: "mdi:thermometer"
        device_class: "temperature"
        state_class: "measurement" 
        unit_of_measurement: "°C" 
      - name: AvgTemp2_M
        device_id: kamstrup
        command: 0x0096  
        icon: "mdi:thermometer" 
        device_class: "temperature"
        state_class: "measurement" 
        unit_of_measurement: "°C"  
      - name: MinFlow_Y
        device_id: kamstrup
        command: 0x007E 
        icon: "mdi:water"  
        state_class: "measurement" 
        unit_of_measurement: "l/h"
      - name: MaxFlow_Y
        device_id: kamstrup
        command: 0x0096 
        icon: "mdi:water"  
        state_class: "measurement"  
        unit_of_measurement: "l/h"
      - name: MinPower_Y
        device_id: kamstrup
        command: 0x0082 
        icon: "mdi:flash"  
        device_class: "power"
        state_class: "measurement"
        unit_of_measurement: "kW"  
      - name: MaxPower_Y
        device_id: kamstrup
        command: 0x0080
        icon: "mdi:flash"
        device_class: "power"
        state_class: "measurement"
        unit_of_measurement: "kW" 
      - name: AvgTemp1_Y
        device_id: kamstrup
        command: 0x0092 
        icon: "mdi:thermometer"  
        device_class: "temperature"
        state_class: "measurement" 
        unit_of_measurement: "°C"   
      - name: AvgTemp2_Y
        device_id: kamstrup
        command: 0x0093
        icon: "mdi:thermometer" 
        device_class: "temperature"
        state_class: "measurement"  
        unit_of_measurement: "°C"   
      - name: Temp1xm3
        device_id: kamstrup
        command: 0x0061  
        icon: "mdi:thermometer"  
        state_class: "measurement"
        unit_of_measurement: "°C"  
      - name: Temp2xm3
        device_id: kamstrup
        command: 0x006E
        icon: "mdi:thermometer"
        state_class: "measurement"
        unit_of_measurement: "°C"  
      - name: Infoevent
        device_id: kamstrup
        command: 0x0063  
        icon: "mdi:eye"  
        state_class: "measurement" 
        entity_category: "diagnostic" 
        accuracy_decimals: 0
      - name: Infoevent counter
        device_id: kamstrup
        command: 0x0071  
        icon: "mdi:eye" 
        state_class: "measurement" 
        entity_category: "diagnostic"
        accuracy_decimals: 0 
      - name: Serial number
        device_id: kamstrup
        command: 0x03E9 
        icon: "mdi:barcode" 
        state_class: "measurement" 
        entity_category: "diagnostic" 
        accuracy_decimals: 0  
      - name: HourCounter
        device_id: kamstrup
        command: 0x03EC  
        icon: "mdi:timer-sand"  
        state_class: "total_increasing" 
        entity_category: "diagnostic" 
        unit_of_measurement: "h" 
      - name: MinFlowDate_M
        device_id: kamstrup
        command: 0x008C
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MaxFlowDate_M
        device_id: kamstrup
        command: 0x008A   
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MinPowerDate_M
        device_id: kamstrup
        command: 0x0090    
        icon: "mdi:calendar"
        device_class: "date"
      - name: MaxPowerDate_M
        device_id: kamstrup
        command: 0x008E   
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MinFlowDate_Y
        device_id: kamstrup
        command: 0x007D 
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MaxFlowDate_Y
        device_id: kamstrup
        command: 0x007B    
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MinPowerDate_Y
        device_id: kamstrup
        command: 0x0081
        icon: "mdi:calendar"
        device_class: "date"
        accuracy_decimals: 0 
      - name: MaxPowerDate_Y
        device_id: kamstrup
        command: 0x007F   
        icon: "mdi:calendar"
        device_class: "timestamp"
        accuracy_decimals: 2 
1 Like