Telegraf / Grafana – Smart Meter

Netherlands supports various “smart” gateways which support a P1 port for actual data discovery of electricity and gas consumption. This post will post actual references and details to configure this in Telegraf/InfluxDB for use in Grafana.

 

Step 1: Reference

The Smart Gateway solution is available form https://smartgateways.nl/ and provides support for Electricity, Gas and Water meters. Visit the actual support section for references, details, updates and documentation. There is specifically a section on Grafana which I used to setup my solution.

Step 2: High Level Overview

Following the procedures make sure that the gateway has an appropriately configured IP address on the WIFI network.

 

  • Smart Gateway feeds information into Mosquitto (MQTT)
  • Telegraf polls information from Mosquitto
  • Telegraf stores information into InfluxDB
  • Grafana presents visual data

 

 

 

 

Step 2: Install Mosquitto

Previous blog entries have already described the deployment of Grafana, InfluxDB and Telegraf. Make sure to now install Mosquitto which uses the same repository as InfluxDB:

# apt install -y mosquitto

Edit the Mosquitto configuration file /etc/mosquitto/mosquitto.conf and make sure that authentication is enabled, port is set and log file for output is defined:

# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

pid_file /run/mosquitto/mosquitto.pid

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

listener 1883
log_type error
log_type warning
log_type notice
log_type information
connection_messages true
log_timestamp true
allow_anonymous false
password_file /etc/mosquitto/passwd

Generate a new password file with account information:

# touch /etc/mosquitto/passwd
# mosquitto_passwd -b /etc/mosquitto/passwd mosquitto <password-to-be-defined>

Enable and start the Mosquitto service:

# systemctl enable mosquitto
# systemctl restart mosquitto

Step 3: Telegraf

Create a telegraf configuration file for the Mosquitto input by creating /etc/telegraf/telegraf.d/telegraf-input-smartmeter.conf

[[inputs.mqtt_consumer]]
name_override = "electricity"
servers = ["tcp://localhost:1883"]
username = "mosquitto"
password = "<passworddefinedinprevioussection>"
topics = [
  "dsmr/reading/electricity_delivered_1",
  "dsmr/reading/electricity_returned_1",
  "dsmr/reading/electricity_delivered_2",
  "dsmr/reading/electricity_returned_2",
  "dsmr/reading/electricity_currently_delivered",
  "dsmr/reading/electricity_currently_returned",
  "dsmr/reading/phase_currently_delivered_l1",
  "dsmr/reading/phase_currently_delivered_l2",
  "dsmr/reading/phase_currently_delivered_l3",
  "dsmr/reading/phase_currently_returned_l1",
  "dsmr/reading/phase_currently_returned_l2",
  "dsmr/reading/phase_currently_returned_l3",
  "dsmr/reading/phase_voltage_l1",
  "dsmr/reading/phase_voltage_l2",
  "dsmr/reading/phase_voltage_l3",
  "dsmr/reading/phase_power_current_l1",
  "dsmr/reading/phase_power_current_l2",
  "dsmr/reading/phase_power_current_l3",
  "dsmr/reading/electricity_hourly_usage"
]
data_format = "value"
data_type = "float"

[[inputs.mqtt_consumer]]
name_override = "dsrm"
servers = ["tcp://localhost:1883"]
username = "mosquitto"
password = "<passworddefinedinprevioussection>"
topics = [
  "dsmr/reading/electricity_equipment_id",
  "dsmr/reading/electricity_tariff",
  "dsmr/reading/gas_equipment_id"
]
data_format = "value"
data_type = "string"

[[inputs.mqtt_consumer]]
name_override = "gas"
servers = ["tcp://localhost:1883"]
username = "mosquitto"
password = "<passworddefinedinprevioussection>"
topics = [
  "dsmr/reading/gas_hourly_usage",
  "dsmr/consumption/gas/delivered"
  
]
data_format = "value"
data_type = "float"

[[inputs.mqtt_consumer]]
name_override = "water"
servers = ["tcp://localhost:1883"]
username = "mosquitto"
password = "<passworddefinedinprevioussection>"
topics = [
  "watermeter/reading/current_value",
  "watermeter/reading/pulse_factor",
  "watermeter/reading/pulse_count"
]
data_format = "value"
data_type = "int"

Restart the Telegraf:

# systemctl restart telegraf

Once Telegraf is restarted you should view its connection in the Mosquitto log file /var/log/mosquitto/mosquitto.log

