Coder Social home page Coder Social logo

asyncio-vedirect-mqtt's Introduction

asyncio-vedirect-mqtt

This is a simple program for publishing serial data from the Victron VE.Direct protocol to an mqtt broker in an asynchronous manner.

The data is published according to the Home Assistant MQTT Discovery specification. This allows the device to be auto-discovered in home assistant.

Currently, the program is set up for use with SmartSolar devices. Adding more devices is possible (pull requests accepted).

This is done using changyuheng/aioserial to read the serial data and passing it through to an async implementation of karioja/vedirect to decode the data. This is then sent over MQTT to a broker of your choice via sbtinstruments/asyncio-mqtt.

The implementation supports TLS and authentication when connecting to the MQTT server.

Getting started:

Install the latest wheel package from the releases tab or download from git with pip.

pip3 install git+https://github.com/metrafonic/asyncio-vedirect-mqtt.git

NOTE: Installing the pre-built wheel (as opposed to git install via pip) is recommended as it saves a significant amount of space.

This will add the ve-mqtt executable to ~/.local/bin.

Run the code:

$ ve-mqtt -h
Welcome to asyncio_vedirect_mqtt v1.1.3
usage: ve-mqtt [-h] --tty TTY [--windowing WINDOWING] --device DEVICE [-v] [--timeout TIMEOUT] --broker BROKER [--port PORT] [--username USERNAME] [--password PASSWORD] [--mqttretry MQTTRETRY] [--tls] [--tls1.2] [--ca_path CA_PATH]

Async implementation of ve.direct to mqtt

optional arguments:
  -h, --help            show this help message and exit
  --tty TTY             Serial port with incoming ve.direct data
  --windowing WINDOWING
                        How many values should be included in the sliding moving average
  --device DEVICE       Unique name of the device
  -v, --verbose         Run with verbose logging
  --timeout TIMEOUT     Serial port read timeout
  --broker BROKER       MQTT broker hostname
  --port PORT           MQTT broker port
  --username USERNAME   MQTT broker username
  --password PASSWORD   MQTT broker password
  --mqttretry MQTTRETRY
                        MQTT broker reconnect timeout interval
  --tls                 Use TLS for MQTT communication
  --tls1.2              Use TLS version 1.2 for MQTT communication
  --ca_path CA_PATH     Custom TLS CA path

System service

Add the following to /lib/systemd/system/ve-mqtt.service:

[Unit]
Description=VE.Direct over MQTT
After=multi-user.target

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

[Install]
WantedBy=multi-user.target

Remember to replace the arguments with your own variables.

Also replace the username and group in the [Service] section to the user that installed and is capable of running the ve-direct software

Reload and start the service:

sudo systemctl daemon-reload
sudo systemctl enable ve-mqtt
sudo systemctl start ve-mqtt

Development:

Sending test data is easy using socat:

socat -d -d PTY,raw,echo=0,link=/tmp/vmodem0 PTY,raw,echo=0,link=/tmp/vmodem1
cat tests/smartsolar_1.39.dump > /tmp/vmodem0

Data will now be available at /tmp/vmodem1

Credits

asyncio-vedirect-mqtt's People

Contributors

metrafonic avatar nellicuslabs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

asyncio-vedirect-mqtt's Issues

MQTT Reconnect

Any chance you will be adding the functionality to reconnect to MQTT when the connection is lost?

Error when trying to set as system service

Hi!

First of all, thank you for the devolpment, I found it very usefull.

I have a problem setting the ve-mqtt as system service. This is my ve-mqtt service:
[Unit]
Description=VE.Direct over MQTT
After=multi-user.target

[Service]
Type=simple
ExecStart=ve-mqtt --tty /dev/serial0 --device BlueSolar-TEST --broker 10.10.10.114 --port 1883 --username mqtt_user -->Restart=on-failure
RestartSec=5s

[Install]
WantedBy=multi-user.target

It gives me error 203, but it works when I do it manually. Any ideas?

Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.