Connecting DDS238-2 Energy Meter to OpenHAB: A Step-by-Step Guide

Hi everyone,

I’ve recently completed a project to connect a DDS238-2 energy meter to my OpenHAB setup, and I wanted to share my experience in case it helps anyone else. This was a bit of a learning curve, but I ended up with a functional and affordable energy monitoring solution.

Setup Overview

I purchased the DDS238-2 meter from AliExpress for around €13.50, along with a RS485 to USB converter for about €4. The goal was to monitor my electricity usage in real-time and integrate it into my smart home ecosystem.

Installation Steps

  1. Hardware Setup

    • The first step was connecting the meter to the USB converter. This was straightforward, but I made sure to check the wiring to avoid any issues.
  2. Software Configuration

    • I installed the Modbus (2.x) binding in OpenHAB through the PaperUI. It’s important to ensure that the OpenHAB user has access to the /dev/ttyUSB0 port. If necessary, adding the user to the dialout group can help.
    • I also enabled Java access to the serial port by modifying the /etc/default/openhab2 file and restarting OpenHAB.
  3. Testing Communication

    • Before integrating into OpenHAB, I tested the communication using Python scripts. This helped confirm that the meter was accessible and responding correctly.
    • I used a Python script to read the meter’s registers, which was crucial for verifying the setup before moving to the OpenHAB configuration.
  4. OpenHAB Configuration

    • I added the Modbus bridge configuration to modbus.things, specifying the correct port, baudrate, and other parameters.
    • In modbus.items, I defined the necessary items to map the meter’s registers to OpenHAB channels. This included settings for total energy, voltage, current, and more.
    • A simple sitemap was created to display the meter’s data, making it easy to monitor from the OpenHAB interface.
  5. Persistence and Rules

    • To track energy consumption over time, I set up persistence using MySQL. This allows me to log changes in energy usage and calculate hourly, daily, weekly, and monthly consumption.
    • I created rules to update counters at specific times (e.g., hourly and daily), which helps in understanding energy usage patterns.

Challenges and Solutions

  • Serial Port Access: Initially, I faced issues with OpenHAB accessing the serial port. Adding the OpenHAB user to the dialout group resolved this.
  • Meter Identification: The meter’s default Modbus ID was 1, which caused conflicts when adding multiple meters. Using a Python script to change the ID was a simple fix.
  • Data Transformation: Some registers required transformation (e.g., dividing by 100 or 1000) to display correctly. I created custom transformation scripts for this purpose.

Results

After completing the setup, I now have real-time monitoring of my electricity usage. The integration with OpenHAB allows me to view energy consumption alongside other smart home metrics, providing a comprehensive overview of my home’s energy use.

Tips for Others

  • Test Communication First: Before configuring everything in OpenHAB, test the meter’s communication using a simple script. This can save a lot of troubleshooting time.
  • Understand Register Mapping: Spend time understanding which registers correspond to which data points. This ensures accurate readings and avoids confusion.
  • Use Persistence: Logging data over time provides valuable insights into energy usage patterns, which can help in optimizing consumption.

If anyone has questions or needs further clarification on any part of the setup, feel free to ask! I’m happy to help others replicate this project.

Best regards,
[Your Name]