Compare commits

...
37 Commits
Author SHA1 Message Date
Colin Seymour 04eb3228bd Use a PostgreSQL version agnostic method of determining if the database exists (#77)
Use PG version agnostic method to find DB
2025-03-19 11:19:28 +00:00
renovate[bot] a5180bcb8e Update docker/login-action action to v3.4.0 (#74)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-03-14 11:05:24 +00:00
renovate[bot] f2d6fcd514 Update home-assistant/builder action to v2025 (#72)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-02-25 16:56:17 +00:00
Colin Seymour 540732b90a Document additional TeslaMate configuration changes (#68)
* Add TeslaMate cfg helper message to log

* Add TeslaMate config details
2025-02-02 09:48:15 +00:00
Colin Seymour 33d50cce75 Document and enforce the Grafana datasource name should be TeslaMate (#65)
* Document that the Grafana datasource must be TeslaMate

* Check datasource name TeslaMate is available
2025-01-27 18:21:43 +00:00
renovate[bot] b5ab114562 Update softprops/action-gh-release action to v2.2.1 (#61)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2025-01-08 11:00:56 +00:00
renovate[bot] b17ded97f6 Update softprops/action-gh-release action to v2.2.0 (#60) 2024-12-11 07:52:24 +00:00
renovate[bot] 3a9e27e9ac Update TeslaMate to v1.32.0 (#57)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-11-23 18:23:33 +00:00
renovate[bot] fb4eff6570 Update softprops/action-gh-release action to v2.1.0 (#56) 2024-11-12 08:00:04 +00:00
renovate[bot] d54d94a480 Update softprops/action-gh-release action to v2.0.9 (#55)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-31 20:18:25 +00:00
renovate[bot] a979b4fdf6 Update TeslaMate to v1.31.1 (#54)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-29 18:55:48 +00:00
Colin Seymour 86fe972431 Switch to new S6 service configuration (#40)
* Add new service files

* Remove moved file

* Move files

* Add exec perm

* Update for new services

* Remove xz-utils after use

* Check labels

* Move labels to build

* Typo

* List images

* Fixit

* Add super lint

* Update labels

* Whoops

* Remove superlint

* Add teslamate dependency

* Fix url
2024-10-27 16:43:53 +00:00
renovate[bot]andColin Seymour 3d167fc6ee Update TeslaMate to v1.31.0 (#51)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Colin Seymour <colin@symr.io>
2024-10-27 16:02:40 +00:00
renovate[bot] 0013f5605b Update actions/checkout action to v4.2.2 (#49)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-27 15:56:16 +00:00
Colin Seymour 826c07ace9 Consolidate versions and Renovate config to a single file (#48)
* Consolidate versions and renovate config to a single file

* Remove unneeded lint check

* Add BUILD_FROM
2024-10-27 15:55:21 +00:00
renovate[bot] 7bfa32be3f Update actions/checkout action to v4.2.1 (#47)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-10-08 08:51:44 +01:00
renovate[bot] b9e37e9f32 Update actions/checkout action to v4.2.0 (#46)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-09-26 10:14:52 +01:00
Colin Seymour 945a7c4822 Fix release note gathering (#44)
Parse json
2024-09-22 12:27:00 +01:00
Colin Seymour 4567555071 Quote DB name in existance check (#43)
Quote DB name
2024-09-13 09:56:26 +01:00
Colin Seymour 694b43eb93 Only include Teslamate release notes if updated since last release (#38) 2024-08-30 13:10:24 +01:00
Colin Seymour 04e01df081 Make startup scripts robust (#37)
* Clean up file if exists and mkdir -p

* Make importing dashboards more robust

* Update info msgs
2024-08-30 12:45:36 +01:00
renovate[bot] d97377bc0e Update home-assistant/builder action to v2024.08.2 (#30)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-08-24 09:33:15 +01:00
Colin Seymour 0aca1dd417 Fix image URL (#33) 2024-08-24 09:32:36 +01:00
renovate[bot]andColin Seymour 556a2f23af Update softprops/action-gh-release action to v2.0.8 (#26)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Colin Seymour <colin@symr.io>
2024-08-12 06:56:30 +01:00
Colin Seymour a73430c34d Add optional env vars config option (#29)
* Add optional env vars config option

* Don't use master builder

It's borked - https://github.com/home-assistant/builder/issues/212

* Use specific builder version
2024-08-11 12:22:12 +01:00
Colin Seymour 2b40dd2668 Fix Postgres link (#28)
* Don't default to old Postgres

* Fix postgres link
2024-07-22 14:48:06 +01:00
renovate[bot] 1757ed78ff Update docker/login-action action to v3.3.0 (#27)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-22 14:31:04 +01:00
Colin Seymour f48e92dc71 Remove default Postgres configuration and add-on suggestion (#25)
Don't default to old Postgres
2024-07-18 18:05:13 +01:00
Colin Seymour 306653220b Fix renovate configuration error (#24)
Remove extra comma
2024-07-18 17:41:36 +01:00
renovate[bot]andColin Seymour 2c729d4f75 Update TeslaMate to v1.30.1 (#17)
* Update TeslaMate to v1.30.1

* Update Dockerfile

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Colin Seymour <colin@symr.io>
2024-07-18 16:26:07 +01:00
renovate[bot] 89abf45735 Update softprops/action-gh-release action to v2.0.7 (#20)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-18 16:25:05 +01:00
renovate[bot] 3c1545d9e4 Update actions/checkout action to v4.1.7 (#14)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-07-18 16:21:45 +01:00
Colin Seymour 64f0213e30 Fix database check and creation (#23)
* Refactor db check and create

* Make exit more accurate
2024-07-18 16:20:36 +01:00
Colin Seymour 213a2205fc Clearly differentiate add-on changes (#16) 2024-06-16 08:18:20 +01:00
Colin Seymour a9c53f4cd5 Update Renovate configuration and fix inclusion of TeslaMate release notes in add-on changelog (#13)
* Fix renovate config

* Fix including TeslaMate release notes
2024-06-12 14:57:17 +01:00
Colin Seymour b964d2dbc9 Limit Renovate managers (#12)
Limit managers
2024-06-11 14:40:50 +01:00
Colin Seymour 4ab0062498 Renovate and releaser improvements (#11)
* Update all files from release

* Pull in TeslaMate release notes
2024-06-11 11:36:45 +01:00
26 changed files with 212 additions and 111 deletions
+3 -1
View File
@@ -8,11 +8,13 @@
"prBodyTemplate": "{{{table}}}{{{warnings}}}{{{notes}}}{{{changelogs}}}", "prBodyTemplate": "{{{table}}}{{{warnings}}}{{{notes}}}{{{changelogs}}}",
"semanticCommits": "disabled", "semanticCommits": "disabled",
"commitMessageTopic": "{{#if (containsString depName 'teslamate')}}TeslaMate{{else}}{{depName}}{{/if}}", "commitMessageTopic": "{{#if (containsString depName 'teslamate')}}TeslaMate{{else}}{{depName}}{{/if}}",
"enabledManagers": ["custom.regex", "github-actions"],
"customManagers": [ "customManagers": [
{ {
"customType": "regex", "customType": "regex",
"fileMatch": "^build\\.json$", "fileMatch": "^build.json$",
"matchStrings": [ "matchStrings": [
"\"teslamate/teslamate:(?<currentValue>\\d+\\.\\d+\\.\\d+)\"",
"\"teslamate_version\": \"(?<currentValue>\\d+\\.\\d+\\.\\d+)\"" "\"teslamate_version\": \"(?<currentValue>\\d+\\.\\d+\\.\\d+)\""
], ],
"datasourceTemplate": "github-releases", "datasourceTemplate": "github-releases",
+1 -11
View File
@@ -14,19 +14,9 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: ⤵️ Check out code from GitHub - name: ⤵️ Check out code from GitHub
uses: actions/checkout@v4.1.6 uses: actions/checkout@v4.2.2
- name: 🚀 Run Home Assistant Add-on Lint - name: 🚀 Run Home Assistant Add-on Lint
uses: frenck/action-addon-linter@v2 uses: frenck/action-addon-linter@v2
with: with:
path: "./" 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"
+3 -3
View File
@@ -23,7 +23,7 @@ jobs:
steps: steps:
- name: Checkout the repository - name: Checkout the repository
uses: actions/checkout@v4.1.6 uses: actions/checkout@v4.2.2
- name: Get version - name: Get version
run: | run: |
@@ -35,14 +35,14 @@ jobs:
fi fi
- name: Login to GitHub Container Registry - name: Login to GitHub Container Registry
uses: docker/login-action@v3.2.0 uses: docker/login-action@v3.4.0
with: with:
registry: ghcr.io registry: ghcr.io
username: ${{ github.repository_owner }} username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }} password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and publish - name: Build and publish
uses: home-assistant/builder@master uses: home-assistant/builder@2025.02.0
with: with:
args: | args: |
--${{ matrix.arch }} \ --${{ matrix.arch }} \
+15 -2
View File
@@ -32,6 +32,18 @@ jobs:
with: with:
semver-input: ${{ env.latest_release }} semver-input: ${{ env.latest_release }}
increment: ${{ github.event.inputs.semverIncrement }} increment: ${{ github.event.inputs.semverIncrement }}
- name: Get TeslaMate release notes
run: |
touch CHANGELOG.txt
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
fi
echo -e "---\n\n## Add-on Release Notes\n\n" >> CHANGELOG.txt
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Create tag - name: Create tag
run: | run: |
git config --global user.email "actions.no-reply@github.com" git config --global user.email "actions.no-reply@github.com"
@@ -40,15 +52,16 @@ jobs:
git push --tags git push --tags
working-directory: ${{ github.workspace }}/teslamate working-directory: ${{ github.workspace }}/teslamate
- name: Create release - name: Create release
uses: softprops/action-gh-release@v2.0.5 uses: softprops/action-gh-release@v2.2.1
with: with:
tag_name: v${{ steps.semver.outputs.semver }} tag_name: v${{ steps.semver.outputs.semver }}
body_path: CHANGELOG.txt
generate_release_notes: true generate_release_notes: true
draft: false draft: false
prerelease: false prerelease: false
token: ${{ secrets.GITHUB_TOKEN }} token: ${{ secrets.GITHUB_TOKEN }}
- name: Checkout addon repo - name: Checkout addon repo
uses: actions/checkout@v4.1.6 uses: actions/checkout@v4.2.2
with: with:
path: repo path: repo
repository: lildude/ha-addons repository: lildude/ha-addons
+6 -2
View File
@@ -32,13 +32,17 @@ jobs:
steps: steps:
- name: Check out repository - name: Check out repository
uses: actions/checkout@v4.1.6 uses: actions/checkout@v4.2.2
- name: Build add-on - name: Build add-on
uses: home-assistant/builder@master uses: home-assistant/builder@2025.02.0
with: with:
args: | args: |
--test \ --test \
--${{ matrix.arch }} \ --${{ matrix.arch }} \
--target /data/ \ --target /data/ \
--addon --addon
- name: Image labels
run: |
docker inspect ghcr.io/lildude/ha-addon-teslamate-${{ matrix.arch }} --format='{{json .Config.Labels}}' | jq
+38 -3
View File
@@ -16,6 +16,7 @@ This add-on allows you to run [TeslaMate][teslamate] on your Home Assistant serv
## Configuration ## Configuration
The configuration is self-explanatory, but essentially we need details about accessing the PostgreSQL database, Grafana and optionally MQTT. 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 ### Options
@@ -29,7 +30,7 @@ Remember to restart the add-on when the configuration is changed.
- `database_port`: The port your PostgreSQL server is listening on. Default: `5432`. - `database_port`: The port your PostgreSQL server is listening on. Default: `5432`.
- `database_host`: The hostname of your PostgreSQL server. Default: `29b65938-postgres` for the [PostgreSQL add-on][postgres]. - `database_host`: The hostname of your PostgreSQL server.
- `database_name`: The name of the PostgreSQL database. Default: `teslamate`. - `database_name`: The name of the PostgreSQL database. Default: `teslamate`.
@@ -105,6 +106,8 @@ _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: Once you have Grafana up and running, you'll need to configure a data source to read data from the PostgreSQL database:
‼️ **Note**: The name must be `TeslaMate` as all the dashboards expect the datasource to use this name.
![Grafana Postgres data source][grafana-datasource] ![Grafana Postgres data source][grafana-datasource]
#### Other Options #### Other Options
@@ -115,6 +118,39 @@ 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`. - `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 addon, 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 addon 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.
## Data Import from TeslaFi ## Data Import from TeslaFi
It is now possible to import CSV data from TeslaFi, refer to the [official docs][teslafi-import]. It is now possible to import CSV data from TeslaFi, refer to the [official docs][teslafi-import].
@@ -135,9 +171,8 @@ Follow this process:
[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
[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
[mosquitto-docs]: https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md [mosquitto-docs]: https://github.com/home-assistant/addons/blob/master/mosquitto/DOCS.md
[postgres]: https://github.com/matt-FFFFFF/hassio-addon-postgres
[samba-addon]: https://github.com/home-assistant/addons/blob/master/samba/DOCS.md [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 [ssh-addon]: https://github.com/home-assistant/addons/blob/master/ssh/DOCS.md
[teslafi-import]: https://docs.teslamate.org/docs/import/teslafi [teslafi-import]: https://docs.teslamate.org/docs/import/teslafi
+10 -26
View File
@@ -1,8 +1,11 @@
FROM teslamate/grafana:1.29.1 as grafana ARG BUILD_FROM
ARG teslamate_version
FROM teslamate/grafana:${teslamate_version} as grafana
#--- #---
FROM teslamate/teslamate:1.29.1 ARG BUILD_FROM
FROM $BUILD_FROM
ARG BUILD_ARCH ARG BUILD_ARCH
ARG BASHIO_VERSION=0.16.2 ARG BASHIO_VERSION=0.16.2
@@ -22,7 +25,6 @@ RUN \
set -x \ set -x \
&& apt-get update && apt-get install -y --no-install-recommends \ && apt-get update && apt-get install -y --no-install-recommends \
bash \ bash \
bind9utils \
ca-certificates \ ca-certificates \
curl \ curl \
jq \ jq \
@@ -30,7 +32,6 @@ RUN \
postgresql-client \ postgresql-client \
tzdata \ tzdata \
xz-utils \ xz-utils \
&& rm -rf /var/lib/apt/lists/* \
&& S6_ARCH="${BUILD_ARCH}" \ && S6_ARCH="${BUILD_ARCH}" \
&& if [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; \ && if [ "${BUILD_ARCH}" = "amd64" ]; then S6_ARCH="x86_64"; \
elif [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \ elif [ "${BUILD_ARCH}" = "armv7" ]; then S6_ARCH="arm"; fi \
@@ -38,33 +39,16 @@ RUN \
&& 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-${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-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 / \ && 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 \ && 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 \ && 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 \ && mv /tmp/bashio/lib /usr/lib/bashio \
&& apt purge -y xz-utils \
&& ln -s /usr/lib/bashio/bashio /usr/bin/bashio \ && 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 / COPY rootfs /
RUN chmod a+x /*.sh COPY --from=grafana /dashboards /dashboards
COPY --from=grafana /dashboards_internal /dashboards
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
# S6-Overlay # S6-Overlay
ENTRYPOINT ["/init"] 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"
+2 -4
View File
@@ -25,9 +25,7 @@ Thanks to @matt-FFFFFF for maintaining this add-on in the past.
## Requirements ## Requirements
TeslaMate needs a PostgreSQL database. TeslaMate needs a PostgreSQL database.
All development and testing has been done using [PostgreSQL add-on][postgres] for convenience but you're welcome to use your own. I recommend using the [PostgreSQL add-on][alexbelgium-postgres] from @alexbelgium's repository if you aren't already using Postgres.
For convenience, my [add-ons repository][addons-repo] includes configuration that points to the [PostgreSQL add-on][postgres] so you can install everything from one repo.
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].
@@ -69,13 +67,13 @@ 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
[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
[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
[mqtt]: https://www.home-assistant.io/integrations/mqtt [mqtt]: https://www.home-assistant.io/integrations/mqtt
[postgres]: https://github.com/matt-FFFFFF/hassio-addon-postgres
[repo-btn]: https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg [repo-btn]: https://my.home-assistant.io/badges/supervisor_add_addon_repository.svg
[sponsor-badge]: https://img.shields.io/badge/Sponsor_Me-%E2%9D%A4-ec6cb9?logo=GitHub [sponsor-badge]: https://img.shields.io/badge/Sponsor_Me-%E2%9D%A4-ec6cb9?logo=GitHub
[teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore [teslamate-backup]: https://docs.teslamate.org/docs/maintenance/backup_restore
+13 -4
View File
@@ -1,13 +1,22 @@
{ {
"build_from": { "build_from": {
"aarch64": "teslamate/teslamate:not-used", "aarch64": "teslamate/teslamate:1.32.0",
"amd64": "teslamate/teslamate:not-used", "amd64": "teslamate/teslamate:1.32.0",
"armv7": "teslamate/teslamate:not-used" "armv7": "teslamate/teslamate:1.32.0"
}, },
"args": { "args": {
"teslamate_version": "1.29.1" "teslamate_version": "1.32.0"
}, },
"codenotary": { "codenotary": {
"signer": "colin@symr.io" "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"
} }
} }
+8 -3
View File
@@ -17,7 +17,7 @@
"database_user": null, "database_user": null,
"database_pass": null, "database_pass": null,
"database_name": "teslamate", "database_name": "teslamate",
"database_host": "29b65938-postgres", "database_host": null,
"database_port": 5432, "database_port": 5432,
"database_ssl": false, "database_ssl": false,
"grafana_import_dashboards": true, "grafana_import_dashboards": true,
@@ -36,7 +36,8 @@
"timezone": "Europe/London", "timezone": "Europe/London",
"import_dir": "/share/teslamate", "import_dir": "/share/teslamate",
"default_geofence": "", "default_geofence": "",
"encryption_key": "" "encryption_key": "",
"env_vars": []
}, },
"schema": { "schema": {
"database_user": "str", "database_user": "str",
@@ -61,7 +62,11 @@
"timezone": "str", "timezone": "str",
"import_dir": "str", "import_dir": "str",
"default_geofence": "str?", "default_geofence": "str?",
"encryption_key": "password?" "encryption_key": "password?",
"env_vars": [{
"name": "str?",
"value": "str?"
}]
}, },
"map": [ "map": [
"share:rw" "share:rw"
+38 -15
View File
@@ -11,13 +11,14 @@
set -o errexit set -o errexit
readonly HOST=$(bashio::config 'grafana_host') HOST=$(bashio::config 'grafana_host')
readonly PORT=$(bashio::config 'grafana_port') PORT=$(bashio::config 'grafana_port')
readonly USER=$(bashio::config 'grafana_user') USER=$(bashio::config 'grafana_user')
readonly PASS=$(bashio::config 'grafana_pass') PASS=$(bashio::config 'grafana_pass')
readonly DASHBOARDS_DIRECTORY="/dashboards" DASHBOARDS_DIRECTORY="/dashboards"
readonly FOLDER_NAME=$(bashio::config 'grafana_folder_name') FOLDER_NAME=$(bashio::config 'grafana_folder_name')
readonly HOST PORT USER PASS DASHBOARDS_DIRECTORY FOLDER_NAME
main() { main() {
@@ -31,7 +32,6 @@ main() {
restore) restore;; restore) restore;;
*) exit 1;; *) exit 1;;
esac esac
} }
@@ -42,9 +42,7 @@ backup() {
dashboard_json=$(get_dashboard "$dashboard") dashboard_json=$(get_dashboard "$dashboard")
if [[ -z "$dashboard_json" ]]; then if [[ -z "$dashboard_json" ]]; then
echo "ERROR: echo "ERROR: Couldn't retrieve dashboard $dashboard."
Couldn't retrieve dashboard $dashboard.
"
exit 1 exit 1
fi fi
@@ -56,10 +54,36 @@ backup() {
restore() { restore() {
bashio::log.info "Checking for Grafana folder: $FOLDER_NAME" bashio::log.info "Checking for Grafana datasource: TeslaMate"
FLD=$(curl --silent --show-error \ datasources=$(curl --silent --show-error \
--user "$LOGIN" -H "Content-Type: application/json" \ --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 if [[ -z "$FLD" ]]; then
bashio::log.info "Not found... creating" bashio::log.info "Not found... creating"
@@ -72,7 +96,7 @@ restore() {
"$URL/api/folders") "$URL/api/folders")
fi fi
FOLDER_ID=$(echo $FLD | jq -r .id) FOLDER_ID=$(echo "$FLD" | jq -r .id)
if [[ -z "$FOLDER_ID" ]]; then if [[ -z "$FOLDER_ID" ]]; then
bashio::log.error "Could not determine Grafana folder id" bashio::log.error "Could not determine Grafana folder id"
@@ -123,5 +147,4 @@ list_dashboards() {
cut -d '/' -f2 cut -d '/' -f2
} }
main "$@" main "$@"
+14
View File
@@ -0,0 +1,14 @@
#!/command/with-contenv bashio
# -*- bash -*-
# shellcheck shell=bash
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
case "${1}" in
1)
bashio::log.error "Nginx encountered an error, halting add-on"
;;
*)
bashio::log.error "Nginx crashed, halting add-on"
;;
esac
/run/s6/basedir/bin/halt
fi
+7 -1
View File
@@ -1,5 +1,11 @@
#!/command/with-contenv bashio #!/command/with-contenv bashio
# -*- bash -*- # -*- bash -*-
# shellcheck shell=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;' exec nginx -g 'daemon off;error_log /proc/1/fd/1 error;'
+1
View File
@@ -0,0 +1 @@
longrun
+15
View File
@@ -0,0 +1,15 @@
#!/command/with-contenv bashio
# -*- bash -*-
# shellcheck shell=bash
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
case "${1}" in
1)
bashio::log.error "TeslaMate encountered an error, halting add-on"
;;
*)
bashio::log.error "TeslaMate crashed, halting add-on"
;;
esac
/run/s6/basedir/bin/halt
fi
+31 -15
View File
@@ -44,36 +44,52 @@ export DATABASE_HOST DATABASE_NAME DATABASE_PASS DATABASE_PORT DATABASE_USER \
DISABLE_MQTT MQTT_HOST MQTT_NAMESPACE MQTT_PASSWORD MQTT_TLS_ACCEPT_INVALID_CERTS \ 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 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
# Import dashboards # Import dashboards
if bashio::config.true 'grafana_import_dashboards'; then if bashio::config.true 'grafana_import_dashboards'; then
/dashboards.sh restore /dashboards.sh restore || bashio::log.error "Failed to import dashboards"
fi fi
# Create the PostgreSQL database if it doesn't exist # Create the PostgreSQL database if it doesn't exist
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 "Creating database $DATABASE_NAME on $DATABASE_HOST" bashio::log.info "Checking for database '$DATABASE_NAME' on $DATABASE_HOST"
res=$(PGPASSWORD="$DATABASE_PASS" psql -h "$DATABASE_HOST" -p "$DATABASE_PORT" -U "$DATABASE_USER" postgres -c "CREATE DATABASE $DATABASE_NAME" 2>&1) || true 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
case "$res" in bashio::log.info "Database $DATABASE_NAME already exists"
"CREATE DATABASE") 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" bashio::log.info "Database $DATABASE_NAME created"
;; else
*"already exists"*) bashio::log.error "Failed to create database $DATABASE_NAME"
bashio::log.info "Database $DATABASE_NAME already exists"
;;
*)
bashio::log.error "Failed to create database $DATABASE_NAME: $res"
exit 1 exit 1
;; fi
esac fi
else else
bashio::log.error "PostgreSQL is not ready" bashio::log.error "PostgreSQL at '$DATABASE_HOST' is not ready or unreachable"
exit 1 exit 1
fi 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))
bashio::log.info "Configure TeslaMate settings by adding these values
to the URL you use to access your Home Assistant instance:
=> Web App: $teslamate_ingress
=> Dashboards: $grafana_ingress
"
fi
ulimit -n 1048576 ulimit -n 1048576
bashio::log.info "Starting TeslaMate" bashio::log.info "Starting TeslaMate..."
cd /opt/app cd /opt/app
exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start exec $(/usr/bin/env sh) /entrypoint.sh bin/teslamate start
@@ -0,0 +1 @@
longrun
-9
View File
@@ -1,9 +0,0 @@
#!/command/with-contenv bashio
# -*- bash -*-
# shellcheck shell=bash
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
bashio::log.warning "Nginx crashed, halting add-on"
/run/s6/basedir/bin/halt
fi
bashio::log.info "Nginx stopped, restarting..."
-9
View File
@@ -1,9 +0,0 @@
#!/command/with-contenv bashio
# -*- bash -*-
# shellcheck shell=bash
if [[ "${1}" -ne 0 ]] && [[ "${1}" -ne 256 ]]; then
bashio::log.warning "TeslaMate crashed, halting add-on"
/run/s6/basedir/bin/halt
fi
bashio::log.info "TeslaMate stopped, restarting..."
+3
View File
@@ -67,3 +67,6 @@ configuration:
import_dir: import_dir:
name: TeslaFi Import Directory name: TeslaFi Import Directory
description: The directory which holds the TeslaFi export you would like to import into TeslaMate. 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.