You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Port: 3306 (default - In case the Home Assistant add-on is used, verify that the port is exposed to the host)
57
57
- <b>EXTRA SAFETY STEP</b>: Create a copy of your existing Home Assistant database so that it is possible to quickly move back to the original database.
58
-
- Right click in the left most window and select ```Create new -> database```
59
-
- Name: ```homeassistant backup```
60
-
- Collation: ```utf8mb4_unicode_ci```
61
-
- Right click the ```homeassistant``` database and select ```Export database as SQL```
62
-
- Press ```Export``` to copy the ```homeassistant``` database to the ```homeassistant backup``` database
58
+
- Right click in the left most window and select `Create new -> database`
59
+
- Name: `homeassistant backup`
60
+
- Collation: `utf8mb4_unicode_ci`
61
+
- Right click the `homeassistant` database and select `Export database as SQL`
62
+
- Press `Export` to copy the `homeassistant` database to the `homeassistant backup` database
63
63
- Settings:
64
-
- Database(s): not selected ```Drop```, selected ```Create```
65
-
- Table(s): not selected ```Drop```, selected ```Create```
66
-
- Data: ```Insert```
67
-
- Output: ```Database```
68
-
- Database: ```homeassistant backup```
69
-
- In case something goes wrong you can remove the ```homeassistant``` database and rename the ```homeassistant backup``` database to the ```homeassistant``` database.
70
-
- Right click the ```homeassistant``` database and select ```Drop```
71
-
- Right click the ```homeassistant backup``` database and select ```Edit``` and change the name into ```homeassistant``` and press ```Ok```
64
+
- Database(s): not selected `Drop`, selected `Create`
65
+
- Table(s): not selected `Drop`, selected `Create`
66
+
- Data: `Insert`
67
+
- Output: `Database`
68
+
- Database: `homeassistant backup`
69
+
- In case something goes wrong you can remove the `homeassistant` database and rename the `homeassistant backup` database to the `homeassistant` database.
70
+
- Right click the `homeassistant` database and select `Drop`
71
+
- Right click the `homeassistant backup` database and select `Edit` and change the name into `homeassistant` and press `Ok`
72
72
- Run the `ImportData.py` script from the Datasources directory to import the generated CSV files and use the following command-line parameters:
73
73
-`--db-type mariadb`
74
74
-`--host HOST` Host as defined in the HeidiSQL database connection
@@ -78,14 +78,31 @@ Importing historical energy data into Home Assistant is not simple and requires
78
78
-`--csv-file CSV_FILE [CSV_FILE ...]` Location of the CSV files generated in the source data preparation step, wildcards are allowed
- Load SQL file ```Import Energy data into Home Assistant.sql``` from the MariaDB directory (File -> Load SQL file - Yes on auto-detect file encoding)
83
+
#### Load import script
84
+
- Load SQL file `Import Energy data into Home Assistant.sql` from the MariaDB directory (File -> Load SQL file - Yes on auto-detect file encoding)
84
85
- Validate the schema version of the database (Select table: schema_changes and select the data tab on the right and scroll down to the bottom)
85
-
- The script has been tested with schema version 48. With higher versions you should validate if the structure of the ```statistics``` and ```short_term_statistics``` tables have changed.
86
-
- Used fields in table ```statistics```: ```metadata_id```, ```state```, ```sum```, ```start_ts```, ```created_ts```
87
-
- Used fields in table ```short_term_statistics```: ```sum```
88
-
- Lookup in the ```statistics_meta``` table the IDs of the sensors (Select table: ```statistics_meta``` and select the data tab on the right. You can use ```filter``` to find the ID of the sensor, For instance: ```statistic_id LIKE '%sensor.gas_meter%'```)
86
+
- The script has been tested with schema version 48. With higher versions you should validate if the structure of the `statistics` and `short_term_statistics` tables have changed.
87
+
- Used fields in table `statistics`: `metadata_id`, `state`, `sum`, `start_ts`, `created_ts`
88
+
- Used fields in table `short_term_statistics`: `sum`
89
+
90
+
#### Determine the sensor configuration
91
+
##### Option 1: Use the `Sensors.py` script (GUI)
92
+
- Run the `Sensors.py` script from the Database directory to determine the sensor configuration and use the following command-line parameters:
93
+
-`--db-type mariadb`
94
+
-`--host HOST` Host as defined in the HeidiSQL database connection
95
+
-`--user USER` Username as defined in the HeidiSQL database connection
96
+
-`--password PASSWORD` Password as defined in the HeidiSQL database connection
- Select the target sensors from Home Assistant and the corresponding source import name identifiers.
101
+
- Determine the unit of measurement of the source data (`Source unit`). The script will automatically determine the correct correction factor based on the unit of measurement of the source data.
102
+
- Determine the `cutoff_new_meter` and `cutoff_invalid_value`. The script will automatically fill in the default values based on the unit of measurement of the target sensor. The different cutoffs are described in the script.
103
+
- Press `Generate SQL` which will generate the SQL statements that need to be replaced in the `Import Energy data into Home Assistant.sql` SQL file.
104
+
##### Option 2: Manually lookup the sensor information
105
+
- Lookup in the `statistics_meta` table the IDs of the sensors (Select table: `statistics_meta` and select the data tab on the right. You can use `filter` to find the ID of the sensor, For instance: `statistic_id LIKE '%sensor.gas_meter%'`)
89
106
- The names of the sensors can be looked up in the Home Assistant Energy dashboard (Settings -> Dashboards -> Energy).
90
107
<br>Example:
91
108
```
@@ -100,14 +117,16 @@ Importing historical energy data into Home Assistant is not simple and requires
100
117
451 sensor.battery_energy_feed_out recorder kWh
101
118
653 sensor.watermeter_quantity_m3 recorder m³
102
119
```
103
-
- Change the script and remove/comment out the lines of the sensors that are not needed. They can be found at the top of the script by looking up the lines where ```/* Change */``` has been added in the SQL statement.
104
-
- Change the script and update the IDs according to the found IDs in the ```statistics_meta``` table.
105
-
They can be found at the top of the script by looking up the lines where ```/* Change */``` has been added in the SQL statement.
106
-
- Determine the ```correction``` value based on the ```unit_of_measurement``` of the sensor and the used datasource. The unit of measurement of the datasource can be found in the readme of the datasource.
120
+
- Change the script and remove/comment out the lines of the sensors that are not needed. They can be found at the top of the script by looking up the lines where `/* Change */` has been added in the SQL statement.
121
+
- Change the script and update the IDs according to the found IDs in the `statistics_meta` table.
122
+
They can be found at the top of the script by looking up the lines where `/* Change */` has been added in the SQL statement.
123
+
- Determine the `correction` value based on the `unit_of_measurement` of the sensor and the used datasource. The unit of measurement of the datasource can be found in the readme of the datasource.
107
124
The different corrections are described in the script.
108
-
- Determine the ```cutoff_new_meter``` and ```cutoff_invalid_value``` values based on the unit of measurement of the target sensor. The different cutoffs are described in the script.
125
+
- Determine the `cutoff_new_meter` and `cutoff_invalid_value` values based on the unit of measurement of the target sensor. The different cutoffs are described in the script.
126
+
127
+
#### Execute import script
109
128
- Execute the SQL and wait for it to complete. (Please be patient because this can take some time!)
110
-
- For the first run the ```COMMIT``` statement at the end of the script can be commented out so that the changes are not written to the database.
129
+
- For the first run the `COMMIT` statement at the end of the script can be commented out so that the changes are not written to the database.
111
130
This makes it possible to test the script and see whether it completes without errors.
112
131
- In case of an error correct the error and execute the script again. The script will automatically rollback any changes before trying again.
0 commit comments