Skip to content

This program reads the information from a Dutch Smart Electricity/Gas usage meter and publishes the results to an MQTT topic. It is configured via a single YAML file and leans heavily on the dsmr_parser library from Nigel Dokter (Github).

License

Notifications You must be signed in to change notification settings

freekvh/dsmr-mqtt-wrapper

Repository files navigation

dsmr-mqtt-wrapper

This program is intended to run on a Raspberry Pi attached to a Dutch smart electricity/gas meter with a P1 cable. It receives the data and publishes the selected information to an MQTT topic. It is configured via a single YAML file and leans heavily on the dsmr_parser library from Nigel Dokter (https://github.com/ndokter/dsmr_parser).

Installation

Optionally create a virtual environment and enter it, on Raspbian do;

sudo apt-get install python3-venv

python3 -m venv ~/.venv/dsmr-mqtt-wrapper

source ~/.venv/dsmr-mqtt-wrapper/bin/activate

pip3 install wheel

Clone this git repository

git clone https://gitlab.com/freekvh/dsmr-mqtt-wrapper.git

Enter the cloned directory and install the program and its dependencies

cd dsmr-mqtt-wrapper

pip install .

Configuration

In the config.yaml file, change the value for mqtt_broker_address to the address of your mqtt broker. This should be all you have to change if you have not configured a user/password or encryption. You can use the mqtt broker build into Home Assistant but it is deprecated (https://www.home-assistant.io/integrations/mqtt/). It is better to run a standalone broker like mosquitto, easyly installed in hass.io or using docker (compose).

List all the values that you want to publish via mqtt under values_of_interest:".

Add a line in the crontab so that the script starts at boot, if you cloned this repo to the home directory of the pi user (/home/pi), add the following line:

@reboot /bin/bash -c 'cd $HOME/dsmr-mqtt-wrapper && source $HOME/.venv/dsmr-mqtt-wrapper/bin/activate && ./dsmr-mqtt-wrapper.py' > /dev/null 2>&1

Alternatively, copy the file dsmr-mqtt-wrapper.service to /etc/systemd/system

sudo cp dsmr-mqtt-wrapper.service /etc/systemd/system

enable the service (start on boot)

sudo systemctl enable dsmr-mqtt-wrapper.service

and start it

sudo systemctl start dsmr-mqtt-wrapper.service

Configuring Home Assistant

By adding the following lines to your Home Assistant configuration.yaml the smart meter values can be read:

mqtt:
  broker: mqtt_broker_address

sensor:
  - platform: mqtt
    name: "Current usage"
    state_topic: "home/smart_meter/CURRENT_ELECTRICITY_USAGE"
    unit_of_measurement: 'kW'
    device_class: 'power'
    state_class: 'measurement'

  - platform: mqtt
    name: "Electricity used"
    state_topic: "home/smart_meter/ELECTRICITY_USED_TARIFF_ALL"
    unit_of_measurement: 'kWh'
    state_class: 'measurement'
    device_class: 'energy'

  - platform: mqtt
    name: "Gas consumed"
    state_topic: "home/smart_meter/HOURLY_GAS_METER_READING"
    unit_of_measurement: 'm3'
    state_class: 'measurement'

About

This program reads the information from a Dutch Smart Electricity/Gas usage meter and publishes the results to an MQTT topic. It is configured via a single YAML file and leans heavily on the dsmr_parser library from Nigel Dokter (Github).

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages