Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
Ik probeer onze stadsverwarming uit te lezen, een Kamstrup MULTICAL 66C02F1386.

Dit gaat dmv de aanwezige IR poort. Na het sturen van een start signaal ('/#1') met 300 baud geeft de meter antwoord op 1200 baud. In dit antwoord zitten o.a. huidige meterstand.
Deze waarden wil ik dus uitlezen met een esp32 en ESPHome en zo deze tonen/verwerken in Home Assistant.

Hier onder heb ik de code toegevoegd, maar het probleem is als volgt. Elke keer als ik antwoord krijg zijn de waarden 'verschoven', Ik heb geen idee waarom..

De eerste keer en zoals het zou moeten zijn:
code:
1
00000 xxxxxx02372461575342 0164560 0006941 0002496 0004445 0000000 0000000 000


Maar vervolgens wordt het een paar keer achter elkaar:

code:
1
2
3
0093 0000000 xxxxxx0237246 1575342 0164560 0006442 0002519 0003923 0000000 0000
000 0000093 0000000 xxxxxx0237246 1575342 0164560 0006442 0002519 0003923 0000
00 0000000 0000093 0000000 xxxxxx0237246 1575342 0164560 0006442 0002519 000392


Het verloopt dus als het waren. Ik heb alleen geen idee waarom, voor zover ik het snap beginnen alle variabelen schoon bij elke run. Dus zou er niks zijn dat blijft 'hangen'.?


C++:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "esphome.h"
#include <iostream>
#include <string>

class Multical602 : public PollingComponent, public UARTDevice
{
public:
  Sensor *sensor_energy{nullptr};
  Sensor *sensor_volume{nullptr};
  Sensor *sensor_tempin{nullptr};
  Sensor *sensor_tempout{nullptr};
  Sensor *sensor_tempdiff{nullptr};
  Sensor *sensor_power{nullptr};
  Sensor *sensor_flow{nullptr};
  TextSensor *textsensor_status{nullptr};

  Multical602(uint32_t update_interval, UARTComponent *uart_tx, UARTComponent *uart_rx, Sensor *m__energy, Sensor *m__volume, Sensor *m__tin, Sensor *m__tout, Sensor *m__tdiff, Sensor *m__power, Sensor *m__flow, TextSensor *m__status) : PollingComponent(update_interval), sensor_energy(m__energy), sensor_volume(m__volume), sensor_tempin(m__tin), sensor_tempout(m__tout), sensor_tempdiff(m__tdiff), sensor_power(m__power), sensor_flow(m__flow), textsensor_status(m__status)
  {
    _tx = new UARTDevice(uart_tx);
    _rx = new UARTDevice(uart_rx);
  }

  void setup() override
  {
  }

  std::string convertToString(char *a, int size)
  {
    int i;
    std::string s = "";
    for (i = 0; i < size; i++)
    {
      s = s + a[i];
    }
    return s;
  }
  void update() override
  {

    byte sendmsg1[] = {175, 163, 177}; //   /#1 with even parity

    byte r = 0;
    byte to = 0;
    byte i;
    byte j;
    char message[255];
    int parityerrors;

    to = 0;
    r = 0;
    i = 0;
    j = 0;
    parityerrors = 0;
    char *tmpstr;
    float m_energy, m_volume, m_tempin, m_tempout, m_tempdiff, m_power;
    long m_hours, m_flow;
    std::string m_status;

    for (int x = 0; x < 3; x++)
    {
      _tx->write(sendmsg1[x]);
    }

    _tx->flush();
    _rx->flush();

    ESP_LOGD("multical", "Start while loop");

    bool mag = true;

    while (r != 0x0A)
    {
      if (_rx->available())
      {

        // receive byte
        r = _rx->read();
        r = r & 127; // Mask MSB to remove parity

        Serial.print(char(r));
        message[i++] = char(r);
      }
      else
      {
        to++;
        delay(25);
      }

      if (i >= 81) 
      {
        
        Serial.println("");
        ESP_LOGD("multical", "OK");
        Serial.println("OK: ");
        Serial.println(message);


        m_status = "OK";

        break;
      }
      if (to > 100)
      {
        message[i] = 0;
        ESP_LOGD("multical", "ERR(TIMEOUT): %f", message);
        m_status = "ERR(TIMEOUT)";
        break;
      }
    }

    textsensor_status->publish_state(m_status);
  }
  UARTDevice *_tx;
  UARTDevice *_rx;
};