1672335661: mosquitto version 2.0.11 starting
1672335661: Config loaded from /etc/mosquitto/mosquitto.conf.
1672335661: Starting in local only mode. Connections will only be possible from clients running on this machine.
1672335661: Create a configuration file which defines a listener to allow remote access.
1672335661: For more details see https://mosquitto.org/documentation/authentication-methods/
1672335661: Opening ipv4 listen socket on port 1883.
1672335661: Opening ipv6 listen socket on port 1883.
1672335661: mosquitto version 2.0.11 running
1672336918: mosquitto version 2.0.11 terminating
1672336918: Saving in-memory database to /var/lib/mosquitto//mosquitto.db.
1672336918: mosquitto version 2.0.11 starting
1672336918: Config loaded from /etc/mosquitto/mosquitto.conf.
1672336918: Opening ipv4 listen socket on port 1883.
1672336918: Opening ipv6 listen socket on port 1883.
1672336918: mosquitto version 2.0.11 running
1672337080: New connection from ::1:48248 on port 1883.
1672337080: New client connected from ::1:48248 as Telegraf-Consumer-8lUQN (p2, c1, k60, u'mosquitto').

Step 4: Smart Gateway (Electric/Gas) Configuration

Make sure the Smart Gateway (Electric/Gas) is configured and attached to your WiFI network (quick overview). Follow instructions provided by the vendor, below is a quick reference:

  • Once Smart Gateway is booted for first time, screen will show that you can connect to http://192.168.4.1
  • Connect to the Access Point created by the Smart Gateway normally called [Smar Gateways P1 READER] use WiFI password [12345678]
  • Once connected, start browser and connect to http://192.168.4.1 -> Select Configuration and define your WiFI SSID and password to use.
  • Once completed the Smart Gateway will reboot, in my case had to force a reboot (power reset) to make sure it appropriately connected.

Once the Smart Gateway is connected to your WiFI network you need to post-configure it:

  • Connect to the Smart Gateway using http://<gateway-ip>:82
  • At the bottom of the screen there is a ‘Login’ button, use user [admin] and password [smartgateways]
  • Change the default password
  • Select the option [Change network and mqtt settings]
  • Configure MQTT
    • MQTT Server -> Mosquitto Server IP Address
    • MQTT Server Port -> 1883
    • MQTT USERNAME -> mosquitto
    • MQTT KEY -> password defined in previous steps in Mosquitto

Once these settings are configured and Smart Gateway has rebooted, MQTT will connect to Mosquitto and attempt to upload its information. You can follow this in the Mosquitto log file /var/log/mosquitto/mosquitto.log

1672446218: New connection from 192.168.200.45:65455 on port 1883.
1672446218: New client connected from 192.168.200.45:65455 as xxxxxxxxxxx (p2, c1, k90, u'mosquitto').

Step 5: Smart Gateway (Water) Configuration

Make sure the Smart Gateway (Water) is configured and attached to your WiFI network (quick overview). The post configuration of this device is identical to the other Gateway. Follow instructions provided by the vendor, below is a quick reference:

  • Once Smart Gateway is booted for first time, screen will show that you can connect to http://192.168.4.1
  • Connect to the Access Point created by the Smart Gateway normally called [SmartGateways WATERMETER] use WiFI password [12345678]
  • Once connected, start browser and connect to http://192.168.4.1 -> Select Configuration and define your WiFI SSID and password to use.
  • Once completed the Smart Gateway will reboot, in my case had to force a reboot (power reset) to make sure it appropriately connected.

Once the Smart Gateway is connected to your WiFI network you need to post-configure it:

  • Connect to the Smart Gateway using http://<gateway-ip>:82
  • At the bottom of the screen there is a ‘Login’ button, use user [admin] and password [smartgateways]
  • Change the default password
  • Select the option [Change network and mqtt settings]
  • Configure MQTT
    • MQTT Server -> Mosquitto Server IP Address
    • MQTT Server Port -> 1883
    • MQTT USERNAME -> mosquitto
    • MQTT KEY -> password defined in previous steps in Mosquitto
    • WATERMETER FACTOR -> define if the wheel turns once for 1L (1) or once for 10L (10).

Once these settings are configured and Smart Gateway has rebooted, MQTT will connect to Mosquitto and attempt to upload its information. You can follow this in the Mosquitto log file /var/log/mosquitto/mosquitto.log

1672446218: New connection from 192.168.200.45:65455 on port 1883.
1672446218: New client connected from 192.168.200.45:65455 as xxxxxxxxxxx (p2, c1, k90, u'mosquitto').

Step 6: Grafana Dashboard

The Grafana dashboard is available from GitHub: https://github.com/ucomesdag/gwe-dashboard/blob/main/dashboard.json

Step 7: Home Assistant

As we are currently pushing the MQTT data to Mosquitto, we cannot push the same data to Home Assistant. So we are using the telnet option to configure this data. See Smart Meter web site for more information.