Skip to content

SmartGateways.nl

shipped within a business day

14-day money backย guarantee

Customer review 4.9/5

Open standards

Connect your Smart Meter to Home Assistant (MQTT)

in deze instructie leg ik je uit hoe je je slimme meter kunt koppelen via MQTT aan Home Assistant. Zorg eerst dat je een MQTT broker hebt geรฏnstalleerd. Hoe je dit doet kun je hier lezen.

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

To read the smart meter with Home Assistant with MQTT, you need a Smart Meter WiFi gateway. Deze is hier verkrijgbaar. (Click on the picture to go to the Smart Meter WiFi gateway product page).

https://smartgateways.nl/slimme-meter-p1-dsmr-uitlezen/

What are the benefits of MQTT?

The advantage of MQTT over the telnet link, 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.

Determining the Interval

You can also use MQTT by reducing the interval at which the gateway sends data to your broker. SMR meters, in fact, 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.

More stable

Above, for example, the telnet variant of linking with the 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 wifi, you can also view hourly usage. The gateway itself calculates the correct values so you don’t have to do any calculations yourself within Home Assistant. Pretty convenient!

Linking smart meter gateway to Home Assistant via MQTT

The gateway with display must first be reset to factory defaults to access the configuration portal. To do this, press and release the little button at the bottom right of the display for 10 seconds. The reset screen is displayed. After the gateway reboots, it is possible to connect to the wifi network that the gateway transmits. Enter the comsetting and baud rate associated with your meter. For DSMR2, this is 9600 / 7E1. The higher versions use 115200 / 8N1.

Users with the gateway without the Advanced display can press the button to activate the portal. The CONNECTIX P1 READER wifi network is broadcast and accessible at http://192.168.4.1

You can then enter the MQTT data in the portal

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?

Once you have completed the above steps, you can begin creating the various dashboards within Home Assistant. Home Assistant already has a standard integration that displays all values. To do this, you need to modify the configuration.yaml with the following:

# Sample configuration Connectix Smart Meter WiFi Gateway
sensor:
  - platform: dsmr_reader
  - platform: mqtt
  name: "Gas consumption per hour"
  state_topic: "dsmr/reading/gas_hourly_usage"
  unit_of_measurement: 'm3'
  - platform: mqtt
  name: "Electricity consumption per hour"
  state_topic: "dsmr/reading/electricity_hourly_usage"
  unit_of_measurement: 'kW'

The first line (- platform: dsmr_reader) is basically sufficient to create the meter readings as sensors within Home Assistant via MQTT. The remaining 2 – platform:mqtt sensors are for hourly consumption. Optionally, you can also add the following topic to create a notification if a firmware update is available. Indeed, the topic smart_gateways/update_available changes from false to true if a firmware update is available for the smart meter wifi gateway. So this way you don’t have to keep an eye on the gateway’s screen.

If you modified the configuration.yaml, you need to restart Home Assistant. This is necessary to visualize the sensors for the smart meter.

For example, after Home Assistant is restarted, you can display the current power consumption on the dashboard. You do this by creating the following card:

Name: Current Energy Consumption
severity:
  green: 750
  red: 1500
  yellow: 1100
type: gauge
entity: sensor.dsmr_reading_electricity_currently_delivered
min: 200
max: 4000

This looks graphically as follows:

You can also display the hourly consumption for gas and electricity:

You do this by using the following text when creating a Vertical Stack Card, for example:

type: vertical-stack
cards:
  - type: sensor
  entity: sensor.electricity consumption_per_hour
  graph:line
  name: Electricity consumption / hour
  unit: kW
- type: sensor
  entity: sensor.gas consumption_per_hour
  graph:line
  name: Gas consumption / hour
  unit: m3

This looks graphically as follows:

Of course, you can add more to the dashboard. All smart meter sensors start with “sensor.dsmr_reading”. So you can put together a nice dashboard yourself at will.