Mon Compteur bridges the output from a French Linky electricity meter to Home Assistant via MQTT. With Mon Compteur your real time electricity use appears in Home Assistant as a grid power source.

Linky is the name of the latest electricity meters installed by Enedis (formally ERDF) in France. The Linky device includes a serial port, which outputs the meter’s current state and account information. This software, Mon Compteur, understands the format of Linky’s output and converts it into a format suitable for inclusion into Home Assistant and other MQTT aware software.

Required Hardware

Mon Compteur requires a hardware adapter to connect the host computer to the Linky serial port. Any adapter that can present the output of the Linky serial port as a serial device on your computer should work.

Charles Hallard offers a range of adapters at reasonable prices.

Required Software

Mon Compteur needs an MQTT service to connect and write to. I use Eclipse Mosquitto. This message queuing service acts as the go between for Home Assistant and Mon Compteur’s output.

An MQTT integration is available for Home Assistant and widely used.

Mon Compteur produces MQTT output intended for Home Assistant’s MQTT integration. This allows for auto-discovery of Mon Compteur in Home Assistant.

Using moncompteur

To get started with Miln Mon Compteur, download and expand the executable file onto your computer.

Mon Compteur is a single executable file. It does not need to be installed, can be run from any directory, and can be removed by deleting the file.

Let’s walk through an example use of moncompteur. Consider this command line call:

./moncompteur -mqtt 'mqtt://192.168.1.5:1883' -tty /dev/ttyUSB1

The flags for this call to moncompteur are:

-mqtt 'mqtt://192.168.1.5:1883'
The MQTT service to connect and write to.
-tty /dev/ttyUSB1
The path to the serial port in the file system.

Once launched, moncompteur will run until receiving a terminate signal.

Output is deliberately limited to avoid causing excessive read and writes to the boot drive. If more detail is needed, pass the -verbose flag.

Why I wrote this tool

I wrote Mon Compteur because I wanted something simple to install and manage. Other software exists for this task but nothing as singular in scope and form. I also enjoy working with esoteric encodings and formats, and this tool does exactly that.

Having real time electricity use in Home Assistant has been great. We have been able to better understand our household power use and track down a few items that had unexpected consumption patterns.

Flags

moncompteur accepts the following command line flags:

Usage of ./moncompteur:
  -config string
    	File path to configuration.
  -device-id string
    	optional unique identifier for the device
  -h	Show this help message and exit. (shorthand)
  -help
    	Show this help message and exit.
  -l string
    	Directory path to licence certificate files (PEM encoded) (shorthand) (default "~/.miln/")
  -legal
    	Show legal notices and exit.
  -licence string
    	Directory path to licence certificate files (PEM encoded) (default "~/.miln/")
  -mqtt string
    	url to MQTT broker to write to (default "mqtt://localhost:1883")
  -show-licence
    	Show licence details and exit.
  -tty string
    	path to TTY device to read from (default "/dev/ttyUSB0")
  -v	Show version details and exit. (shorthand)
  -verbose
    	increase logging verbosity
  -version
    	Show version details and exit.

Launch on Boot with systemd

Mon Compteur can be managed by Linux’s systemd by creating the following text file at /etc/systemd/system/moncompteur.service:

[Unit]
Description=moncompteur
After=network.target

[Service]
Type=simple
StandardOutput=inherit
StandardError=inherit
ExecStart=/home/pi/moncompteur -mqtt 'mqtt://192.168.1.5:1883' -tty /dev/ttyUSB1
User=pi

[Install]
WantedBy=multi-user.target

For the above service to work, you must change:

Once created, the systemd service can be enabled, started, and inspected with these commands:

sudo systemctl enable moncompteur.service
sudo systemctl start moncompteur.service
sudo systemctl status moncompteur.service

Download

Latest downloads for Miln Mon Compteur.

Legal

Legal notices associated with Mon Compteur.