Skip to content

Commit

Permalink
add documentation about config file for essmqtt
Browse files Browse the repository at this point in the history
  • Loading branch information
gluap committed May 30, 2020
1 parent 4d784fd commit fc13e60
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
24 changes: 20 additions & 4 deletions README.rst
Expand Up @@ -87,7 +87,7 @@ To connect your ESS with an mqtt server run the following in your venv::

essmqtt --mqtt_server=<your_mqtt_server> --mqtt_user <your_mqtt_username> --mqtt_password <your_mqtt_password> --ess_password <your_ess_password>

Your ESS will show up in /ess/# on mqtt.
Your ESS will show up in ``ess/#`` on mqtt.

Available values to control the ess (write true/false) **Remember that this is an MIT-Licensed software and I take no responsibility for the usage of this library. That being said I send the same commands the app would send to trigger these actions to my best knowledge.**::

Expand Down Expand Up @@ -169,23 +169,36 @@ I use ``mosquitto_sub`` to find the values I'm interested in while debugging lik
mosquitto_sub -v -h <your_mqtt_server> -p 1883 -u <your_mqtt_user> -P <your_mqtt_password> -t "#"


Configuring essmqtt with a config file
......................................

To permanently configure essmqtt you can create a config file in either ``/etc/essmqtt.conf`` or ``~/essmqtt.conf``
of the user running ``essmqtt`` or you can specify which config file to load by using the argument ``--config_file``.
The config file can contain any of the command line arguments. Example::

ess_password = <your_ess_password>
mqtt_server = <your_mqtt_server>
mqtt_user = <your_mqtt_username>
mqtt_password = <your_mqtt_password>

essmqtt as systemd service
..........................
To set up ``essmqtt`` as a daemon (systemd service) it is recommended to install it in a venv first::

python3.7 -m venv <path_to_venv>
<path_to_venv>/bin/pip install pyess

from then on ``essmqtt`` can be called via <path_to_venv>/bin/essmqtt.
from then on ``essmqtt`` can be called via ``<path_to_venv>/bin/essmqtt``.

A systemd service file ``/etc/systemd/system/essmqtt.service`` could look like so::

[Unit]
Description=ESS MQTT wrapper

[Service]
# all essmqtt command line arguments can be used here.
ExecStart=<path_to_venv>/bin/essmqtt --mqtt_server=<MQTT SERVER IP> --ess_password <PW> --interval_seconds <POLL INTERVALL> --mqtt_user <MQTT_USER> --mqtt_passwort <MQTT_PASSWORD>
# all essmqtt command line arguments can be used here. it is recommended to configure essmqtt in a config file
# for this use case
ExecStart=<path_to_venv>/bin/essmqtt
# Restart will keep the service alive for instance in case the mqtt server goes down or isn't up yet
# when esmqqt starts
Restart=on-failure
Expand All @@ -212,6 +225,9 @@ be accessed via the EnerVu App.
Changelog
=========

**2020-05-30 0.1.7**
- add config file

**2020-05-30 0.1.6**
- repair crash introduced with 0.1.5

Expand Down
9 changes: 7 additions & 2 deletions pyess/essmqtt.py
@@ -1,4 +1,4 @@
import argparse
import configargparse
import asyncio
import logging
import sys
Expand Down Expand Up @@ -62,7 +62,12 @@ def main(arguments=None):


async def _main(arguments=None):
parser = argparse.ArgumentParser(prog='pyess', description='Command line interface for pyess')

parser = configargparse.ArgumentParser(prog='essmqtt', description='Mqtt connector for pyess',
add_config_file_help=True,
default_config_files=['/etc/essmqtt.conf', '~/.essmqtt.conf'],
args_for_setting_config_path=["--config_file"],)

parser.add_argument(
'--loglevel', default='info', help='Log level',
choices=['debug', 'info', 'warning', 'error', 'critical'],
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -22,7 +22,7 @@
packages=['pyess'],

install_requires=[
'zeroconf', 'requests', 'graphyte', 'aiohttp', 'asyncio-mqtt>=0.3.0'
'zeroconf', 'requests', 'graphyte', 'aiohttp', 'asyncio-mqtt>=0.3.0', 'ConfigArgParse'
],

zip_safe=False,
Expand Down

0 comments on commit fc13e60

Please sign in to comment.