Deel van de YAML waar de UART poorten zijn gedefinieerd.
YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
uart:
  - rx_pin: 16
    baud_rate: 1200
    data_bits: 7
    parity: EVEN
    stop_bits: 1
    id: uart_rx
  - tx_pin: 17
    baud_rate: 300
    data_bits: 7
    parity: EVEN
    stop_bits: 1
    id: uart_tx  


Iemand een idee? Ik heb dit eerder werkend gehad met een arduino, maar daar had ik het zelfde probleem. Daar opgelost door na elke run een reset te doen :X

Acties:
  • 0 Henk 'm!

  • bouwfraude
  • Registratie: Februari 2004
  • Niet online
Zo te zien krijg je na de eerste poll meer bytes terug dan je inleest, die komen er bij de volgende poll bij.

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
Ja ik denk dat het zo iets was. Maar ik kwam er niet precies meer achter wat. Ik heb de boel omgegooid zodat werkt.

Eindelijk ook de technische documentatie weer terug gevonden en daarin kwam ik tegen hoe en wat het precies ook alweer moest zijn.

Request=300 baud and Data=1200 baud.
The signal format is: 1 start bit, 7 data bit, equal
parity and 2 stop bit.
The registers are separated by [SP] and each line
is ended with [CR]

Dus ik heb nu weer goed gefilterd op de CR en dat werkt een stuk beter. Ook een while loop gemaakt op
_rx->available().

Krijg nu elke run netjes antwoord en niks verloopt meer.

Acties:
  • 0 Henk 'm!

  • Kalobok
  • Registratie: Februari 2018
  • Laatst online: 25-02-2022
Hi!

Which parts are you using for IR read/write?

Acties:
  • 0 Henk 'm!

  • bipsen
  • Registratie: April 2022
  • Laatst online: 20-04-2022
@ProudElm - Did you get your custom component to work?

I am asking, as I would like to get data from my Kamstrup 382Lx7 into Home Assistant, and it also uses IR (and DLMS protocol) - but I am not so skilled in programming part, until now I just have some code which can dump reading to the USB/serial port of the ESP32 - but getting in it via ESPhome would be an optimal solution..

Regards
Brian

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
I dit not make a custom component. i just sticked with ESPHome.

It works fine since i installed it, i only had had to add a filter to the sensor so when it boots up it wont report a 0.

I used this:
filters:
- filter_out: 0.000

I will try to get the code up to github this weekend.

@Kalobok Sorry, i dit not noticed your message. Do you still seek the parts?

Acties:
  • 0 Henk 'm!

  • bipsen
  • Registratie: April 2022
  • Laatst online: 20-04-2022
Unfortunately my energy meter uses DLMS protocol with CRC1021 (or whatever it is called), and it requires a bit of special programming to request data and interpret the results for human reading afterwards...

Just for information - I am using an IR eye built from the instructions on https://wiki.hal9k.dk/projects/kamstrup (a Danish makerspace)

Acties:
  • +1 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
That's the same i'm using :-) I bought it some where else as a hole so i didnt had to assamble it myself.

But that logic of requsting and processing the data can be done in ESPHome also. Again, i will try to get the code asap on github. I cannot acces it today.

Acties:
  • 0 Henk 'm!

  • bipsen
  • Registratie: April 2022
  • Laatst online: 20-04-2022
Sound great... On 382Lx7 the interface uses 9600 8N1 - so it is pretty standard

I'd appreciate if you update the post once you have put something on github :-)

Acties:
  • 0 Henk 'm!

  • bipsen
  • Registratie: April 2022
  • Laatst online: 20-04-2022
Seems like I found a workaround - and something is up and running...
I am no C++ programmer, so I am not sure about the right location of the different variables...

I have put my code on https://github.com/bipsendk/kamstrup-382Lx7

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
I almost forgot, but i have my code now up on github. Its not much, but it works.

https://github.com/ProudElm/ESPHome_multical_sensor

Acties:
  • 0 Henk 'm!

  • svenvdmeer
  • Registratie: December 2011
  • Laatst online: 21-05 16:14
ProudElm schreef op woensdag 6 april 2022 @ 15:01:
That's the same i'm using :-) I bought it some where else as a hole so i didnt had to assamble it myself.

