mirror of
https://github.com/lildude/ha-addon-teslamate.git
synced 2026-10-13 21:19:16 -04:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7a86a1f0c3 | ||
|
|
83c29fbed8 | ||
|
|
ee6faf280d | ||
|
|
2421d0a805 | ||
|
|
aa5dee6c4a | ||
|
|
77e7510e3b | ||
|
|
6031fe6fa4 | ||
|
|
eb7945344e | ||
|
|
e9c77210b7 | ||
|
|
64cbe20138 | ||
|
|
1c521e808c | ||
|
|
0d7507b3d9 | ||
|
|
d8aa9cb7d9 | ||
|
|
2dfda5bbc0 | ||
|
|
522e9890ca | ||
|
|
453252d864 | ||
|
|
800d3ee3ab | ||
|
|
562fd279b0 | ||
|
|
9d0729c9bf | ||
|
|
e3a352b44d | ||
|
|
fc5f6d6c2d | ||
|
|
db77437898 | ||
|
|
111527b4b6 | ||
|
|
df2f87600b | ||
|
|
4bc610e9a7 | ||
|
|
48cc287c98 | ||
|
|
04eb3228bd | ||
|
|
a5180bcb8e | ||
|
|
f2d6fcd514 | ||
|
|
540732b90a | ||
|
|
33d50cce75 | ||
|
|
b5ab114562 | ||
|
|
b17ded97f6 | ||
|
|
3a9e27e9ac | ||
|
|
fb4eff6570 | ||
|
|
d54d94a480 | ||
|
|
a979b4fdf6 | ||
|
|
86fe972431 | ||
|
|
3d167fc6ee | ||
|
|
0013f5605b | ||
|
|
826c07ace9 | ||
|
|
7bfa32be3f | ||
|
|
b9e37e9f32 | ||
|
|
945a7c4822 | ||
|
|
4567555071 | ||
|
|
694b43eb93 | ||
|
|
04e01df081 | ||
|
|
d97377bc0e | ||
|
|
0aca1dd417 | ||
|
|
556a2f23af | ||
|
|
a73430c34d | ||
|
|
2b40dd2668 | ||
|
|
1757ed78ff |
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"name": "HA Addon: TeslaMate",
|
||||
"image": "ghcr.io/home-assistant/devcontainer:addons",
|
||||
"image": "ghcr.io/home-assistant/devcontainer:2-addons",
|
||||
"appPort": ["7123:8123", "7357:4357"],
|
||||
"postStartCommand": "sudo sed -i 's/export SUPERVISOR_VERSION=.*/export SUPERVISOR_VERSION=2024.03.1.dev1803/' /etc/supervisor_scripts/common && bash devcontainer_bootstrap", // Workaround until https://github.com/home-assistant/supervisor/issues/5021 is fixed"
|
||||
"postStartCommand": "bash devcontainer_bootstrap",
|
||||
"runArgs": ["-e", "GIT_EDITOR=code --wait", "--privileged"],
|
||||
"containerEnv": {
|
||||
"WORKSPACE_DIRECTORY": "${containerWorkspaceFolder}"
|
||||
@@ -27,5 +27,8 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"mounts": ["type=volume,target=/var/lib/docker"]
|
||||
"mounts": [
|
||||
"type=volume,target=/var/lib/docker",
|
||||
"type=volume,target=/mnt/supervisor"
|
||||
]
|
||||
}
|
||||
@@ -8,12 +8,13 @@
|
||||
"prBodyTemplate": "{{{table}}}{{{warnings}}}{{{notes}}}{{{changelogs}}}",
|
||||
"semanticCommits": "disabled",
|
||||
"commitMessageTopic": "{{#if (containsString depName 'teslamate')}}TeslaMate{{else}}{{depName}}{{/if}}",
|
||||
"enabledManagers": ["custom.regex", "github-actions", "dockerfile"],
|
||||
"enabledManagers": ["custom.regex", "github-actions"],
|
||||
"customManagers": [
|
||||
{
|
||||
"customType": "regex",
|
||||
"fileMatch": "^build.json$",
|
||||
"matchStrings": [
|
||||
"\"teslamate/teslamate:(?<currentValue>\\d+\\.\\d+\\.\\d+)\"",
|
||||
"\"teslamate_version\": \"(?<currentValue>\\d+\\.\\d+\\.\\d+)\""
|
||||
],
|
||||
"datasourceTemplate": "github-releases",
|
||||
|
||||
@@ -14,19 +14,9 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: ⤵️ Check out code from GitHub
|
||||
uses: actions/checkout@v4.1.7
|
||||
uses: actions/checkout@v5.0.0
|
||||
|
||||
- name: 🚀 Run Home Assistant Add-on Lint
|
||||
uses: frenck/action-addon-linter@v2
|
||||
with:
|
||||
path: "./"
|
||||
|
||||
- name: Check versions match
|
||||
run: |
|
||||
docker_ver=$(grep "FROM teslamate/teslamate" Dockerfile | cut -d':' -f2)
|
||||
build_ver=$(jq -r ".args.teslamate_version" build.json)
|
||||
if [ "$docker_ver" != "$build_ver" ]; then
|
||||
echo -e "\033[31;1mTeslaMate versions don't match: Dockerfile => ${docker_ver} | build.json => ${build_ver}\033[0m"
|
||||
exit 1
|
||||
fi
|
||||
echo -e "\033[32;1mTeslaMate versions match: Dockerfile => ${docker_ver} | build.json => ${build_ver}\033[0m"
|
||||
|
||||
@@ -19,11 +19,11 @@ jobs:
|
||||
packages: write
|
||||
strategy:
|
||||
matrix:
|
||||
arch: ["amd64", "armv7", "aarch64"]
|
||||
arch: ["amd64", "aarch64"]
|
||||
|
||||
steps:
|
||||
- name: Checkout the repository
|
||||
uses: actions/checkout@v4.1.7
|
||||
uses: actions/checkout@v5.0.0
|
||||
|
||||
- name: Get version
|
||||
run: |
|
||||
@@ -35,14 +35,14 @@ jobs:
|
||||
fi
|
||||
|
||||
- name: Login to GitHub Container Registry
|
||||
uses: docker/login-action@v3.2.0
|
||||
uses: docker/login-action@v3.6.0
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.repository_owner }}
|
||||
password: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Build and publish
|
||||
uses: home-assistant/builder@master
|
||||
uses: home-assistant/builder@2025.09.0
|
||||
with:
|
||||
args: |
|
||||
--${{ matrix.arch }} \
|
||||
|
||||
@@ -19,7 +19,7 @@ jobs:
|
||||
packages: write
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
uses: actions/checkout@v5
|
||||
with:
|
||||
path: teslamate
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
@@ -35,12 +35,13 @@ jobs:
|
||||
- name: Get TeslaMate release notes
|
||||
run: |
|
||||
touch CHANGELOG.txt
|
||||
gh pr list --repo lildude/ha-addon-teslamate --state=merged --search="Update TeslaMate" --limit=1 --json=body --jq '.[].body' | sed -n "/<\/summary>/,/<\/details>/p" | sed '1d;$d' > changelog.tmp
|
||||
last_release_date=$(gh release list --repo lildude/ha-addon-teslamate --limit=1 --json=publishedAt | jq -r '.[].publishedAt')
|
||||
gh pr list --repo lildude/ha-addon-teslamate --state=merged --search="Update TeslaMate in:title closed:>$last_release_date" --limit=1 --json=body --jq '.[].body' | sed -n "/<\/summary>/,/<\/details>/p" | sed '1d;$d' > changelog.tmp
|
||||
if [ -s changelog.tmp ]; then
|
||||
echo "## TeslaMate Release Notes" > CHANGELOG.txt
|
||||
cat changelog.tmp >> CHANGELOG.txt
|
||||
echo -e "---\n\n## Add-on Release Notes\n\n" >> CHANGELOG.txt
|
||||
fi
|
||||
echo -e "---\n\n## Add-on Release Notes\n\n" >> CHANGELOG.txt
|
||||
env:
|
||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Create tag
|
||||
@@ -51,7 +52,7 @@ jobs:
|
||||
git push --tags
|
||||
working-directory: ${{ github.workspace }}/teslamate
|
||||
- name: Create release
|
||||
uses: softprops/action-gh-release@v2.0.7
|
||||
uses: softprops/action-gh-release@v2.4.1
|
||||
with:
|
||||
tag_name: v${{ steps.semver.outputs.semver }}
|
||||
body_path: CHANGELOG.txt
|
||||
@@ -60,7 +61,7 @@ jobs:
|
||||
prerelease: false
|
||||
token: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Checkout addon repo
|
||||
uses: actions/checkout@v4.1.7
|
||||
uses: actions/checkout@v5.0.0
|
||||
with:
|
||||
path: repo
|
||||
repository: lildude/ha-addons
|
||||
|
||||
@@ -28,17 +28,21 @@ jobs:
|
||||
name: Build add-on
|
||||
strategy:
|
||||
matrix:
|
||||
arch: ["amd64", "armv7", "aarch64"]
|
||||
arch: ["amd64", "aarch64"]
|
||||
|
||||
steps:
|
||||
- name: Check out repository
|
||||
uses: actions/checkout@v4.1.7
|
||||
uses: actions/checkout@v5.0.0
|
||||
|
||||
- name: Build add-on
|
||||
uses: home-assistant/builder@master
|
||||
uses: home-assistant/builder@2025.09.0
|
||||
with:
|
||||
args: |
|
||||
--test \
|
||||
--${{ matrix.arch }} \
|
||||
--target /data/ \
|
||||
--addon
|
||||
|
||||
- name: Image labels
|
||||
run: |
|
||||
docker inspect ghcr.io/lildude/ha-addon-teslamate-${{ matrix.arch }} --format='{{json .Config.Labels}}' | jq
|
||||
|
||||
@@ -7,7 +7,7 @@ A self-hosted data logger for your Tesla 🚘
|
||||
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
||||
|
||||
- Written in **[Elixir][elixir]**
|
||||
- Data is stored in a **Postgres** database
|
||||
- Data is stored in a **PostgreSQL** database
|
||||
- Visualization and data analysis with **Grafana**
|
||||
- Vehicle data is published to a local **MQTT** Broker
|
||||
|
||||
@@ -16,6 +16,7 @@ This add-on allows you to run [TeslaMate][teslamate] on your Home Assistant serv
|
||||
## Configuration
|
||||
|
||||
The configuration is self-explanatory, but essentially we need details about accessing the PostgreSQL database, Grafana and optionally MQTT.
|
||||
You will also need to configure TeslaMate (see "TeslaMate Configuration" below) so the links to TeslaMate in the Grafana dashboards work.
|
||||
|
||||
### Options
|
||||
|
||||
@@ -76,7 +77,6 @@ custom_plugins:
|
||||
- name: panodata-map-panel
|
||||
url: https://github.com/panodata/panodata-map-panel/releases/download/0.16.0/panodata-map-panel-0.16.0.zip
|
||||
unsigned: true
|
||||
custom_plugins: []
|
||||
env_vars:
|
||||
- name: GF_SECURITY_ADMIN_USER
|
||||
value: <youruser>
|
||||
@@ -105,7 +105,9 @@ _Note_ that the security admin password and usernames can only be set on the fir
|
||||
|
||||
Once you have Grafana up and running, you'll need to configure a data source to read data from the PostgreSQL database:
|
||||
|
||||
![Grafana Postgres data source][grafana-datasource]
|
||||
‼️ **Note**: The name must be `TeslaMate` as all the dashboards expect the datasource to use this name.
|
||||
|
||||
![Grafana PostgreSQL data source][grafana-datasource]
|
||||
|
||||
#### Other Options
|
||||
|
||||
@@ -115,6 +117,105 @@ Once you have Grafana up and running, you'll need to configure a data source to
|
||||
|
||||
- `import_dir`: (Optional) The path to the directory where TeslaMate should look for the TeslaMate export CSV file. Default: `/share/teslamate`.
|
||||
|
||||
- `env_vars`: (Optional) Set additional environment variables for TeslaMate which aren't currently exposed by the configuration options in this add-on.
|
||||
|
||||
Each entry is made up of a name and value:
|
||||
|
||||
- `name`: The case-sensitive environment variable name.
|
||||
- `value`: The value to be set in the environment variable.
|
||||
|
||||
Note: These will also overwrite any environment variable set using the configuration options above.
|
||||
|
||||
## TeslaMate Configuration
|
||||
|
||||
In order for the links in the Grafana dashboards and the TeslaMate UI to link to the correct locations, you will also need to configure TeslaMate.
|
||||
Once you have started the add-on, look at the log output for the section which looks like this and take note of the two lines with `=>`:
|
||||
|
||||
```
|
||||
[09:26:32] INFO: Configure TeslaMate settings by adding these values
|
||||
to the URL you use to access your Home Assistant instance:
|
||||
|
||||
=> Web App: /api/hassio_ingress/ljiIc6sOVGOSQfTRjscvLVJJS5Rxp33gsdEtf9y3oQY
|
||||
=> Dashboards: /api/hassio_ingress/G9ocwA44wt9Bcba8LvP8tDhlfFiFnnPftOZBwp-Pgzs
|
||||
|
||||
```
|
||||
|
||||
From the add-on Info tab, click "Open Web UI", enter the Tesla API access and refresh tokens if you haven't already, and then go to TeslaMate's Settings.
|
||||
Scroll to the very bottom and set each of the URLs to the URL you use to access your Home Assistant instance with each of the above appended.
|
||||
|
||||
For example, if you access your Home Assistant instance at `https://ha.example.com`, set each as follows:
|
||||
|
||||
- Web App: `https://ha.example.com/api/hassio_ingress/ljiIc6sOVGOSQfTRjscvLVJJS5Rxp33gsdEtf9y3oQY`
|
||||
- Dashboards: `https://ha.example.com/api/hassio_ingress/G9ocwA44wt9Bcba8LvP8tDhlfFiFnnPftOZBwp-Pgzs`
|
||||
|
||||
Do _not_ use these values. Use the values from your log output.
|
||||
|
||||
**Note:** If you do not see the links in your add-on logs, clear the values in the TeslaMate configuration and restart the add-on.
|
||||
|
||||
## 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.
|
||||
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.
|
||||
|
||||
1. Ensure you have both the current and new PostgreSQL servers installed and running and ensure you have the same users and roles configured on both.
|
||||
|
||||
2. Stop the TeslaMate add-on.
|
||||
|
||||
3. Install the [pgAdmin4](https://github.com/expaso/hassos-addons) add-on.
|
||||
|
||||
4. Start the pgAdmin4 add-on and open the web UI
|
||||
|
||||
5. Make a new connection to the current PostgreSQL server by clicking "Add New Server".
|
||||
|
||||
1. Give it a recognisable name in the General tab.
|
||||
|
||||
2. Switch to the Connection tab and enter the hostname, port, username and password currently used.
|
||||
You can find these in your TeslaMate add-on configuration.
|
||||
|
||||
3. Click Save
|
||||
|
||||
6. Click the dropdown next to the new server -> Databases and then select the database you use for TeslaMate.
|
||||
This will be the same name you configured in the TeslaMate add-on configuration.
|
||||
|
||||
7. Go to Tools -> Backup, enter a filename, if you know what you're doing feel free to make other customisations but it's not essential, and then click Backup. [^1]
|
||||
|
||||
8. Once the backup has finished, repeats step 5 for your new PostgreSQL server to establish a connection to your new PostgreSQL server.
|
||||
|
||||
9. Select the new server, if not already selected, and go to Object -> Create -> Database and enter the same name and owner as used on your old server and click Save.
|
||||
|
||||
10. If the database is not already selected, select it and then go to Tools -> Restore, enter the filename you entered in step 7 and click Restore.
|
||||
You may need to use the file browser to locate the file. If you didn't change the path in step 7, the backup should be in `/root/`.
|
||||
|
||||
11. Once the restore has completed, go to the TeslaMate add-on settings and update the database settings to point to your new database server.
|
||||
The easiest approach is to use the steps in [Migrating to this version of the add-on][migrate-addon] further down in this file and change the `database_host` to the name of your new PostgreSQL server.
|
||||
|
||||
12. Update the Grafana configuration by going to the Grafana add-on -> Open web UI -> Grafana logo in top left -> Connections -> Datasources, select the TeslaMate source and change the Host URL to your new PostgreSQL server and click "Save & test".
|
||||
|
||||
13. Start the TeslaMate add-on and verifying everything is working as it was before. [^2]
|
||||
|
||||
You can now uninstall the pgAdmin4 add-on if you want and stop and uninstall your old PostgreSQL server if you're not using it for anything else.
|
||||
|
||||
## Import TeslaMate Backup
|
||||
|
||||
If you have made a backup of a TeslaMate installation as per the [TeslaMate backup documentation][teslamate-backup] and now have a `teslamate.bak` file you want to use with this add-on, you can do so as follows:
|
||||
|
||||
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.
|
||||
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.
|
||||
|
||||
4. Transfer the `teslamate.bck` file to the `/share/teslamate` folder on your Home Assistant instance.
|
||||
You can do this using the [Samba][samba-addon] or [SSH][ssh-addon] add-ons.
|
||||
|
||||
5. Perform steps 9 and 10 from [Migrate TeslaMate to a Different PostreSQL Server][migrate-psql] above.
|
||||
Note: the file location will be `/share/teslamate/teslamate.bck`.
|
||||
|
||||
6. Configure TeslaMate and Grafana as per the details at the top of this file.
|
||||
|
||||
7. Start TeslaMate.
|
||||
|
||||
## Data Import from TeslaFi
|
||||
|
||||
It is now possible to import CSV data from TeslaFi, refer to the [official docs][teslafi-import].
|
||||
@@ -132,12 +233,27 @@ Follow this process:
|
||||
|
||||
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
|
||||
[elixir]: https://elixir-lang.org/
|
||||
[grafana-addon]: https://github.com/hassio-addons/addon-grafana
|
||||
[grafana-datasource]: https://raw.githubusercontent.com/lildude/hassio-addon-teslamate/main/imgs/grafana-postgres.png
|
||||
[grafana-datasource]: https://raw.githubusercontent.com/lildude/ha-addon-teslamate/main/imgs/grafana-postgres.png
|
||||
[migrate-psql]: #migrate-teslamate-to-a-different-postresql-server
|
||||
[migrate-addon]: https://github.com/lildude/ha-addon-teslamate/blob/main/README.md#migrating-to-this-version-of-the-add-on
|
||||
[mosquitto-docs]: https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md
|
||||
[pgadmin4]: https://github.com/expaso/hassos-addons
|
||||
[samba-addon]: https://github.com/home-assistant/addons/blob/master/samba/DOCS.md
|
||||
[ssh-addon]: https://github.com/home-assistant/addons/blob/master/ssh/DOCS.md
|
||||
[teslafi-import]: https://docs.teslamate.org/docs/import/teslafi
|
||||
[teslamate]: https://github.com/teslamate-org/teslamate/
|
||||
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore/#backup
|
||||
[timescaledb]: https://github.com/expaso/hassos-addon-timescaledb
|
||||
|
||||
[^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.
|
||||
For example, for PostgreSQL 14, enter `/usr/local/pgsql-14`, for PostgreSQL 15, enter `/usr/local/pgsql-15` etc.
|
||||
|
||||
[^2]:
|
||||
If you see the `ERROR: type "earth" does not exist at character` error in the TeslaMate log, you can fix this by going back into pgAdmin4 and right click on the TeslaMate database -> "CREATE script".
|
||||
Delete everything auto generated and paste in the [codeblock here](https://github.com/diogob/activerecord-postgres-earthdistance/issues/30#issuecomment-2122829036).
|
||||
Click "Execute script" (It's the ▶️ symbol at the top).
|
||||
|
||||
+11
-28
@@ -1,8 +1,11 @@
|
||||
FROM teslamate/grafana:1.30.1 as grafana
|
||||
ARG BUILD_FROM
|
||||
ARG teslamate_version
|
||||
FROM teslamate/grafana:${teslamate_version} as grafana
|
||||
|
||||
#---
|
||||
|
||||
FROM teslamate/teslamate:1.30.1
|
||||
ARG BUILD_FROM
|
||||
FROM $BUILD_FROM
|
||||
|
||||
ARG BUILD_ARCH
|
||||
ARG BASHIO_VERSION=0.16.2
|
||||
@@ -22,7 +25,6 @@ RUN \
|
||||
set -x \
|
||||
&& apt-get update && apt-get install -y --no-install-recommends \
|
||||
bash \
|
||||
bind9utils \
|
||||
ca-certificates \
|
||||
curl \
|
||||
jq \
|
||||
@@ -30,41 +32,22 @@ RUN \
|
||||
postgresql-client \
|
||||
tzdata \
|
||||
xz-utils \
|
||||
&& rm -rf /var/lib/apt/lists/* \
|
||||
&& S6_ARCH="${BUILD_ARCH}" \
|
||||
&& if [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; \
|
||||
elif [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \
|
||||
&& if [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; fi \
|
||||
&& curl -Ls "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-noarch.tar.xz" | tar xpJ -C / \
|
||||
&& curl -Ls "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-${S6_ARCH}.tar.xz" | tar xpJ -C / \
|
||||
&& curl -Ls "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-noarch.tar.xz" | tar Jxp -C / \
|
||||
&& curl -Ls "https://github.com/just-containers/s6-overlay/releases/download/v${S6_OVERLAY_VERSION}/s6-overlay-symlinks-arch.tar.xz" | tar Jxp -C / \
|
||||
&& mkdir -p /etc/fix-attrs.d \
|
||||
&& mkdir -p /etc/services.d \
|
||||
&& mkdir -p /tmp/bashio \
|
||||
&& curl -Ls "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar xz --strip 1 -C /tmp/bashio \
|
||||
&& mv /tmp/bashio/lib /usr/lib/bashio \
|
||||
&& apt purge -y xz-utils \
|
||||
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio \
|
||||
&& rm -rf /tmp/bashio
|
||||
&& rm -rf /var/lib/apt/lists/* /tmp/*
|
||||
|
||||
COPY --chown=root scripts/*.sh /
|
||||
RUN chmod a+x /*.sh
|
||||
|
||||
COPY --chown=root services/teslamate/run services/teslamate/finish /etc/services.d/teslamate/
|
||||
RUN chmod a+x /etc/services.d/teslamate/*
|
||||
|
||||
COPY --chown=root services/nginx/run services/nginx/finish /etc/services.d/nginx/
|
||||
RUN chmod a+x /etc/services.d/nginx/*
|
||||
|
||||
COPY --chown=root services/nginx/teslamate.conf /etc/nginx/conf.d/
|
||||
|
||||
COPY --from=grafana --chown=root /dashboards /dashboards
|
||||
COPY --from=grafana --chown=root /dashboards_internal /dashboards
|
||||
COPY rootfs /
|
||||
COPY --from=grafana /dashboards /dashboards
|
||||
COPY --from=grafana /dashboards_internal /dashboards
|
||||
|
||||
# S6-Overlay
|
||||
ENTRYPOINT ["/init"]
|
||||
|
||||
LABEL \
|
||||
org.opencontainers.image.title="Home Assistant Add-on: TeslaMate" \
|
||||
org.opencontainers.image.description="A self-hosted data logger for your Tesla." \
|
||||
org.opencontainers.image.source="https://github.com/lildude/ha-addon-ghostfolio/" \
|
||||
org.opencontainers.image.licenses="MIT"
|
||||
|
||||
@@ -7,7 +7,7 @@ A self-hosted data logger for your Tesla 🚘
|
||||
[TeslaMate][teslamate] is a powerful, self-hosted data logger for your Tesla.
|
||||
|
||||
- Written in **[Elixir][elixir]**
|
||||
- Data is stored in a **Postgres** database
|
||||
- Data is stored in a **PostgreSQL** database
|
||||
- Visualization and data analysis with **Grafana**
|
||||
- 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
|
||||
|
||||
TeslaMate needs a PostgreSQL database.
|
||||
I recommend using the [PostgreSQL add-on][alexbelgium-postgres] from @alexbelgium's repository if you aren't already using Postgres.
|
||||
**TeslaMate v2 needs a PostgreSQL 16.7 or 17.3 or later database.**
|
||||
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].
|
||||
|
||||
@@ -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. 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 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
|
||||
[addons-repo]: https://github.com/lildude/ha-addons
|
||||
[alexbegium-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
|
||||
[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/
|
||||
[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
|
||||
@@ -79,3 +87,4 @@ Everything should pick up where it was before.
|
||||
[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]: https://github.com/teslamate-org/teslamate/
|
||||
[timescaledb]: https://github.com/expaso/hassos-addon-timescaledb
|
||||
|
||||
+11
-6
@@ -1,13 +1,18 @@
|
||||
{
|
||||
"build_from": {
|
||||
"aarch64": "teslamate/teslamate:not-used",
|
||||
"amd64": "teslamate/teslamate:not-used",
|
||||
"armv7": "teslamate/teslamate:not-used"
|
||||
"aarch64": "teslamate/teslamate:2.2.0",
|
||||
"amd64": "teslamate/teslamate:2.2.0"
|
||||
},
|
||||
"args": {
|
||||
"teslamate_version": "1.30.1"
|
||||
"teslamate_version": "2.2.0"
|
||||
},
|
||||
"codenotary": {
|
||||
"signer": "colin@symr.io"
|
||||
"labels":{
|
||||
"maintainer": "Colin Seymour (https://github.com/lildude)",
|
||||
"org.opencontainers.image.authors": "Colin Seymour (https://github.com/lildude)",
|
||||
"org.opencontainers.image.description": "A self-hosted data logger for your Tesla.",
|
||||
"org.opencontainers.image.documentation": "https://github.com/lildude/ha-addon-teslamate/blob/main/DOCS.md",
|
||||
"org.opencontainers.image.licenses": "MIT",
|
||||
"org.opencontainers.image.source": "https://github.com/lildude/ha-addon-teslamate/",
|
||||
"org.opencontainers.image.title": "Home Assistant Add-on: TeslaMate"
|
||||
}
|
||||
}
|
||||
+75
-69
@@ -1,71 +1,77 @@
|
||||
{
|
||||
"name": "TeslaMate",
|
||||
"version": "dev",
|
||||
"slug": "teslamate",
|
||||
"description": "A self-hosted data logger for your Tesla.",
|
||||
"url": "https://github.com/lildude/ha-addon-teslamate",
|
||||
"arch": [
|
||||
"armv7",
|
||||
"aarch64",
|
||||
"amd64"
|
||||
],
|
||||
"ingress": true,
|
||||
"init": false,
|
||||
"panel_icon": "mdi:car-connected",
|
||||
"panel_title": "TeslaMate",
|
||||
"options": {
|
||||
"database_user": null,
|
||||
"database_pass": null,
|
||||
"database_name": "teslamate",
|
||||
"database_host": null,
|
||||
"database_port": 5432,
|
||||
"database_ssl": false,
|
||||
"grafana_import_dashboards": true,
|
||||
"grafana_folder_name": "TeslaMate",
|
||||
"grafana_host": "a0d7b954-grafana",
|
||||
"grafana_port": 3000,
|
||||
"grafana_user": "",
|
||||
"grafana_pass": "",
|
||||
"disable_mqtt": false,
|
||||
"mqtt_host": "core-mosquitto",
|
||||
"mqtt_user": "",
|
||||
"mqtt_pass": "",
|
||||
"mqtt_tls": false,
|
||||
"mqtt_tls_accept_invalid_certs": false,
|
||||
"mqtt_namespace": "",
|
||||
"timezone": "Europe/London",
|
||||
"import_dir": "/share/teslamate",
|
||||
"default_geofence": "",
|
||||
"encryption_key": ""
|
||||
},
|
||||
"schema": {
|
||||
"database_user": "str",
|
||||
"database_pass": "password",
|
||||
"database_name": "str",
|
||||
"database_host": "str",
|
||||
"database_ssl": "bool",
|
||||
"database_port": "int",
|
||||
"grafana_import_dashboards": "bool",
|
||||
"grafana_folder_name": "str",
|
||||
"grafana_host": "str",
|
||||
"grafana_port": "int",
|
||||
"grafana_user": "str?",
|
||||
"grafana_pass": "password?",
|
||||
"disable_mqtt": "bool",
|
||||
"mqtt_host": "str?",
|
||||
"mqtt_user": "str?",
|
||||
"mqtt_pass": "password?",
|
||||
"mqtt_tls": "bool",
|
||||
"mqtt_tls_accept_invalid_certs": "bool",
|
||||
"mqtt_namespace": "str?",
|
||||
"timezone": "str",
|
||||
"import_dir": "str",
|
||||
"default_geofence": "str?",
|
||||
"encryption_key": "password?"
|
||||
},
|
||||
"map": [
|
||||
"share:rw"
|
||||
],
|
||||
"codenotary": "colin@symr.io",
|
||||
"image": "ghcr.io/lildude/ha-addon-teslamate-{arch}"
|
||||
"name": "TeslaMate",
|
||||
"version": "dev",
|
||||
"slug": "teslamate",
|
||||
"description": "A self-hosted data logger for your Tesla.",
|
||||
"url": "https://github.com/lildude/ha-addon-teslamate",
|
||||
"arch": [
|
||||
"aarch64",
|
||||
"amd64"
|
||||
],
|
||||
"hassio_api": true,
|
||||
"ingress": true,
|
||||
"init": false,
|
||||
"panel_icon": "mdi:car-connected",
|
||||
"panel_title": "TeslaMate",
|
||||
"options": {
|
||||
"database_user": null,
|
||||
"database_pass": null,
|
||||
"database_name": "teslamate",
|
||||
"database_host": null,
|
||||
"database_port": 5432,
|
||||
"database_ssl": false,
|
||||
"grafana_import_dashboards": true,
|
||||
"grafana_folder_name": "TeslaMate",
|
||||
"grafana_host": "a0d7b954-grafana",
|
||||
"grafana_port": 3000,
|
||||
"grafana_user": "",
|
||||
"grafana_pass": "",
|
||||
"disable_mqtt": false,
|
||||
"mqtt_host": "core-mosquitto",
|
||||
"mqtt_user": "",
|
||||
"mqtt_pass": "",
|
||||
"mqtt_tls": false,
|
||||
"mqtt_tls_accept_invalid_certs": false,
|
||||
"mqtt_namespace": "",
|
||||
"timezone": "Europe/London",
|
||||
"import_dir": "/share/teslamate",
|
||||
"default_geofence": "",
|
||||
"encryption_key": "",
|
||||
"env_vars": []
|
||||
},
|
||||
"schema": {
|
||||
"database_user": "str",
|
||||
"database_pass": "password",
|
||||
"database_name": "str",
|
||||
"database_host": "str",
|
||||
"database_ssl": "bool",
|
||||
"database_port": "int",
|
||||
"grafana_import_dashboards": "bool",
|
||||
"grafana_folder_name": "str",
|
||||
"grafana_host": "str",
|
||||
"grafana_port": "int",
|
||||
"grafana_user": "str?",
|
||||
"grafana_pass": "password?",
|
||||
"disable_mqtt": "bool",
|
||||
"mqtt_host": "str?",
|
||||
"mqtt_user": "str?",
|
||||
"mqtt_pass": "password?",
|
||||
"mqtt_tls": "bool",
|
||||
"mqtt_tls_accept_invalid_certs": "bool",
|
||||
"mqtt_namespace": "str?",
|
||||
"timezone": "str",
|
||||
"import_dir": "str",
|
||||
"default_geofence": "str?",
|
||||
"encryption_key": "password?",
|
||||
"env_vars": [
|
||||
{
|
||||
"name": "str?",
|
||||
"value": "str?"
|
||||
}
|
||||
]
|
||||
},
|
||||
"map": [
|
||||
"share:rw"
|
||||
],
|
||||
"image": "ghcr.io/lildude/ha-addon-teslamate-{arch}"
|
||||
}
|
||||
|
||||
Regular → Executable
+38
-15
@@ -11,13 +11,14 @@
|
||||
|
||||
set -o errexit
|
||||
|
||||
readonly HOST=$(bashio::config 'grafana_host')
|
||||
readonly PORT=$(bashio::config 'grafana_port')
|
||||
readonly USER=$(bashio::config 'grafana_user')
|
||||
readonly PASS=$(bashio::config 'grafana_pass')
|
||||
readonly DASHBOARDS_DIRECTORY="/dashboards"
|
||||
readonly FOLDER_NAME=$(bashio::config 'grafana_folder_name')
|
||||
HOST=$(bashio::config 'grafana_host')
|
||||
PORT=$(bashio::config 'grafana_port')
|
||||
USER=$(bashio::config 'grafana_user')
|
||||
PASS=$(bashio::config 'grafana_pass')
|
||||
DASHBOARDS_DIRECTORY="/dashboards"
|
||||
FOLDER_NAME=$(bashio::config 'grafana_folder_name')
|
||||
|
||||
readonly HOST PORT USER PASS DASHBOARDS_DIRECTORY FOLDER_NAME
|
||||
|
||||
|
||||
main() {
|
||||
@@ -31,7 +32,6 @@ main() {
|
||||
restore) restore;;
|
||||
*) exit 1;;
|
||||
esac
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,7 @@ backup() {
|
||||
dashboard_json=$(get_dashboard "$dashboard")
|
||||
|
||||
if [[ -z "$dashboard_json" ]]; then
|
||||
echo "ERROR:
|
||||
Couldn't retrieve dashboard $dashboard.
|
||||
"
|
||||
echo "ERROR: Couldn't retrieve dashboard $dashboard."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -56,10 +54,36 @@ backup() {
|
||||
|
||||
|
||||
restore() {
|
||||
bashio::log.info "Checking for Grafana folder: $FOLDER_NAME"
|
||||
FLD=$(curl --silent --show-error \
|
||||
bashio::log.info "Checking for Grafana datasource: TeslaMate"
|
||||
datasources=$(curl --silent --show-error \
|
||||
--user "$LOGIN" -H "Content-Type: application/json" \
|
||||
$URL/api/folders | jq ".[] | select(.title==\"$FOLDER_NAME\")")
|
||||
"$URL/api/datasources")
|
||||
|
||||
if [[ $datasources == *"statusCode"* ]]; then
|
||||
bashio::log.error "Error getting Grafana datasources: $(echo "$datasources" | jq -r .message)"
|
||||
bashio::log.debug "$datasources"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
DS=$(echo "$datasources" | jq ".[] | select(.name==\"TeslaMate\")")
|
||||
|
||||
if [[ -z "$DS" ]]; then
|
||||
bashio::log.error "'TeslaMate' datasource not found. Please create or rename your datasource. It must be named 'TeslaMate'."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
bashio::log.info "Checking for Grafana folder: $FOLDER_NAME"
|
||||
folders=$(curl --silent --show-error \
|
||||
--user "$LOGIN" -H "Content-Type: application/json" \
|
||||
"$URL/api/folders")
|
||||
|
||||
if [[ $folders == *"statusCode"* ]]; then
|
||||
bashio::log.error "Error getting Grafana folders: $(echo "$folders" | jq -r .message)"
|
||||
bashio::log.debug "$folders"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
FLD=$(echo "$folders" | jq ".[] | select(.title==\"$FOLDER_NAME\")")
|
||||
|
||||
if [[ -z "$FLD" ]]; then
|
||||
bashio::log.info "Not found... creating"
|
||||
@@ -72,7 +96,7 @@ restore() {
|
||||
"$URL/api/folders")
|
||||
fi
|
||||
|
||||
FOLDER_ID=$(echo $FLD | jq -r .id)
|
||||
FOLDER_ID=$(echo "$FLD" | jq -r .id)
|
||||
|
||||
if [[ -z "$FOLDER_ID" ]]; then
|
||||
bashio::log.error "Could not determine Grafana folder id"
|
||||
@@ -123,5 +147,4 @@ list_dashboards() {
|
||||
cut -d '/' -f2
|
||||
}
|
||||
|
||||
|
||||
main "$@"
|
||||
Regular → Executable
Regular → Executable
+7
-1
@@ -1,5 +1,11 @@
|
||||
#!/command/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
mkdir /run/nginx
|
||||
|
||||
bashio::log.info "Starting NGINX..."
|
||||
if [ -f /run/nginx ]; then
|
||||
rm -f /run/nginx
|
||||
fi
|
||||
mkdir -p /run/nginx
|
||||
|
||||
exec nginx -g 'daemon off;error_log /proc/1/fd/1 error;'
|
||||
@@ -0,0 +1 @@
|
||||
longrun
|
||||
Regular → Executable
Executable
+125
@@ -0,0 +1,125 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Database things
|
||||
DATABASE_HOST=$(bashio::config 'database_host')
|
||||
DATABASE_NAME=$(bashio::config 'database_name')
|
||||
DATABASE_PASS=$(bashio::config 'database_pass')
|
||||
DATABASE_PORT=$(bashio::config 'database_port')
|
||||
DATABASE_USER=$(bashio::config 'database_user')
|
||||
|
||||
# MQTT things
|
||||
DISABLE_MQTT=$(bashio::config 'disable_mqtt')
|
||||
MQTT_HOST=$(bashio::config 'mqtt_host')
|
||||
MQTT_NAMESPACE=$(bashio::config 'mqtt_namespace')
|
||||
MQTT_PASSWORD=$(bashio::config 'mqtt_pass')
|
||||
MQTT_TLS_ACCEPT_INVALID_CERTS=$(bashio::config 'mqtt_tls_accept_invalid_certs')
|
||||
MQTT_TLS=$(bashio::config 'mqtt_tls')
|
||||
MQTT_USERNAME=$(bashio::config 'mqtt_user')
|
||||
|
||||
# Other things
|
||||
IMPORT_DIR=$(bashio::config 'import_dir')
|
||||
PORT=4000
|
||||
TZ=$(bashio::config 'timezone')
|
||||
DEFAULT_GEOFENCE=$(bashio::config 'default_geofence')
|
||||
|
||||
encryption_key=$(bashio::config 'encryption_key')
|
||||
if bashio::config.is_empty 'encryption_key'; then
|
||||
encryption_key=$(openssl rand -hex 32)
|
||||
bashio::addon.option 'encryption_key' "$encryption_key"
|
||||
fi
|
||||
ENCRYPTION_KEY=$(bashio::config 'encryption_key')
|
||||
|
||||
ingress_entry=$(curl -X GET \
|
||||
-H "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-s http://supervisor/addons/self/info | \
|
||||
jq -r '.data.ingress_entry')
|
||||
|
||||
export URL_PATH=$ingress_entry
|
||||
|
||||
export DATABASE_HOST DATABASE_NAME DATABASE_PASS DATABASE_PORT DATABASE_USER \
|
||||
DISABLE_MQTT MQTT_HOST MQTT_NAMESPACE MQTT_PASSWORD MQTT_TLS_ACCEPT_INVALID_CERTS \
|
||||
MQTT_TLS MQTT_USERNAME IMPORT_DIR PORT TZ DEFAULT_GEOFENCE ENCRYPTION_KEY URL_PATH
|
||||
|
||||
# These are optional and applied last so we can override those set above if needed.
|
||||
for env_var in $(bashio::config 'env_vars|keys'); do
|
||||
name=$(bashio::config "env_vars[${env_var}].name")
|
||||
value=$(bashio::config "env_vars[${env_var}].value")
|
||||
bashio::log.debug "Setting Env Variable ${name} to ${value}"
|
||||
export "${name}=${value}"
|
||||
done
|
||||
|
||||
# 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
|
||||
# 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
|
||||
bashio::log.info "Database $DATABASE_NAME already exists"
|
||||
else
|
||||
if PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -qc "CREATE DATABASE \"$DATABASE_NAME\""; then
|
||||
bashio::log.info "Database $DATABASE_NAME created"
|
||||
else
|
||||
bashio::log.error "Failed to create database $DATABASE_NAME"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
bashio::log.error "PostgreSQL at '$DATABASE_HOST' is not ready or unreachable"
|
||||
exit 1
|
||||
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
|
||||
teslamate_ingress=$(bashio::addon.ingress_entry)
|
||||
grafana_ingress=$(bashio::addon.ingress_entry "$(bashio::supervisor.addons | grep grafana)")
|
||||
if [[ "$teslamate_ingress" == "$grafana_ingress" ]]; then
|
||||
grafana_ingress="** Grafana addon not found. Ensure the addon is installed and running. **"
|
||||
fi
|
||||
|
||||
bashio::log.notice ""
|
||||
bashio::log.notice "Configure TeslaMate settings by adding these values"
|
||||
bashio::log.notice "to the URL you use to access your Home Assistant instance:"
|
||||
bashio::log.notice ""
|
||||
bashio::log.notice "=> Web App: $teslamate_ingress"
|
||||
bashio::log.notice "=> Dashboards: $grafana_ingress"
|
||||
bashio::log.notice ""
|
||||
fi
|
||||
|
||||
# Set max open file limit to avoid memory allocation issues
|
||||
if [ "$(ulimit -Hn)" -gt 524288 ]; then
|
||||
ulimit -n 524288
|
||||
fi
|
||||
|
||||
bashio::log.info "Starting TeslaMate..."
|
||||
|
||||
cd /opt/app
|
||||
exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start
|
||||
@@ -0,0 +1 @@
|
||||
longrun
|
||||
@@ -1,76 +0,0 @@
|
||||
#!/usr/bin/with-contenv bashio
|
||||
# -*- bash -*-
|
||||
# shellcheck shell=bash
|
||||
set -e
|
||||
|
||||
# Database things
|
||||
DATABASE_HOST=$(bashio::config 'database_host')
|
||||
DATABASE_NAME=$(bashio::config 'database_name')
|
||||
DATABASE_PASS=$(bashio::config 'database_pass')
|
||||
DATABASE_PORT=$(bashio::config 'database_port')
|
||||
DATABASE_USER=$(bashio::config 'database_user')
|
||||
|
||||
# MQTT things
|
||||
DISABLE_MQTT=$(bashio::config 'disable_mqtt')
|
||||
MQTT_HOST=$(bashio::config 'mqtt_host')
|
||||
MQTT_NAMESPACE=$(bashio::config 'mqtt_namespace')
|
||||
MQTT_PASSWORD=$(bashio::config 'mqtt_pass')
|
||||
MQTT_TLS_ACCEPT_INVALID_CERTS=$(bashio::config 'mqtt_tls_accept_invalid_certs')
|
||||
MQTT_TLS=$(bashio::config 'mqtt_tls')
|
||||
MQTT_USERNAME=$(bashio::config 'mqtt_user')
|
||||
|
||||
# Other things
|
||||
IMPORT_DIR=$(bashio::config 'import_dir')
|
||||
PORT=4000
|
||||
TZ=$(bashio::config 'timezone')
|
||||
DEFAULT_GEOFENCE=$(bashio::config 'default_geofence')
|
||||
|
||||
encryption_key=$(bashio::config 'encryption_key')
|
||||
if bashio::config.is_empty 'encryption_key'; then
|
||||
encryption_key=$(openssl rand -hex 32)
|
||||
bashio::addon.option 'encryption_key' "$encryption_key"
|
||||
fi
|
||||
ENCRYPTION_KEY=$(bashio::config 'encryption_key')
|
||||
|
||||
ingress_entry=$(curl -X GET \
|
||||
-H "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-s http://supervisor/addons/self/info | \
|
||||
jq -r '.data.ingress_entry')
|
||||
|
||||
export URL_PATH=$ingress_entry
|
||||
|
||||
export DATABASE_HOST DATABASE_NAME DATABASE_PASS DATABASE_PORT DATABASE_USER \
|
||||
DISABLE_MQTT MQTT_HOST MQTT_NAMESPACE MQTT_PASSWORD MQTT_TLS_ACCEPT_INVALID_CERTS \
|
||||
MQTT_TLS MQTT_USERNAME IMPORT_DIR PORT TZ DEFAULT_GEOFENCE ENCRYPTION_KEY URL_PATH
|
||||
|
||||
# Import dashboards
|
||||
if bashio::config.true 'grafana_import_dashboards'; then
|
||||
/dashboards.sh restore
|
||||
fi
|
||||
|
||||
# Create the PostgreSQL database if it doesn't exist
|
||||
if pg_isready -h "$DATABASE_HOST" -p "$DATABASE_PORT" > /dev/null 2>&1; then
|
||||
bashio::log.info "Creating database '$DATABASE_NAME' on $DATABASE_HOST"
|
||||
|
||||
if [[ -n $(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -Atqc "\list $DATABASE_NAME") ]]; then
|
||||
bashio::log.info "Database $DATABASE_NAME already exists"
|
||||
else
|
||||
if PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -qc "CREATE DATABASE \"$DATABASE_NAME\""; then
|
||||
bashio::log.info "Database $DATABASE_NAME created"
|
||||
else
|
||||
bashio::log.error "Failed to create database $DATABASE_NAME"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
bashio::log.error "PostgreSQL at '$DATABASE_HOST' is not ready or unreachable"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
ulimit -n 1048576
|
||||
|
||||
bashio::log.info "Starting TeslaMate"
|
||||
|
||||
cd /opt/app
|
||||
exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start
|
||||
@@ -67,3 +67,6 @@ configuration:
|
||||
import_dir:
|
||||
name: TeslaFi Import Directory
|
||||
description: The directory which holds the TeslaFi export you would like to import into TeslaMate.
|
||||
env_vars:
|
||||
name: Environment Variables
|
||||
description: Set additional environment variables for TeslaMate which aren't currently exposed by the configuration options in this add-on.
|
||||
|
||||
Reference in New Issue
Block a user