diff --git a/README.rst b/README.rst index fb339c8..ad3bf24 100644 --- a/README.rst +++ b/README.rst @@ -87,7 +87,7 @@ To connect your ESS with an mqtt server run the following in your venv:: essmqtt --mqtt_server= --mqtt_user --mqtt_password --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.**:: @@ -169,6 +169,18 @@ I use ``mosquitto_sub`` to find the values I'm interested in while debugging lik mosquitto_sub -v -h -p 1883 -u -P -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 = + mqtt_server = + mqtt_user = + 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:: @@ -176,7 +188,7 @@ To set up ``essmqtt`` as a daemon (systemd service) it is recommended to install python3.7 -m venv /bin/pip install pyess -from then on ``essmqtt`` can be called via /bin/essmqtt. +from then on ``essmqtt`` can be called via ``/bin/essmqtt``. A systemd service file ``/etc/systemd/system/essmqtt.service`` could look like so:: @@ -184,8 +196,9 @@ A systemd service file ``/etc/systemd/system/essmqtt.service`` could look like s Description=ESS MQTT wrapper [Service] - # all essmqtt command line arguments can be used here. - ExecStart=/bin/essmqtt --mqtt_server= --ess_password --interval_seconds --mqtt_user --mqtt_passwort + # all essmqtt command line arguments can be used here. it is recommended to configure essmqtt in a config file + # for this use case + ExecStart=/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 @@ -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 diff --git a/pyess/essmqtt.py b/pyess/essmqtt.py index 100ac1a..a886e12 100644 --- a/pyess/essmqtt.py +++ b/pyess/essmqtt.py @@ -1,4 +1,4 @@ -import argparse +import configargparse import asyncio import logging import sys @@ -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'], diff --git a/setup.py b/setup.py index 5f18b4d..23d7043 100755 --- a/setup.py +++ b/setup.py @@ -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,