Support for reading Dutch Smart Meter (electricity/gas) (P1 port)

I did make a change to /dev/ttyUSB1 and now it works again. really strange.

  - platform: dsmr
    port: /dev/ttyUSB1
    dsmr_version: 4

Thatā€™s strange indeed. When I do a ā€œls -ltr /dev/ | grep ttyUSB*ā€ I only get the ttyUSB0.
I also updated to Home Assistant 47.1, no effect.
However, running the dsmr_console command it now only provides the output and no more logging errors.

Are you running multiple USB devices? Unfortunately on Linux it is a bit of guesstimation what device gets which name. That is why I renamed the USB devices based on their serial number through Udev rules.

Hi Frank, Iā€™m not running multiple USB devices. I only have Ethernet and the P1 cable plugged in. (and obviously the power cable)

I have a Kaifa MA105C. Itā€™s seems to me that this device is not yet supported. Is this correct?

The device requires the following settings:
DSMR version: 4.2.2
Baudrate: 115200
Bits: 8
Parity: None
Stopbits: 1
Telegram reader: KFM5

Thanks a lot for your hard work so far.

Edit: Iā€™ve tried to changing the settings.py in the dsmr_parser, but still no response. When i run ā€œsudo stty -F /dev/ttyS0 -aā€ I can confirm the settings changed (cs7 has become cs8 and so on).

Also with the dsmr_console (dsmr_console --version 4 -b 8 -p N --device /dev/ttyUSB0 -v) I get no response. On Windows the cable works.

Edit 2: Finally got it working. Although I have to use two workarounds.
The first workaround is that I have to edit the ā€œdsmr_parser/clients/settings.pyā€ file and change version 4 settings to:

SERIAL_SETTINGS_V4 = {
    'baudrate': 115200,
    'bytesize': serial.EIGHTBITS,
    'parity': serial.PARITY_NONE,
    'stopbits': serial.STOPBITS_ONE,
    'xonxoff': 0,
    'rtscts': 0,
    'timeout': 20
}

The second workaround and the reason why my cable doesnā€™t work on Ubuntu, but does work on Windows has to do with the TDR setting. I fixed this by running the following script at startup of my Ubuntu machine. The script forces DTR to be set to 1. Make sure to start the script delayed so that Ubuntu has time enough to initialize the devices.

#!/usr/bin/env tclsh8.5
set device "/dev/ttyUSB0"
set dh [open $device r+]
fconfigure $dh -mode "115200,n,8,1" -translation binary -encoding binary -blocking 0 -buffering line -ttycontrol {RTS 0 
DTR 1}
close $dh

As I said for now it works, but I hope that in the future I wouldnā€™t have to use these workarounds anymore.

1 Like

Glad to see you got it to work. I think I will be working soon on making the serial settings fully configurable as more people are having issues with this as it differs from manufacturer to manufacturer.

Could you maybe add the DTR information to the component page so it is available for others: https://home-assistant.io/developers/website/

Before buying oneā€¦ can anyone tell me if the module of espthingies works correcly on a Kaifa MA105C? Or what to edit/do to have it working.

I used the mindergas.py from earlier in this post. I have HA running on https now and that broke the script. I tried changing the port to 443 but that didnā€™t fix the problem. What should I change in the script to connect over https ?

Ignore that, fixed it:

api = remote.API(hass_ip,hass_password, hass_port, **use_ssl = True**)

Since last time an update to the DSMR components caused some issues with users Iā€™d like to test the latest update before offering it for merge, if people here are willing to test this it would be awesome, instructions can be found here: https://github.com/home-assistant/home-assistant/issues/8128#issuecomment-329483945 Preferably leave feedback in that thread as well. Specifically DSMR4/5 users but others are welcome as well.

Hello i please need some help getting my p1 port working on hassioā€¦

I found the website were my meter Landis Gyr E350 ZCF110 says 6 pins rj11 i bought a 4 pins rj11 to usb is this going to work?
And if it will work what pin config should i use and do i need an resistance

Any help will be great!!

Thanks


Landis + Gyr E350 (ZCF110) 1-fase kleinverbruik RJ-11, 6-pins 4.2 115200 8N1 Zie mailtip onder /XMX5LG

Here a picture of my p1 usb to rj11 cable
Hope anybody can help!

Nobody to help me? still not working for meā€¦ Tried a different pin layout on the rj11 connector but still nog data in my home assistant

Does your cable has an FTDI chip inside? You will need this (or similar device) to convert the serial data from the meter to USB. Secondly you will need a resistor between VDD (+5V) and the RxD pin. see the mailtip in the document you linked.

Hi,

Since im new here, i hope not to ask for something asked a hundred times already, but ive tried to read this whole thread and couldnā€™t findā€¦

Im trying to connect my p1 slimme meter to Home Assistant. Got it running on a Synology Nas at the moment, hope to install a Raspberry Pi next week.

  • What would be the optimal hardware connection? Is t the P1 to usb conversion cable?

  • Ive edited the configuration file to include the DSMR section, but didnā€™t manage to install the parser https://github.com/ndokter/dsmr_parser yet. Somehow i canā€™t pip itā€¦

Is there a special command forgoing that. Please bare with me for the moment, and hoe you can help with some useful hints!
Thanks,
Marius

The most used scenario is a serial to USB connection to a Pi, although a Pi can also read the serial port directly (if you disable bluetooth on the same UART pins for the Pi3). An Arduino-like device lacks the connectivity and in many cases the speed to process the data at 115.200 baud while also parsing it and doing CRC16 calculation and verification at the same time.

Personally, I use a WiFi connected ESP8266 that sends the parsed and translated data (from a Landis+Gyr 350 providing DSMR v4.2 output at 115.200 baud) via MQTT. That way I donā€™t have to place a EUR 35+ Raspberry Pi near the smart meter doing almost nothing. Instead I use a EUR 3,50 ESP8266 that is connected to the P1 port with an RJ11 cable/connector (all 6 pins).

To answer your first question after this way too long introduction: If youā€™re not experienced with hardware and programming: go for a ready-made TTL-serial to USB cable connected to a Pi.

I cannot hep you with the second question, as I used a different setup and parse the telegram in the ESP8266.

On the topic of using a Pi: please bear in mind that a Pi and in particular a SD card is not very reliable in the long run. Make sure you also setup a solid backup strategy. Or keep it running on your NASā€¦ ;o|

As @phsdv says, you need a TTL-serial to USB cable and from the picture we cannot see what exactly it is.

For the P1 interface to work, you just need to connect DATA (pin 5) and DATA GND (pin 3) to the TTL-Serial side of the cable (do you know which of the three wires in the picture is what?). You also need to add the resistor as mentioned for the Landis+Gyr - because it is a so-called open collector output.

If you have all this connected properly, then youā€™re probably bitten by the reversed TTL output of this smart meter. Either have a cable that can invert it, or do the inversion in software.

Iā€™ve created a Smart Meter blog post detailing this and more. Sorry for plugging my little blogā€¦

Thanks!
Im hoping to spend some extra investigating time with this coming week.
Your guidance surely helps finding the right direction.

Cheers,
Marius

Why would you believe the Pi and card arenā€™t reliable in the long run?

I thought it better to have a dedicated device and took it off of my Nas ;-)ā€¦

The Pi is ok. I am refering to the SD-card that will degrade over time. Also Iā€™ve seen some corrupted SD-cards after a power failure (been using Piā€™s since the Pi 1).

Maybe I should ask elsewhere on the forum but please point me to the main advantages /disadvantages/differences of having the Pi configured with 1: Raspberry and home assistant app, 2: Haspberry, and, as I have it now, 3: with Hassio

With Hassio I miss the Raspberry desktop , I would like to explore too ā€¦ or can i ssh into the Hassio-Pi to do that alsoā€¦

Sorryā€¦
Marius