Building an ESP8266 DSMR5 reader for Home Assistant

Oct 18, 2021

For sending statistics about energy usage to my Home Assistant (HA) instance from my smart meter, a Sagemcom XS210 ESMR5 (DSMR5), I’ve been using a P1 cable and a Raspberry Pi Zero (RPi) running ser2net following a blog post by Jean-Paul van Ravensberg. However, the idea of using both a P1 connector cable RJ11 (4-pin) and a RPi Zero seemed somewhat overkill as I had to make a wall mount for it, use an extra power outlet to power the RPi and the RPi is running a full OS for just reading and submitting serial data. Time to move to an ESP8266 solution!

In one of my previous posts I wrote about submitting MQTT messages with an ESP8266 NodeMCU to a broker, like HA. Look it up if you’d like to rehearse.

When reading more about ESP8266’s I came by a (forked) repo that replaces the P1 cable and RPi solution by using a 4 bucks ESP8266 (D1 Mini) and a RJ12 (6-pin) using the 5V power on the 6th pin. In the process below we’ll build a small ESP8266-based DSMR5 connector for our smart meter.

Credits for the DSMR software go to Flip Hess and Daniel Jong.


Preparing the wires ⚡

The RJ12 cable numbering walks from index 1-6 with it’s pin down. Connect colors in the example as follows:

  1. Blue: 5V
  2. Yellow: 3.3V, RTS
  3. Green: Ground
  4. -
  5. Black: RxD
  6. White: NC, (Ground)


Preparing the software

  1. Install Visual Code with the PlatformIO plugin. This plugin will build and upload the DSMR5 software to our D1 Mini.

  2. Checkout the forked repository by Daniel Jong and open it in Visual Code. Go to the PlatformIO tab and choose Build. Next choose Upload and Monitor after a successful build. You should see some logs like the following:

     > Executing task: platformio run --target upload --target monitor --environment d1_mini <
     Processing d1_mini (platform: espressif8266; board: d1_mini; framework: arduino)
     Writing at 0x00038000... (93 %)
     Writing at 0x0003c000... (100 %)
     Wrote 361712 bytes (258298 compressed) at 0x00000000 in 25.0 seconds (effective 115.8 kbit/s)...
     Hash of data verified.
     Hard resetting via RTS pin...
     === [SUCCESS] Took 29.35 seconds ===
  3. Keep in mind that you can always override credentials in settings.h to pre-fill credentials on the Wifi/MQTT configuration screen:
    // header.h
    // * To be filled with EEPROM data
    char MQTT_HOST[64] = "";
    char MQTT_PORT[6]  = "1883";
    char MQTT_USER[32] = "SOME_USERNAME";
    char MQTT_PASS[32] = "SOME_PASSWORD";
  4. After a successful upload, check your Wifi networks. The ESP8266 should broadcast itself. Connect to it, this will present a Wifi setup screen. Override your MQTT broker credentials when needed, and fill in your Wifi SSID and password. When connected successfully the ESP8266 will not present itself as a network anymore. Run a tool like LanScan (MacOS) to check for its LAN address.

    Wifi Setup

  5. Unplug The ESP8266 and solder the wires and components onto a solder PCB prototyping board and cut it at a correct size. Use included spacers for the ESP8266 to encapsulate the soldered parts. I’m using a Rademacher WR-Typ 790-5 board. This makes it easier to solder multiple wires and connections.

    Rademacher WR-Typ 790-5

  6. Make sure you register the MQTT entities correctly for the new HA Energy Management pane.

    Register your power consumption entities like the following:

    # sensors.p1.yaml
    - platform: mqtt
      name: P1 Laagtarief (consumptie)
      unit_of_measurement: 'kWh'
      state_topic: "sensors/power/p1meter/consumption_low_tarif"
      value_template: "{{ value|float / 1000 }}"
      device_class: 'energy'
      state_class: 'total_increasing'

    And your gas usage as follows:

    # sensors.p1.yaml
    - platform: mqtt
      name: P1 Gas Verbruik
      unit_of_measurement: 'm³'
      state_topic: "sensors/power/p1meter/gas_meter_m3"
      value_template: "{{ value|float / 1000 }}"
      icon: 'mdi:gas-cylinder'
      device_class: 'gas'
      state_class: 'total_increasing'
  7. Reload MQTT entities on the Server Controls page.

  8. Entities should now appear on the Energy configuration page of your HA instance:



If you cannot find the entities, make sure your ESP8266 is connected to the MQTT broker by choosing Upload and Monitor from the PlatformIO panel in Visual Code. This show necessary debugging information about the configured Wifi and MQTT connection. Also make sure your .yaml entities contain the correct device_class and state_class. The entities appear only in the dropdown of the defined device_class in the Energy configuration panel.

For a full example of the MQTT entities, check the previous example configuration by Flip Hess. Not that the entities in the examples do not have the correct device_class and state_class which should be provided as noted above.


When necessary you can download my design for a 3D printable case. Feel free to adjust as needed.


Jeroen Boumans

Backend & App Developer