diff --git a/.gitignore b/.gitignore index 7a125d6..ca55ac0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ *.pyc -home-assistant-core \ No newline at end of file +home-assistant-core +/.vs diff --git a/README.md b/README.md index 09cd7fd..6568d8e 100644 --- a/README.md +++ b/README.md @@ -49,7 +49,9 @@ be done trivially, I believe. In order to not duplicate logic, the script uses the InfluxDB component of Home Assistant directly. -I've tested this on Ubuntu 18.04 with Python 3.7. +Tested on +- Ubuntu 18.04 with Python 3.7. +- Ubuntu 20.04.1 LTS with Python 3.8.5 Setup: 1. `sudo apt install python3 python3.7-dev` @@ -60,11 +62,17 @@ Setup: Dependency installation: 1. `. .venv/bin/activate` -2. `pip install -r home-assistant-core/requirements.txt` -3. `pip install -r requirements.txt` +2. `pip install -r requirements.txt` +3. `pip install -r home-assistant-core/requirements.txt` + +For MySQL +1. `sudo apt install libmysqlclient-dev` + +For MariaDB +1. `sudo apt install libmariadbclient-dev` Run script: -1. Copy your InfluxDB configuration from Home Assistant to influxdb.yaml. +1. Use and edit the provided influxdb.yaml example OR copy your InfluxDB configuration from Home Assistant to influxdb.yaml. This should be the file that you include via `influxdb: !include influx.yaml` in your installation (i.e. it does not start with `influxdb:\n`!). It must not include any !secret statements but rather the token (for v2) diff --git a/homeassistant2influxdb.py b/homeassistant2influxdb.py index 93b574a..f330835 100755 --- a/homeassistant2influxdb.py +++ b/homeassistant2influxdb.py @@ -72,9 +72,12 @@ def main(): parser.add_argument('--host', '-s', dest='host', action='store', required=True, help='MySQL/MariaDB host') + parser.add_argument('--port', '-o', + dest='port', action='store', required=True, + help='MySQL/MariaDB host') parser.add_argument('--database', '-d', - dest='database', action='store', required=True, - help='MySQL/MariaDB database') + dest='database', action='store', required=false, type=int, default=3306, + help='MySQL/MariaDB port. MySQL 3306 (default), MariaDB 3307') parser.add_argument('--count', '-c', dest='row_count', action='store', required=False, type=int, default=0, help='If 0 (default), determine upper bound of number of rows by querying database, ' @@ -95,7 +98,7 @@ def main(): converter = _generate_event_to_json(influx_config) # connect to MySQL/MariaDB database - connection = mysql_connect(host=args.host, user=args.user, password=args.password, database=args.database, cursorclass=cursors.SSCursor, charset="utf8") + connection = mysql_connect(host=args.host, port=args.port, user=args.user, password=args.password, database=args.database, cursorclass=cursors.SSCursor, charset="utf8") cursor = connection.cursor() # untested: connect to SQLite file instead (you need to get rid of the first three `add_argument` calls above) diff --git a/influxdb.yaml b/influxdb.yaml new file mode 100644 index 0000000..aff0d5a --- /dev/null +++ b/influxdb.yaml @@ -0,0 +1,4 @@ +# This is your influx configuration from home assistant. Note the two indents before each line! + host: localhost + port: 8086 + database: home_assistant \ No newline at end of file