mirror of
https://github.com/lildude/ha-addon-teslamate.git
synced 2026-10-13 13:10:30 -04:00
Prep for TeslaMate v2 update (#91)
* Prep docs for v2 * Add pg version check * Import dashboards after DB * Assume compatible * Emphasis version * Use 2 spaces for ident * Improve logging
This commit is contained in:
@@ -7,7 +7,7 @@ A self-hosted data logger for your Tesla 🚘
|
|||||||
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
||||||
|
|
||||||
- Written in **[Elixir][elixir]**
|
- Written in **[Elixir][elixir]**
|
||||||
- Data is stored in a **Postgres** database
|
- Data is stored in a **PostgreSQL** database
|
||||||
- Visualization and data analysis with **Grafana**
|
- Visualization and data analysis with **Grafana**
|
||||||
- Vehicle data is published to a local **MQTT** Broker
|
- Vehicle data is published to a local **MQTT** Broker
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ Once you have Grafana up and running, you'll need to configure a data source to
|
|||||||
|
|
||||||
‼️ **Note**: The name must be `TeslaMate` as all the dashboards expect the datasource to use this name.
|
‼️ **Note**: The name must be `TeslaMate` as all the dashboards expect the datasource to use this name.
|
||||||
|
|
||||||
![Grafana Postgres data source][grafana-datasource]
|
![Grafana PostgreSQL data source][grafana-datasource]
|
||||||
|
|
||||||
#### Other Options
|
#### Other Options
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ For example, if you access your Home Assistant instance at `https://ha.example.c
|
|||||||
|
|
||||||
Do _not_ use these values. Use the values from your log output.
|
Do _not_ use these values. Use the values from your log output.
|
||||||
|
|
||||||
## Migrate TeslaMate to a Different PostreSQL Server
|
## Migrate TeslaMate to a Different PostgreSQL Server
|
||||||
|
|
||||||
In order to migrate TeslaMate to a different PostgreSQL server, you will need to make a backup of the original data and then restore it to the destination server.
|
In order to migrate TeslaMate to a different PostgreSQL server, you will need to make a backup of the original data and then restore it to the destination server.
|
||||||
This isn't much of a challenge for the seasoned sysadmin familiar with Docker, PostgreSQL and the command line, however most Home Assistant users aren't expert sysadmins so this guide if for you.
|
This isn't much of a challenge for the seasoned sysadmin familiar with Docker, PostgreSQL and the command line, however most Home Assistant users aren't expert sysadmins so this guide if for you.
|
||||||
@@ -201,7 +201,7 @@ If you have made a backup of a TeslaMate installation as per the [TeslaMate back
|
|||||||
1. Install this TeslaMate add-on if you haven't already, but don't start it.
|
1. Install this TeslaMate add-on if you haven't already, but don't start it.
|
||||||
|
|
||||||
2. Install a PostgreSQL server and start it if you haven't already.
|
2. Install a PostgreSQL server and start it if you haven't already.
|
||||||
We recommend the [PostgreSQL add-on][alexbelgium-postgres] from @alexbelgium's repository .
|
We recommend the [PostgreSQL 17 add-on][alexbelgium-postgres] from @alexbelgium's repository, or [TimescaleDB][timescaledb] (for advanced users).
|
||||||
|
|
||||||
3. Perform steps 3, 4 and 5 from [Migrate TeslaMate to a Different PostreSQL Server][migrate-psql] above.
|
3. Perform steps 3, 4 and 5 from [Migrate TeslaMate to a Different PostreSQL Server][migrate-psql] above.
|
||||||
|
|
||||||
@@ -232,6 +232,7 @@ Follow this process:
|
|||||||
|
|
||||||
5. Once imported sucessfully, delete the CSV files to avoid the import screen being presented.
|
5. Once imported sucessfully, delete the CSV files to avoid the import screen being presented.
|
||||||
|
|
||||||
|
[alexbelgium-postgres]: https://github.com/alexbelgium/hassio-addons/tree/master/postgres_17
|
||||||
[docker]: https://hub.docker.com/r/teslamate/teslamate
|
[docker]: https://hub.docker.com/r/teslamate/teslamate
|
||||||
[elixir]: https://elixir-lang.org/
|
[elixir]: https://elixir-lang.org/
|
||||||
[grafana-addon]: https://github.com/hassio-addons/addon-grafana
|
[grafana-addon]: https://github.com/hassio-addons/addon-grafana
|
||||||
@@ -245,6 +246,7 @@ Follow this process:
|
|||||||
[teslafi-import]: https://docs.teslamate.org/docs/import/teslafi
|
[teslafi-import]: https://docs.teslamate.org/docs/import/teslafi
|
||||||
[teslamate]: https://github.com/teslamate-org/teslamate/
|
[teslamate]: https://github.com/teslamate-org/teslamate/
|
||||||
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore/#backup
|
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore/#backup
|
||||||
|
[timescaledb]: https://github.com/expaso/hassos-addon-timescaledb
|
||||||
|
|
||||||
[^1]:
|
[^1]:
|
||||||
If the backup or restore fails due to a `server version mismatch` error, you will need to select the latest version of PostgreSQL in pgAdmin4 by going to File -> Paths -> Binary paths and add the correct path for each version.
|
If the backup or restore fails due to a `server version mismatch` error, you will need to select the latest version of PostgreSQL in pgAdmin4 by going to File -> Paths -> Binary paths and add the correct path for each version.
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ A self-hosted data logger for your Tesla 🚘
|
|||||||
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
||||||
|
|
||||||
- Written in **[Elixir][elixir]**
|
- Written in **[Elixir][elixir]**
|
||||||
- Data is stored in a **Postgres** database
|
- Data is stored in a **PostgreSQL** database
|
||||||
- Visualization and data analysis with **Grafana**
|
- Visualization and data analysis with **Grafana**
|
||||||
- Vehicle data is published to a local **MQTT** Broker
|
- Vehicle data is published to a local **MQTT** Broker
|
||||||
|
|
||||||
@@ -24,8 +24,8 @@ Thanks to @matt-FFFFFF for maintaining this add-on in the past.
|
|||||||
|
|
||||||
## Requirements
|
## Requirements
|
||||||
|
|
||||||
TeslaMate needs a PostgreSQL database.
|
**TeslaMate v2 needs a PostgreSQL 16.7 or 17.3 or later database.**
|
||||||
I recommend using the [PostgreSQL add-on][alexbelgium-postgres] from @alexbelgium's repository if you aren't already using Postgres.
|
I recommend using the [PostgreSQL 17 add-on][alexbelgium-postgres] from @alexbelgium's repository, or [TimescaleDB][timescaledb] (for advanced users), if you aren't already using PostgreSQL.
|
||||||
|
|
||||||
To get the full experience, it is recommended that you also install the community [Grafana add-on][grafana-addon] and [MQTT integration][mqtt].
|
To get the full experience, it is recommended that you also install the community [Grafana add-on][grafana-addon] and [MQTT integration][mqtt].
|
||||||
|
|
||||||
@@ -46,6 +46,13 @@ To get the full experience, it is recommended that you also install the communit
|
|||||||
1. Check the logs of the add-on to see if everything went well.
|
1. Check the logs of the add-on to see if everything went well.
|
||||||
1. Click the `OPEN WEB UI` button to open TeslaMate.
|
1. Click the `OPEN WEB UI` button to open TeslaMate.
|
||||||
|
|
||||||
|
## Upgrading this add-on from v1 to v2
|
||||||
|
|
||||||
|
TeslaMate v2 introduced a hard requirement on the version of PostgreSQL database.
|
||||||
|
**You will need to use PostgreSQL 16.7 or 17.3 or later.**
|
||||||
|
If you are currently using an earlier version of PostgreSQL, you will need to backup your TeslaMate data, upgrade the database, and then restore the data.
|
||||||
|
You can find details on how to do this in the "_Migrate TeslaMate to a Different Postres Server_" section of this add-on's documentation tab or in the [DOCS.md][docs-md] file in the add-on repository.
|
||||||
|
|
||||||
## Migrating to this version of the add-on
|
## Migrating to this version of the add-on
|
||||||
|
|
||||||
Migrating to this version of the add-on should not result in any loss of data, but you can never be too careful, so I recommend you take a full backup of your Home Assistant instance and also a direct backup of the TeslaMate database as detailed in the [TeslaMate documentation][teslamate-backup] before proceeding.
|
Migrating to this version of the add-on should not result in any loss of data, but you can never be too careful, so I recommend you take a full backup of your Home Assistant instance and also a direct backup of the TeslaMate database as detailed in the [TeslaMate documentation][teslamate-backup] before proceeding.
|
||||||
@@ -67,9 +74,10 @@ Everything should pick up where it was before.
|
|||||||
|
|
||||||
[addon]: https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Flildude%2Fha-addons
|
[addon]: https://my.home-assistant.io/redirect/supervisor_add_addon_repository/?repository_url=https%3A%2F%2Fgithub.com%2Flildude%2Fha-addons
|
||||||
[addons-repo]: https://github.com/lildude/ha-addons
|
[addons-repo]: https://github.com/lildude/ha-addons
|
||||||
[alexbelgium-postgres]: https://github.com/alexbelgium/hassio-addons/tree/master/postgres
|
[alexbelgium-postgres]: https://github.com/alexbelgium/hassio-addons/tree/master/postgres_17
|
||||||
[archs]: https://img.shields.io/badge/dynamic/json?color=green&label=Arch&query=%24.arch&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fconfig.json
|
[archs]: https://img.shields.io/badge/dynamic/json?color=green&label=Arch&query=%24.arch&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fconfig.json
|
||||||
[docker]: https://hub.docker.com/r/teslamate/teslamate
|
[docker]: https://hub.docker.com/r/teslamate/teslamate
|
||||||
|
[docs-md]: https://github.com/lildude/ha-addon-teslamate/blob/main/DOCS.md#migrate-teslamate-to-a-different-postgresql-server
|
||||||
[elixir]: https://elixir-lang.org/
|
[elixir]: https://elixir-lang.org/
|
||||||
[grafana-addon]: https://github.com/hassio-addons/addon-grafana
|
[grafana-addon]: https://github.com/hassio-addons/addon-grafana
|
||||||
[ingres-badge]: https://img.shields.io/badge/dynamic/json?label=Ingress&query=%24.ingress&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fconfig.json
|
[ingres-badge]: https://img.shields.io/badge/dynamic/json?label=Ingress&query=%24.ingress&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fconfig.json
|
||||||
@@ -79,3 +87,4 @@ Everything should pick up where it was before.
|
|||||||
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore
|
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore
|
||||||
[teslamate-version]: https://img.shields.io/badge/dynamic/json?label=TeslaMate%20Version&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fbuild.json&query=%24.args.teslamate_version
|
[teslamate-version]: https://img.shields.io/badge/dynamic/json?label=TeslaMate%20Version&url=https%3A%2F%2Fraw.githubusercontent.com%2Flildude%2Fha-addon-teslamate%2Fmain%2Fbuild.json&query=%24.args.teslamate_version
|
||||||
[teslamate]: https://github.com/teslamate-org/teslamate/
|
[teslamate]: https://github.com/teslamate-org/teslamate/
|
||||||
|
[timescaledb]: https://github.com/expaso/hassos-addon-timescaledb
|
||||||
|
|||||||
+4
-2
@@ -64,10 +64,12 @@
|
|||||||
"import_dir": "str",
|
"import_dir": "str",
|
||||||
"default_geofence": "str?",
|
"default_geofence": "str?",
|
||||||
"encryption_key": "password?",
|
"encryption_key": "password?",
|
||||||
"env_vars": [{
|
"env_vars": [
|
||||||
|
{
|
||||||
"name": "str?",
|
"name": "str?",
|
||||||
"value": "str?"
|
"value": "str?"
|
||||||
}]
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"map": [
|
"map": [
|
||||||
"share:rw"
|
"share:rw"
|
||||||
|
|||||||
@@ -52,14 +52,30 @@ for env_var in $(bashio::config 'env_vars|keys'); do
|
|||||||
export "${name}=${value}"
|
export "${name}=${value}"
|
||||||
done
|
done
|
||||||
|
|
||||||
# Import dashboards
|
|
||||||
if bashio::config.true 'grafana_import_dashboards'; then
|
|
||||||
/dashboards.sh restore || bashio::log.error "Failed to import dashboards"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Create the PostgreSQL database if it doesn't exist
|
# Create the PostgreSQL database if it doesn't exist
|
||||||
|
bashio::log.info "Checking for database '$DATABASE_NAME' on $DATABASE_HOST"
|
||||||
if pg_isready -h "$DATABASE_HOST" -p "$DATABASE_PORT" > /dev/null 2>&1; then
|
if pg_isready -h "$DATABASE_HOST" -p "$DATABASE_PORT" > /dev/null 2>&1; then
|
||||||
bashio::log.info "Checking for database '$DATABASE_NAME' on $DATABASE_HOST"
|
# Check the version of PostgreSQL database is v16.7 or later or v17.3 or later
|
||||||
|
pg_version=$(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "SELECT regexp_replace(version(), 'PostgreSQL ([^ ]+) .*', '\\1') AS version")
|
||||||
|
major_version=$(echo "$pg_version" | cut -d '.' -f 1)
|
||||||
|
minor_version=$(echo "$pg_version" | cut -d '.' -f 2)
|
||||||
|
compat=true
|
||||||
|
case "$major_version" in
|
||||||
|
16)
|
||||||
|
[[ "$minor_version" -lt 7 ]] && compat=false
|
||||||
|
;;
|
||||||
|
17)
|
||||||
|
[[ "$minor_version" -lt 3 ]] && compat=false
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
[[ "$major_version" -lt 16 ]] && compat=false
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
if [ $compat = false ]; then
|
||||||
|
bashio::log.error "PostgreSQL version $pg_version is not supported. Please upgrade to v16.7 or later or v17.3 or later."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -n $(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "SELECT datname FROM pg_database WHERE datname = '$DATABASE_NAME'") ]]; then
|
if [[ -n $(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "SELECT datname FROM pg_database WHERE datname = '$DATABASE_NAME'") ]]; then
|
||||||
bashio::log.info "Database $DATABASE_NAME already exists"
|
bashio::log.info "Database $DATABASE_NAME already exists"
|
||||||
@@ -76,19 +92,26 @@ else
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Import dashboards
|
||||||
|
if bashio::config.true 'grafana_import_dashboards'; then
|
||||||
|
bashio::log.info "Importing Grafana dashboards..."
|
||||||
|
/dashboards.sh restore || bashio::log.error "Failed to import dashboards"
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z $(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" "$DATABASE_NAME" -Atqc "SELECT 1 FROM settings WHERE base_url LIKE '%api/hassio_ingress%'" 2> /dev/null ) ]]; then
|
if [[ -z $(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" "$DATABASE_NAME" -Atqc "SELECT 1 FROM settings WHERE base_url LIKE '%api/hassio_ingress%'" 2> /dev/null ) ]]; then
|
||||||
teslamate_ingress=$(bashio::addon.ingress_entry)
|
teslamate_ingress=$(bashio::addon.ingress_entry)
|
||||||
grafana_ingress=$(bashio::addon.ingress_entry $(bashio::supervisor.addons | grep grafana))
|
grafana_ingress=$(bashio::addon.ingress_entry "$(bashio::supervisor.addons | grep grafana)")
|
||||||
if [[ "$teslamate_ingress" == "$grafana_ingress" ]]; then
|
if [[ "$teslamate_ingress" == "$grafana_ingress" ]]; then
|
||||||
grafana_ingress="** Grafana addon not found. Ensure the addon is installed and running. **"
|
grafana_ingress="** Grafana addon not found. Ensure the addon is installed and running. **"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
bashio::log.info "Configure TeslaMate settings by adding these values
|
bashio::log.notice ""
|
||||||
to the URL you use to access your Home Assistant instance:
|
bashio::log.notice "Configure TeslaMate settings by adding these values"
|
||||||
|
bashio::log.notice "to the URL you use to access your Home Assistant instance:"
|
||||||
=> Web App: $teslamate_ingress
|
bashio::log.notice ""
|
||||||
=> Dashboards: $grafana_ingress
|
bashio::log.notice "=> Web App: $teslamate_ingress"
|
||||||
"
|
bashio::log.notice "=> Dashboards: $grafana_ingress"
|
||||||
|
bashio::log.notice ""
|
||||||
fi
|
fi
|
||||||
ulimit -n 1048576
|
ulimit -n 1048576
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user