metrafonic / victron-hass-mqtt

Python application for transmitting VE.Direct data to an mqtt server via the Home Assistant MQTT specification

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Victron HASS MQTT

⚠️ WARNING This version is no longer under development, see this project instead https://github.com/metrafonic/asyncio-vedirect-mqtt

Python application for transmitting VE.Direct data to an mqtt server via the Home Assistant MQTT specification to enable automatic device discovery

Hacked together based on code from:

Installation

Install via PIP:

pip3 install git+https://github.com/metrafonic/victron-hass-mqtt

This should place an entrypoint for the code at ~/.local/bin/victron-mqtt.

Ensure that ~/.local/bin/ is added to your PATH or use the full path when running the code

Usage:

usage: victron-mqtt [-h] --tty TTY --name NAME [--timeout TIMEOUT] [--window_size WINDOW_SIZE] [--broker BROKER] [--port PORT]
                    [--username USERNAME] [--password PASSWORD] [--tls] [--ca_path CA_PATH]

Process VE.Direct protocol

optional arguments:
  -h, --help            show this help message and exit
  --tty TTY             Serial port
  --name NAME           MQTT Identifier
  --timeout TIMEOUT     Serial port read timeout
  --window_size WINDOW_SIZE
                        Sliding window moving average
  --broker BROKER       MQTT broker address
  --port PORT           MQTT broker port
  --username USERNAME   MQTT broker port
  --password PASSWORD   MQTT password
  --tls                 Use tls
  --ca_path CA_PATH     TLS CA cert path (required if using TLS)

NOTE: The windowing function defaults to 60, meaning that it will wait for 60 messages per variable, and average them out before sending. This means that it will take up to 2 minutes for the first variables to appear in home-assistant.

System service

Add the following to /lib/systemd/system/victron.service: Remember to replace the arguments with your own variables

[Unit]
Description=Victron MQTT
After=multi-user.target

[Service]
Type=simple
ExecStart=victron-mqtt --name Mobile-1 --tty /dev/ttyAMA0 --broker xxxxx --port 8883 --username mqtt --password xxxxxxxxxx --tls
Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

Reload and start the service:

sudo systemctl daemon-reload
sudo systemctl enable victron
sudo systemctl start victron

About

Python application for transmitting VE.Direct data to an mqtt server via the Home Assistant MQTT specification


Languages

Language:Python 100.0%