Skip to content

Connect your Smart Meter to Home Assistant (MQTT)

In this tutorial, I explain how to link your smart meter via MQTT to Home Assistant. First, make sure you have an MQTT broker installed. You can read how to do this here.

What do you need for Home Assistant to read the smart meter with MQTT?

To connect your smart meter to Home Assistant with MQTT, you need a Smart Meter WiFi Gateway. The gateway can be ordered here. (Click on the picture to go to the Smart Meter WiFi Gateway product page).

What are the benefits of MQTT?

The advantage of MQTT over the telnet connection, for example, is that the gateway checks the messages for correctness. In fact, your meter sends a CRC checksum after every telegram. This is the outcome of a set calculation that the smart meter calculates based on the telegram sent. The gateway knows this calculation and also calculates the outcome itself based on the data received from the smart meter. If both results are the same, then the telegram arrived correctly. If there is a difference between these results, then the CRC check failed and the gateway ignores the telegram. So this way you keep your home assistant clean of incorrect meter readings. This is the preferred method.

Determining the Interval

You can also use MQTT by reducing the interval at which the gateway sends data to your broker. Smart Meters send a telegram every second. This can be very stressful for Home Assistant so it is sometimes necessary to reduce the interval. By default, the gateway sends an update every 10 seconds even though your meter sends one every second. You can change the interval to your needs in the web portal of your gateway.

More stable

Above, for example, using telnet to connect your Smart Meter to Home Assistant, MQTT is also a lot more stable. By error checking and lowering the interval, Home Assistant is not unnecessarily burdened. It may also be that due to poor wifi connection Home Assistant often tries to reconnect to the gateway’s built-in telnet server. The telnet server can handle up to 7 sessions. If a session is disconnected due to, for example, a restart of Home Assistant or loss of the wifi connection, the gateway is reconnected. After 7 sessions, the gateway will have to be manually restarted because all telnet sessions are in use.

Hourly consumption also visible

By using the Smart Meter Gateway via mqtt, you can also view hourly electricity and gas usage. The gateway itself calculates the correct values so you don’t have to do any calculations yourself within Home Assistant. Pretty convenient isn’t it!

Connecting your Smart Meter Gateway to Home Assistant by MQTT

First, login to your gateway and go to the MQTT menu.

Fill in the following fields:

  • MQTT SERVER: ip address of your mqtt broker (probably the ip address of your raspberry pi running home assistant)
  • MQTT SERVER PORT: the port number of your mqtt broker (default is 1883).
  • MQTT USERNAME: the user you created on your mqtt broker.
  • MQTT PASSWORD: the associated password.
  • MQTT INTERVAL: the interval (in seconds) at which the gateway sends updates to your broker. If you fill in nothing, this is 10. Allows you to limit how often the gateway sends updates to Home Assistant
  • MQTT PREFIX: the pre-run topic you can use. This is for advanced users only. Most users do not have to fill in anything here

Once completed, the gateway will connect to your mqtt broker and send data at the interval you set.

How do I know if the broker’s connection to the broker was established correctly and the data arrives correctly?

You can connect to your mqtt broker yourself by using the program MQTT Explorer. MQTT Explorer is available for download here.

If you have installed MQTT Explorer you first need to establish a connection to your mqtt broker. Select the “+” to add a new connection. The screen then looks something like this:

If you have completed everything, press CONNECT.

The following screen is displayed. Here you can see all the information (mqtt topics) that your broker handles. If all goes well, you will also see the dsmr topic and the smart_gateways topic here. By selecting the arrows in front of the topic, you can display all the data the gateway sends to your broker.

At the bottom of the screen you will see a graph of the latest meter readings. Selecting another topic shows the graph of the selected topic. So this is a good check to see if your gateway is communicating properly with your MQTT broker.

How can I display meter readings in Home Assistant?

Just follow this manual to make a beautiful dashboard!