TeslaMate: Difference between revisions
From KlavoWiki
Jump to navigationJump to search
No edit summary |
|||
Line 14: | Line 14: | ||
= TeslaMate Install = | = TeslaMate Install = | ||
<pre>vi /home/pi/docker-compose.yml</pre> | |||
<pre>version: "3" | |||
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:14 | |||
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:</pre> | |||
<pre>docker-compose -f /home/pi/docker-compose.yml pull</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 | ||
Line 25: | Line 84: | ||
@reboot sleep 15 && /usr/local/bin/docker-compose up & | @reboot sleep 15 && /usr/local/bin/docker-compose up & | ||
</pre> | </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 | |||
Stop docker-compose down | |||
Update docker-compose pull | |||
Logs docker-compose logs teslamate | |||
</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 47: | Line 130: | ||
=== Restore Database === | === Restore Database === | ||
<pre>docker-compose exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck</pre> | <pre>docker-compose exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck</pre> | ||
= References = | = References = |
Revision as of 13:09, 22 July 2022
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 sudo apt install -y libffi-dev libssl-dev python3 python3-pip sudo pip3 -v install docker-compose
TeslaMate Install
vi /home/pi/docker-compose.yml
version: "3" 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:14 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 @reboot sleep 15 && /usr/local/bin/docker-compose up &
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 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 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'; .
Restore Database
docker-compose exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck