Fix for checksum mismatch

Thanks to a lot of good work and effort of Maurice Makaay, there is a fix for the checksum mismatch error (here and here on GitHub). The reason in short is: “telegrams are getting more data as expected and doesn’t fit therefore in the declared size”. Two fixes are in the original code (for now, as it will be merged eventually in the core).

Fix one

Under uart there is a line added rx_buffer_size: 1500. This makes the rx buffer larger.

Fix two

Second fix is a piece of external code from Maurice Makaay:

external_components:
  - source:
      type: git
      url: https://github.com/mmakaay/esphome
      ref: fix-dsmr-read-chunk-size
    components: [ "dsmr" ]
    refresh: 60s

This does some extra stuff for the size of the telegram. I can’t write it otherwise than this, as I’m not a coder like Maurice 😂 But is does fix the issue and thats all I care about.

The main code

This is the whole code I’m using. That makes it usable for anyone in Netherlands, Belgium, Luxembourg and other counties.

I do recommend everybody to use their own code within ESPHome. Then you can remove unneeded pieces of code. The less code you use, the better.

I’ve noticed recently that the new ESPHome code is getting more power-hungry. More CPU is used and more wifi transmissions. And that causes in some cases to cross the 250mA limit on the P1 port.

---
substitutions:
  device_name: slimmelezer
  device_description: "DIY P1 module to read your smart meter"
    
esphome:
  name: ${device_name}
  comment: "${device_description}"
  platform: ESP8266
  esp8266_restore_from_flash: true
  board: d1_mini
  name_add_mac_suffix: false
  project:
    name: zuidwijk.slimmelezer
    version: "1.0"
  on_boot:
    then:
      - if:
          condition:
            lambda: return id(has_key);
          then:
            - lambda: |-
                std::string key(id(stored_decryption_key), 32);
                id(dsmr_instance).set_decryption_key(key);
          else:
            - logger.log:
                level: info
                format: "Not using decryption key. If you need to set a key use Home Assistant service 'ESPHome:  ${device_name}_set_dsmr_key'"

external_components:
  - source:
      type: git
      url: https://github.com/mmakaay/esphome
      ref: fix-dsmr-read-chunk-size
    components: [ "dsmr" ]
    refresh: 60s
    
wifi:
  networks:
    - ssid: !secret wifi_ssid
      password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: ${device_name}
    ap_timeout: 15s

captive_portal:

# Enable logging
logger:
  baud_rate: 0

# Enable Home Assistant API
api:
  services:
    service: set_dsmr_key
    variables:
      private_key: string
    then:
      - logger.log:
          format: Setting private key %s. Set to empty string to disable
          args: [private_key.c_str()]
      - globals.set:
          id: has_key
          value: !lambda "return private_key.length() == 32;"
      - lambda: |-
          if (private_key.length() == 32)
            private_key.copy(id(stored_decryption_key), 32);
          id(dsmr_instance).set_decryption_key(private_key);

ota:

web_server:
  port: 80

uart:
  baud_rate: 115200
  rx_pin: D7
  rx_buffer_size: 1500

globals:
  - id: has_key
    type: bool
    restore_value: yes
    initial_value: "false"
  - id: stored_decryption_key
    type: char[32]
    restore_value: yes

dsmr:
  id: dsmr_instance
  # For Luxembourg users set here your decryption key
  #decryption_key: !secret decryption_key // enable this when using decryption for Luxembourg; key like '00112233445566778899AABBCCDDEEFF'

sensor:
  - platform: dsmr
    energy_delivered_lux:
      name: "Energy Consumed Luxembourg"
      state_class: total_increasing
    energy_delivered_tariff1:
      name: "Energy Consumed Tariff 1"
      state_class: total_increasing
    energy_delivered_tariff2:
      name: "Energy Consumed Tariff 2"
      state_class: total_increasing
    energy_returned_lux:
      name: "Energy Produced Luxembourg"
      state_class: total_increasing
    energy_returned_tariff1:
      name: "Energy Produced Tariff 1"
      state_class: total_increasing
    energy_returned_tariff2:
      name: "Energy Produced Tariff 2"
      state_class: total_increasing
    power_delivered:
      name: "Power Consumed"
      accuracy_decimals: 3
    power_returned:
      name: "Power Produced"
      accuracy_decimals: 3
    electricity_failures:
      name: "Electricity Failures"
      icon: mdi:alert
    electricity_long_failures:
      name: "Long Electricity Failures"
      icon: mdi:alert
    voltage_l1:
      name: "Voltage Phase 1"
    voltage_l2:
      name: "Voltage Phase 2"
    voltage_l3:
      name: "Voltage Phase 3"
    current_l1:
      name: "Current Phase 1"
    current_l2:
      name: "Current Phase 2"
    current_l3:
      name: "Current Phase 3"
    power_delivered_l1:
      name: "Power Consumed Phase 1"
      accuracy_decimals: 3
    power_delivered_l2:
      name: "Power Consumed Phase 2"
      accuracy_decimals: 3
    power_delivered_l3:
      name: "Power Consumed Phase 3"
      accuracy_decimals: 3
    power_returned_l1:
      name: "Power Produced Phase 1"
      accuracy_decimals: 3
    power_returned_l2:
      name: "Power Produced Phase 2"
      accuracy_decimals: 3
    power_returned_l3:
      name: "Power Produced Phase 3"
      accuracy_decimals: 3
    gas_delivered:
      name: "Gas Consumed"
      state_class: total_increasing
    gas_delivered_be:
      name: "Gas Consumed Belgium"
      state_class: total_increasing
  - platform: uptime
    name: "SlimmeLezer Uptime"
  - platform: wifi_signal
    name: "SlimmeLezer Wi-Fi Signal"
    update_interval: 60s

text_sensor:
  - platform: dsmr
    identification:
      name: "DSMR Identification"
    p1_version:
      name: "DSMR Version"
    p1_version_be:
      name: "DSMR Version Belgium"
  - platform: wifi_info
    ip_address:
      name: "SlimmeLezer IP Address"
    ssid:
      name: "SlimmeLezer Wi-Fi SSID"
    bssid:
      name: "SlimmeLezer Wi-Fi BSSID"
  - platform: version
    name: "ESPHome Version"
    hide_timestamp: true

27 comments

    1. Marcel

      I’m thinking about making a version with extra headers to attach a water meter (needs to be standard, otherwise its a hassle to make it all work). Gas meter should be integrated/connected to your smart meter. Or do you have another version?

        1. Marcel

          Well, I’m about to order a water meter to do some testings… I dont get the clue for gasmeter. You’re not having a gasmeter. If you have one, or get one, it would be integrated into the Smart Meter and the readout should be in the telegrams of the Smart Meter.

          1. BJ

            I am using P1Monitor with an induction sensor for the watermeter. I want to switch to the slimmelezer because it uses the power supply of the slimmemeter and I can reuse my Raspberry PI. The lack of a watermeter connector/pins on the board is the only thing stopping me.

          2. Marcel

            Have you got a suggestion for me for how to add an optional header? It’s not hard to add an external sensor. The only issue/challenge is powering it. The DSMR 5 meter can deliver max 250mA (which will be consumed by the ESP8266). Adding more sensors might cause brown-outs and therefore needs external power via usb.

  1. Chris van Aalst

    Marcel, Maurice,

    Thanks this fixed my problem – (Slimmelezer incl Belgian fix) – compiled with ESPHome.

    Regards

    Chris

  2. Rogier

    I really wanted this to be the fix. However… no ajetoo here. Copy pasted the entire flash log below:

    [[cut]]
    [20:55:07][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [20:55:08][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [20:55:09][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [20:55:10][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [[cut]]

    1. Marcel

      I removed most of the log, as it is way too big for a post on my website. I left the most important error message. Please look at here. And please do open an issue on the ESPHome GitHub issue page. Not that I’m unwilling, yet there is more knowledge there and the developers are there too.

  3. Hannon Queiroz

    Hi Marcel, I tried this fix but I run into a problem when I add the external_components section. Do you know what this could be? (Let me know if there is a better channel to communicate abou this for better formatting or something like that.

    [[removed]]

    1. Marcel

      Hi Hannon, I’ve removed the log, as that’s getting too big for the website. Please look here for all existing knowledge. If you can’t find it, please open a new issue there.

  4. Deze

    Thanks for your work and for this great device! Unfortunately this patch did not solve the problem for me either, I get the following error message in the log: ” Error: telegram larger than buffer (1500 bytes)”.
    I have an SX631 meter and I am with a Hungarian service provider. Do you have any ideas or suggestions for a solution? Any help is welcome…

        1. Zsolt

          Deze, did it solve your problem? I’m really cuorious, since I’m also planning to use Slimme in Hungary 🙂 As soon as Marcel will have some on stock again 🙂

          1. Marcel

            Well, it did solve on my meter in The Netherlands, and most likely it will solve that issue for any meter (as long as it has a P1 port and not mbus port).

  5. Remco

    INFO Starting log output from slimmelezer.local using esphome API
    WARNING Can’t connect to ESPHome API for slimmelezer.local: Timeout while connecting to (‘192.168.1.94’, 6053)
    INFO Trying to reconnect to slimmelezer.local in the background

    ik krijg dit als error als ik de code in esphome zet.

  6. Remco

    Got it working. Enige andere probleem is hij laat het nu in kWh zien ipv watt dus 0.37 kWh laat hij dus zien op de grafiek als 0.37 W.

  7. Dennis

    Marcel,

    Hopelijk kan je me op weg helpen. Ik kreeg de checksum error dus update gedaan via ESPHOME ( met bovenstaande code) maar krijg nu weer een andere error waar ik niet uit kom.

    Missing unit
    [16:04:45][C][mdns:084]: mDNS:
    [16:04:45][C][mdns:085]: Hostname: slimmelezer
    [16:04:45][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:46][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:47][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:48][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:49][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:50][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:51][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:52][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:53][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:54][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:55][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:56][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)
    ^
    Missing unit
    [16:04:57][E][dsmr:168]: 0-1:24.2.1(700101010000W)(00000000)

    Enig idee waarom? gr

  8. Hannon Queiroz

    Hi Marcel, after I updated ESPHome and applied the checksum mismatch fix (which worked, btw), the gas consumption value will sometimes read out 0 for a while and then go back to the correct reading from my smart meter. I have opend an issue on ESPHome github page, but maybe you have an idea of what’s causing it? Please see the issue here: https://github.com/esphome/issues/issues/2758

    1. Marcel

      To be honest, I have no idea. It could be that the telegram is corrupt and/or incomplete and therefore missing some data. When that happens, you need to compare the data in ESPHome with the actual telegram to see what’s different. Only then you can go troubleshoot.

Leave a Reply

Your email address will not be published. Required fields are marked *