But that logic of requsting and processing the data can be done in ESPHome also. Again, i will try to get the code asap on github. I cannot acces it today.
May I ask where you bought this complete IR unit?

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
I bought the unit back in 2014 from:
https://wiki.volkszaehler...reib-lesekopf-ttl-ausgang

I dont know if its still being sold there.

Acties:
  • 0 Henk 'm!

  • didekoning
  • Registratie: Juli 2015
  • Laatst online: 23-06 11:45
Beste,

Ik heb de volgende module op eBay gekocht omdat ik ook graag mijn stadsverwarming wil uitlezen (Multical 401). Echter staat nergens aangegeven welk contact waarvoor is. Weet een van jullie toevallig hoe je dit kunt achterhalen of is dit gewoon op de printplaat te zien? Ik heb niet zoveel ervaring met elektronica :)

Mijn vermoeden is van links naar rechts:
[list=1]
• RX
• GND
• VIN
• TX
[/list]

Op de achterkant denk ik dat LED101 de IR led is en T101 de ontvanger. Op basis daarvan ook mijn vermoeden voor welke TX en welke RX is.

Afbeeldingslocatie: https://tweakers.net/i/A7aKFfvk1xJNBIXgSoP4PwvuE-g=/x800/filters:strip_icc():strip_exif()/f/image/OCogcc75Yoj4K28M5p1i6X1o.jpg?f=fotoalbum_large

Afbeeldingslocatie: https://tweakers.net/i/XNiWje3wQZ4WnKmWI06CS22S3lY=/800x/filters:strip_icc():strip_exif()/f/image/8K9x9jqmD2WzUYxDMBx4uEdx.jpg?f=fotoalbum_large


Zojuist na wat extra zoeken toch een handleiding kunnen vinden: https://bayha-electronics.de/download/Bauanleitung-TTL.pdf

Bij voorbaat dank _/-\o_

[ Voor 4% gewijzigd door didekoning op 13-10-2022 17:28 ]


Acties:
  • 0 Henk 'm!

  • Henksnavel
  • Registratie: Juli 2013
  • Laatst online: 13-05 16:29
@ProudElm Zou dit ook werken op een multical-603?

Ik heb een deze aangeschaft maar ik krijg met jou script helaas niks terug behalve ERROR

https://www.ebay.de/itm/353940190755

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
Geen idee eigenlijk, je zou moeten kijken of er documentatie is over die 603. Welke baud settings en eventueel wat je moet sturen om antwoord te krijgen? Grote kans wel dat dit gelijk is aan de 602 natuurlijk, maar zou ook zo maar kunnen afwijken..

Acties:
  • 0 Henk 'm!

  • rvhadam
  • Registratie: Januari 2014
  • Laatst online: 21-06 13:47
@ProudElm
Ik heb jouw code nu gebruikt op mijn 66c kampstrup en dat werkt goed. maar alle gegevens worden alleen bijgewerkt als ik handmatig de schakelaar aan zet...

Heb je in home assistant dan een automations die de hele tijd die schakelaar omzet? Kan dat niet vanzelf?

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
Ik had het zo gemaakt omdat ik dan vanuit HA kan zeggen wanneer ik een nieuwe waarde wil. Juist om de batterij van het kastje te ontlasten.
Dus overdag elke 15 min. Maar 's nachts 1x per uur. In de zomer staat de verwarming uit, dus dan maar 1x per dag.

Nu we ook warm water krijgen door de warmtewisselaar heb ik dan ook gemaakt dat als er langer dan 5 min warm water gepakt wordt dat als dit weer uit gaat dat er dan ook een nieuwe waarde wordt opgehaald.

Daarom heb ik het zo opgelost..

Acties:
  • 0 Henk 'm!

  • rvhadam
  • Registratie: Januari 2014
  • Laatst online: 21-06 13:47
Ik snap hem! ik heb nu een interval ingesteld van 5 min in esphome, dan haalt hij het ook elke 5 min op

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
Ja dat kan ook! Mooi opgelost!

Hopelijk schieten ze op met die slimme meter die de huidige meter moet vervangen van de stadsverwarming.. Ergens loopt er een pilot, maar weer eens contact zoeken met Vattenfall..

Acties:
  • 0 Henk 'm!

  • rvhadam
  • Registratie: Januari 2014
  • Laatst online: 21-06 13:47
Je gaat het niet geloven... 3 minuten geleden kreeg ik een mail dat ze warmtelink willen komen installeren....
Net nu ik die kamstrup kan uitlezen...

