TeslaMate: Difference between revisions
From KlavoWiki
Jump to navigationJump to search
(5 intermediate revisions by the same user not shown) | |||
Line 7: | Line 7: | ||
sudo reboot | sudo reboot | ||
</pre> | |||
= TeslaMate Install = | |||
<pre>vi /home/pi/docker-compose.yml</pre> | |||
<pre> | |||
services: | |||
teslamate: | |||
image: teslamate/teslamate:latest | |||
restart: always | |||
environment: | |||
- ENCRYPTION_KEY= #insert a secure key to encrypt your Tesla API tokens | |||
- DATABASE_USER=teslamate | |||
- DATABASE_PASS= #insert your secure database password! | |||
- DATABASE_NAME=teslamate | |||
- DATABASE_HOST=database | |||
- MQTT_HOST=mosquitto | |||
ports: | |||
- 80:4000 | |||
volumes: | |||
- ./import:/opt/app/import | |||
cap_drop: | |||
- all | |||
database: | |||
image: postgres:15 | |||
restart: always | |||
environment: | |||
- POSTGRES_USER=teslamate | |||
- POSTGRES_PASSWORD= #insert your secure database password! | |||
- POSTGRES_DB=teslamate | |||
volumes: | |||
- teslamate-db:/var/lib/postgresql/data | |||
grafana: | |||
image: teslamate/grafana:latest | |||
restart: always | |||
environment: | |||
- DATABASE_USER=teslamate | |||
- DATABASE_PASS= #insert your secure database password! | |||
- DATABASE_NAME=teslamate | |||
- DATABASE_HOST=database | |||
ports: | |||
- 88:3000 | |||
volumes: | |||
- teslamate-grafana-data:/var/lib/grafana | |||
mosquitto: | |||
image: eclipse-mosquitto:2 | |||
restart: always | |||
command: mosquitto -c /mosquitto-no-auth.conf | |||
# ports: | |||
# - 1883:1883 | |||
volumes: | |||
- mosquitto-conf:/mosquitto/config | |||
- mosquitto-data:/mosquitto/data | |||
volumes: | |||
<pre>docker | teslamate-db: | ||
teslamate-grafana-data: | |||
mosquitto-conf: | |||
mosquitto-data:</pre> | |||
<pre>docker compose -f /home/pi/docker-compose.yml pull</pre> | |||
== crontab == | == crontab == | ||
<pre>crontab -e -u pi</pre> | |||
<pre> | <pre> | ||
MAILFROM=no-reply@myemail.com | MAILFROM=no-reply@myemail.com | ||
MAILTO=me@myemail.com | MAILTO=me@myemail.com | ||
45 */8 * * * /usr/bin/bash /opt/teslamate-backup.sh | |||
</pre> | |||
== WEB User Interface == | |||
Within the WEB UI: | |||
* Select Setting | |||
* Under the URLs section based on docker-compose.yml | |||
** Web App: http://192.168.1.101 | |||
** Dashboards: http://192.168.1.101:88 | |||
The default username and password for Grafana is admin:admin | |||
The default ports if not chnaged are WEB 4000, Dashboards 3000. | |||
= Commands = | |||
<pre> | |||
Start docker compose up -d | |||
Stop docker compose down | |||
Update docker compose pull | |||
Logs docker compose logs teslamate | |||
</pre> | </pre> | ||
= Disaster Recovery = | |||
== Backup == | |||
<pre>docker compose -f /home/pi/docker-compose.yml exec -T database pg_dump -U teslamate teslamate > /home/pi/20220523-1645-teslamate.bck</pre> | |||
== Restore == | == Restore == | ||
Line 31: | Line 109: | ||
=== Erase Existing Database === | === Erase Existing Database === | ||
<pre> | <pre> | ||
docker-compose exec -T database psql -U teslamate << . | docker compose -f /home/pi/docker-compose.yml stop teslamate | ||
docker compose exec -T database psql -U teslamate << . | |||
drop schema public cascade; | drop schema public cascade; | ||
create schema public; | create schema public; | ||
Line 43: | Line 123: | ||
AS 'SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(\$1))*cos(radians(\$2))),public.earth()*cos(radians(\$1))*sin(radians(\$2))),public.earth()*sin(radians(\$1)))::public.earth'; | AS 'SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(\$1))*cos(radians(\$2))),public.earth()*cos(radians(\$1))*sin(radians(\$2))),public.earth()*sin(radians(\$1)))::public.earth'; | ||
. | . | ||
docker compose -f /home/pi/docker-compose.yml start teslamate | |||
</pre> | </pre> | ||
=== Restore Database === | === Restore Database === | ||
<pre>docker compose -f /home/pi/docker-compose.yml stop teslamate</pre> | |||
Erase existing database using the commands from the section above. <b>Note:</b>Don't start the teslamate service after the erase. | |||
<pre> | |||
docker compose exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck | |||
docker compose -f /home/pi/docker-compose.yml start teslamate | |||
</pre> | |||
= | = Clean Up = | ||
Over time there seems to be a growth in images. I belive this is becuase of upgrades. The older images can be deleted. | |||
<pre> | <pre> | ||
docker system df | |||
docker system prune -a | |||
</pre> | </pre> | ||
Latest revision as of 07:58, 28 March 2024
Docker Install
Assuming running Docker and TeslaMate as user pi.
sudo curl -sSL https://get.docker.com | sh sudo usermod -aG docker pi sudo reboot
TeslaMate Install
vi /home/pi/docker-compose.yml
services: teslamate: image: teslamate/teslamate:latest restart: always environment: - ENCRYPTION_KEY= #insert a secure key to encrypt your Tesla API tokens - DATABASE_USER=teslamate - DATABASE_PASS= #insert your secure database password! - DATABASE_NAME=teslamate - DATABASE_HOST=database - MQTT_HOST=mosquitto ports: - 80:4000 volumes: - ./import:/opt/app/import cap_drop: - all database: image: postgres:15 restart: always environment: - POSTGRES_USER=teslamate - POSTGRES_PASSWORD= #insert your secure database password! - POSTGRES_DB=teslamate volumes: - teslamate-db:/var/lib/postgresql/data grafana: image: teslamate/grafana:latest restart: always environment: - DATABASE_USER=teslamate - DATABASE_PASS= #insert your secure database password! - DATABASE_NAME=teslamate - DATABASE_HOST=database ports: - 88:3000 volumes: - teslamate-grafana-data:/var/lib/grafana mosquitto: image: eclipse-mosquitto:2 restart: always command: mosquitto -c /mosquitto-no-auth.conf # ports: # - 1883:1883 volumes: - mosquitto-conf:/mosquitto/config - mosquitto-data:/mosquitto/data volumes: teslamate-db: teslamate-grafana-data: mosquitto-conf: mosquitto-data:
docker compose -f /home/pi/docker-compose.yml pull
crontab
crontab -e -u pi
MAILFROM=no-reply@myemail.com MAILTO=me@myemail.com 45 */8 * * * /usr/bin/bash /opt/teslamate-backup.sh
WEB User Interface
Within the WEB UI:
- Select Setting
- Under the URLs section based on docker-compose.yml
- Web App: http://192.168.1.101
- Dashboards: http://192.168.1.101:88
The default username and password for Grafana is admin:admin The default ports if not chnaged are WEB 4000, Dashboards 3000.
Commands
Start docker compose up -d Stop docker compose down Update docker compose pull Logs docker compose logs teslamate
Disaster Recovery
Backup
docker compose -f /home/pi/docker-compose.yml exec -T database pg_dump -U teslamate teslamate > /home/pi/20220523-1645-teslamate.bck
Restore
While docker is running.
Erase Existing Database
docker compose -f /home/pi/docker-compose.yml stop teslamate docker compose exec -T database psql -U teslamate << . drop schema public cascade; create schema public; create extension cube; create extension earthdistance; CREATE OR REPLACE FUNCTION public.ll_to_earth(float8, float8) RETURNS public.earth LANGUAGE SQL IMMUTABLE STRICT PARALLEL SAFE AS 'SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(\$1))*cos(radians(\$2))),public.earth()*cos(radians(\$1))*sin(radians(\$2))),public.earth()*sin(radians(\$1)))::public.earth'; . docker compose -f /home/pi/docker-compose.yml start teslamate
Restore Database
docker compose -f /home/pi/docker-compose.yml stop teslamate
Erase existing database using the commands from the section above. Note:Don't start the teslamate service after the erase.
docker compose exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck docker compose -f /home/pi/docker-compose.yml start teslamate
Clean Up
Over time there seems to be a growth in images. I belive this is becuase of upgrades. The older images can be deleted.
docker system df docker system prune -a