Hi @ linisgre
Thanks for sharing your script. I hope you could answer to a couple of questions I have:
Does the script respect the include: entities: property from the yaml file? Or will it migrate all entities data to influxdb? By having a look at the code, i think it does only migrate the entities included in the yaml file.
In my case, I am already running the influxdb integration. Am I supposed to disable the integration and delete data from influxdb before running the script. Or can I run it anyway, and it will take care of âmergingâ historical data with the data already present on influxdb?
The script itself does nothing with the influx.yaml, it does not even access InfluxDB itself, thatâs purely handled via the code in HA. I donât recall whether it is so, but I believe that this means it will honor the include lines, i.e. only port the stuff given there.
In my case I did it with a clean conversion. The script itself will not handle any merging. I donât know whether the code in HA will check duplicates, but I doubt it. What you could do is check your InfluxDB for the date of the earliest element, and adjust the query in the script to only include data before that timestamp.
I tried the script for SQLite and core_2021.11.2.
I used debian and python 3.9.
I have errors, I assume they are related to elements in the home-assistant_v2.db which are not accepted (anymore?).
These are the errors:
python homeassistant2influxdb.py
Traceback (most recent call last):
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/homeassistant2influxdb.py", line 190, in <module>
main()
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/homeassistant2influxdb.py", line 91, in main
influx_config = schema(influx_config)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
return self._compiled([], data)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/validators.py", line 215, in _run
return self._exec(self._compiled, value, path)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/validators.py", line 341, in _exec
raise e if self.msg is None else AllInvalid(self.msg, path=path)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/validators.py", line 339, in _exec
v = func(path, v)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 817, in validate_callable
return schema(data)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 272, in __call__
return self._compiled([], data)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 594, in validate_dict
return base_validate(path, iteritems(data), out)
File "/home/jo/Downloads/migrate2influxdb/migrate2influxdb/.venv/lib/python3.9/site-packages/voluptuous/schema_builder.py", line 432, in validate_mapping
raise er.MultipleInvalid(errors)
voluptuous.error.MultipleInvalid: extra keys not allowed @ data['influxdb']
Any suggestions on what is wrong or even better what can be done to solve the errors?
I have the same issue, noe sure how to fix. Any ideas?
Using MariaDB.
EDIT: Did som investigation and it seems like there is a bug somewhere between the current home-assistant-core and voluptous versions. This is using python 3.9. Same without anything in the influxdb.yaml
(.venv) root@homeassistant:/migrate2influxdb# python homeassistant2influxdb.py -h
Traceback (most recent call last):
File "/migrate2influxdb/homeassistant2influxdb.py", line 25, in <module>
from homeassistant.components.influxdb import get_influx_connection, _generate_event_to_json, INFLUX_SCHEMA
File "/migrate2influxdb/home-assistant-core/homeassistant/components/influxdb/__init__.py", line 34, in <module>
from homeassistant.helpers import event as event_helper, state as state_helper
File "/migrate2influxdb/home-assistant-core/homeassistant/helpers/state.py", line 12, in <module>
from homeassistant.components.sun import STATE_ABOVE_HORIZON, STATE_BELOW_HORIZON
File "/migrate2influxdb/home-assistant-core/homeassistant/components/sun/__init__.py", line 13, in <module>
from homeassistant.helpers.entity import Entity
File "/migrate2influxdb/home-assistant-core/homeassistant/helpers/entity.py", line 45, in <module>
from .entity_platform import EntityPlatform
File "/migrate2influxdb/home-assistant-core/homeassistant/helpers/entity_platform.py", line 15, in <module>
from homeassistant import config_entries
File "/migrate2influxdb/home-assistant-core/homeassistant/config_entries.py", line 17, in <module>
from .components import persistent_notification
File "/migrate2influxdb/home-assistant-core/homeassistant/components/persistent_notification/__init__.py", line 15, in <module>
from homeassistant.helpers.entity import async_generate_entity_id
ImportError: cannot import name 'async_generate_entity_id' from partially initialized module 'homeassistant.helpers.entity' (most likely due to a circular import) (/migrate2influxdb/home-assistant-core/homeassistant/helpers/entity.py)
The original repo for this script by dseifert has been archived.
I created a fork of it and updated it to match the current HA DB schema.
If you use option both for the argument tables itâll populate data to entities using statistics for days you do not have event data for.
You can find my fork of it here. If youâre reading this far in the future, please add an issue to the repo or make a pull request if the script is broken again.
i read the post but honestly iâm not very familiar with db, i have an installation of HA OS on a vm and i would like to copy all the data i have on the standard db of HA on influx and then clean HA, the script in question works on this type of installation?
Hi! I tried to use your script but got the following error:
(.venv) root@debian:~/migrate2influxdb# python homeassistant2influxdb.py -t sqlite -d home-assistant_v2.db
Warning: Could not load Mysql driver, might not be a problem if you intend to use sqlite
Migrating home assistant database statistics, states to Influx database home-assistant_v2.db and bucket Home Assistant
Traceback (most recent call last):
File "/root/migrate2influxdb/homeassistant2influxdb.py", line 358, in <module>
main()
File "/root/migrate2influxdb/homeassistant2influxdb.py", line 151, in main
cursor.execute(tmp_table_query)
sqlite3.OperationalError: near "SELECT": syntax error
Guys I getting some incompatability issues and thoughts (I have tried down grading conextfiler")
(.venv) pi@PiB:~/homeassistant2influxdb $ python homeassistant2influxdb.py --type SQLite --database home-assistant_v2.db
Traceback (most recent call last):
File âhomeassistant2influxdb.pyâ, line 6, in
from homeassistant.components.influxdb import get_influx_connection, _generate_event_to_json, INFLUX_SCHEMA
File â/home/pi/homeassistant2influxdb/.venv/lib/python3.7/site-packages/homeassistant/components/influxdb/init.pyâ, line 30, in
from homeassistant.helpers import event as event_helper, state as state_helper
File â/home/pi/homeassistant2influxdb/.venv/lib/python3.7/site-packages/homeassistant/helpers/event.pyâ, line 47, in
from homeassistant.helpers.template import RenderInfo, Template, result_as_boolean
File â/home/pi/homeassistant2influxdb/.venv/lib/python3.7/site-packages/homeassistant/helpers/template.pyâ, line 19, in
from jinja2 import contextfilter, contextfunction
ImportError: cannot import name âcontextfilterâ from âjinja2â (/home/pi/homeassistant2influxdb/.venv/lib/python3.7/site-packages/jinja2/init.py)
Are these related to python version issue that we reported earlier ?
homeassistant 2021.1.5 has requirement importlib-metadata==1.6.0; python_version < â3.8â, but youâll have importlib-metadata 6.7.0 which is incompatible.
homeassistant 2021.1.5 has requirement pyyaml==5.3.1, but youâll have pyyaml 6.0.1 which is incompatible.
homeassistant 2021.1.5 has requirement requests==2.25.0, but youâll have requests 2.31.0 which is incompatible.
homeassistant 2021.1.5 has requirement voluptuous==0.12.1, but youâll have voluptuous 0.13.1 which is incompatible.
Yeah, all these forks seem to be broken right now. They all fail to resolve dependencies successfully when you run âpip install -r home-assistant-core/requirements.txtâ