Skip to content
This repository was archived by the owner on Jun 27, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*~
*.pyc
home-assistant-core
home-assistant-core
/.vs
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions homeassistant2influxdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,

@dseifert dseifert Dec 28, 2020

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mixed up port and database here: required, int, 3306 and help text changes belong to the new lines 76/77 (for port)

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, '
Expand All @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions influxdb.yaml
Original file line number Diff line number Diff line change
@@ -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