Nou dat word ombouwen hahahahaha

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
haha geweldig.. zal je inderdaad altijd zien!

Ik ben benieuwd naar je ervaringen!

Acties:
  • 0 Henk 'm!

  • TheLastMeow
  • Registratie: April 2022
  • Laatst online: 20-05 07:58
ProudElm schreef op zaterdag 9 april 2022 @ 15:27:
I almost forgot, but i have my code now up on github. Its not much, but it works.

https://github.com/ProudElm/ESPHome_multical_sensor
Hello,
Thanks for your great work. I have ordered my sensor and I checked your code. From my understanding if I want it to report the consumption, I should turn on the sensor and when I don't need it I can turn it off?

Acties:
  • 0 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
The sensor is kind of a switch, but it's triggered from a automation in HA and then the sensor will gather the information and send it back.
The switch will switch back form on to off once it's done. (if my memory is correct, it's been a long time...)

Acties:
  • 0 Henk 'm!

  • TheLastMeow
  • Registratie: April 2022
  • Laatst online: 20-05 07:58
ProudElm schreef op dinsdag 14 februari 2023 @ 14:44:
The sensor is kind of a switch, but it's triggered from a automation in HA and then the sensor will gather the information and send it back.
The switch will switch back form on to off once it's done. (if my memory is correct, it's been a long time...)
This is a neat and great idea; I love it. Since these meters are battery powered and I read somewhere everytime we read from IR it consumes alot.

This is from your awesome code:
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
  on_boot:
    priority: -100
    then:
      - switch.turn_off: multical_sensor
      - switch.turn_on: multical_sensor
      

# Enable Home Assistant API
api:
  services:
    - service: read_sensor
      then:
          - switch.turn_on: multical_sensor


I couldn't find the auto on/off but from the ESPHome HASS API code above, it seems it only turns that on. Either way I'm waiting for the sensor I ordered from ebay. Hope it works for me too :)

Again thanks for the github

Acties:
  • +1 Henk 'm!

  • ProudElm
  • Registratie: Juni 2003
  • Laatst online: 09:20
It's coming back. i use the following automation from HA:

YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
alias: Stadsverwarming -  elke 15
description: Stadsverwarmig check elke 15 min
trigger:
  - minutes: /15
    platform: time_pattern
condition:
  - condition: time
    after: "06:00:00"
    before: "00:30"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: esphome.stadsverwarming_read_sensor
    data: {}
mode: single


I use the service provided from the sensor indeed to activate it. Hopefully the sensor comes soon and you can get it to work!

Acties:
  • +1 Henk 'm!

  • TheLastMeow
  • Registratie: April 2022
  • Laatst online: 20-05 07:58
ProudElm schreef op dinsdag 14 februari 2023 @ 16:20:
It's coming back. i use the following automation from HA:

YAML:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
alias: Stadsverwarming -  elke 15
description: Stadsverwarmig check elke 15 min
trigger:
  - minutes: /15
    platform: time_pattern
condition:
  - condition: time
    after: "06:00:00"
    before: "00:30"
    weekday:
      - mon
      - tue
      - wed
      - thu
      - fri
      - sat
      - sun
action:
  - service: esphome.stadsverwarming_read_sensor
    data: {}
mode: single


I use the service provided from the sensor indeed to activate it. Hopefully the sensor comes soon and you can get it to work!
Thanks, I apricate this a lot.

With this yaml automation my job is less than before. Thanks ProudElm!

Acties:
  • 0 Henk 'm!

  • maxmeo
  • Registratie: December 2011
  • Laatst online: 31-05 12:49
Henksnavel schreef op dinsdag 8 november 2022 @ 09:30:
@ProudElm Zou dit ook werken op een multical-603?

Ik heb een deze aangeschaft maar ik krijg met jou script helaas niks terug behalve ERROR

https://www.ebay.de/itm/353940190755
Is het nog gelukt met deze IR lezer?

Acties:
  • 0 Henk 'm!

  • Henksnavel
  • Registratie: Juli 2013
  • Laatst online: 13-05 16:29
maxmeo schreef op zondag 9 april 2023 @ 16:28:
[...]


Is het nog gelukt met deze IR lezer?
Ja helemaal gelukt. Lees hem nu via een esp8266 met esphome uit
via deze: https://github.com/cenobitedk/esphome_multical402

[ Voor 12% gewijzigd door Henksnavel op 11-04-2023 11:41 ]

Pagina: 1