TeslaMate: Difference between revisions

From KlavoWiki
Jump to navigationJump to search
No edit summary
Line 7: Line 7:


sudo reboot
sudo reboot
sudo apt install -y libffi-dev libssl-dev python3 python3-pip
</pre>
</pre>
<pre> sudo apt install docker-compose</pre>
Deprecated
<pre>sudo pip3 -v install docker-compose</pre>


= TeslaMate Install =
= TeslaMate Install =
Line 76: Line 69:
   mosquitto-conf:
   mosquitto-conf:
   mosquitto-data:</pre>
   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>




Line 85: Line 78:
MAILTO=me@myemail.com
MAILTO=me@myemail.com


@reboot sleep 15 && /usr/local/bin/docker-compose up -d
45 */8 * * * /usr/bin/bash /opt/teslamate-backup.sh
</pre>
</pre>


Line 100: Line 93:
= Commands =
= Commands =
<pre>
<pre>
Start docker-compose up -d
Start docker compose up -d
Stop docker-compose down
Stop docker compose down
Update docker-compose pull
Update docker compose pull


Logs docker-compose logs teslamate
Logs docker compose logs teslamate
</pre>
</pre>


Line 110: Line 103:


== Backup ==
== 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>
<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 117: Line 110:
=== 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 129: Line 124:
     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 exec -T database psql -U teslamate -d teslamate < 20220523-1645-teslamate.bck</pre>
 
<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 =
= Clean Up =

Revision as of 01:17, 27 November 2023

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
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

45 */8 * * * /usr/bin/bash /opt/teslamate-backup.sh

WEB User Interface

Within the WEB UI:

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

References

Docker Install
TeslaMate Install