Skip to main content

Manual install (FreeBSD)

This document provides the necessary steps for installation of TeslaMate in a FreeBSD jail. The recommended and most straightforward installation approach is through the use of Docker, however this walkthrough provides the necessary steps for manual installation in a FreeBSD 13.0 environment. It assumes that pre-requisites are met and only basic instructions are provided and should also work in FreeBSD before 13.0.

Requirements#

Click on the following items to view detailed installation steps.

bash
pkg install bashbash

For simplicity reasons, follow the rest of the tutorial in bash rather the csh.

git
pkg install git
Erlang (v21+)
pkg install erlang
Elixir (v1.11+)

Unfortunately the Elixir part is not well updated in FreeBSD ports. Hence the latest supported version for Erlang 21 (latest in FreeBSD ports) is Elixir 1.11.

We will need to compile it from source, which is pretty easy though.

pkg install gmake
cd /usr/local/srcgit clone https://github.com/elixir-lang/elixir.gitcd elixirgit checkout v1.11.4gmake clean testgmake installelixir --version
Postgres (v12+)
pkg install postgressql(12|13)-serverecho postgres_enable="yes" >> /etc/rc.conf
Grafana (v7.2+) & Plugins
pkg install grafana7echo grafana_enable="yes" >> /etc/rc.conf
An MQTT Broker (e.g. Mosquitto)
pkg install mosquittoecho mosquitto_enable="yes" >> /etc/rc.conf
Node.js (v14+)
pkg install node(12|14|)

Clone TeslaMate git repository#

The following command will clone the source files for the TeslaMate project. This should be run in an appropriate directory within which you would like to install TeslaMate. You should also record this path and provide them to the startup scripts proposed at the end of this guide.

cd /usr/local/src
git clone https://github.com/adriankumpf/teslamate.gitcd teslamate
git checkout $(git describe --tags `git rev-list --tags --max-count=1`) # Checkout the latest stable version

Create PostgreSQL database#

The following commands will create a database called teslamate on the PostgreSQL database server, and a user called teslamate. When creating the teslamate user, you will be prompted to enter a password for the user interactively. This password should be recorded and provided as an environment variable in the startup script at the end of this guide.

psqlpostgres=# create database teslamate;postgres=# create user teslamate with encrypted password 'secret';postgres=# grant all privileges on database teslamate to teslamate;postgres=# ALTER USER teslamate WITH SUPERUSER;postgres=# \q

Note: The superuser privileges can be revoked after running the initial database migrations.

Compile Elixir Project#

mix local.hex --force; mix local.rebar --force
mix deps.get --only prodnpm install --prefix ./assets && npm run deploy --prefix ./assets
export MIX_ENV=prodmix do phx.digest, release --overwrite

Starting TeslaMate at boot time#

Create FreeBSD service definition /usr/local/etc/rc.d/teslamate#

# PROVIDE: teslamate# REQUIRE: DAEMON# KEYWORD: teslamate,tesla
. /etc/rc.subr
name=teslamatercvar=teslamate_enable
load_rc_config $name
user=teslamategroup=teslamate
## DO NOT CHANGE THESE DEFAULT VALUES HERE# SET THEM IN THE /etc/rc.conf FILE#teslamate_enable=${teslamate_enable-"NO"}pidfile=${teslamate_pidfile-"/var/run/${name}.pid"}
teslamate_enable_mqtt=${teslamate_enable_mqtt-"FALSE"}teslamate_db_port=${teslamate_db_port-"5432"}
HTTP_BINDING_ADDRESS="0.0.0.0"; export HTTP_BINDING_ADDRESSHOME="/usr/local/src/teslamate"; export HOMEPORT=${teslamate_port-"4000"}; export PORTTZ=${teslamate_timezone-"Europe/Berlin"}; export TZLANG=${teslamate_locale-"en_US.UTF-8"}; export LANGLC_CTYPE=${teslamate_locale-"en_US.UTF-8"}; export LC_TYPEDATABASE_NAME=${teslamate_db-"teslamate"}; export DATABASE_NAMEDATABASE_HOST=${teslamate_db_host-"localhost"}; export DATABASE_HOSTDATABASE_USER=${teslamate_db_user-"teslamate"}; export DATABASE_USERDATABASE_PASS=${teslamate_db_pass}; export DATABASE_PASSDISABLE_MQTT=${teslamate_mqtt_enable-"FALSE"}; export DISABLE_MQTTMQTT_HOST=${teslamate_mqtt_host-"localhost"}; export MQTT_HOSTVIRTUAL_HOST=${teslamate_virtual_host-"teslamate.example.com"}; export VIRTUAL_HOST
COMMAND=${teslamate_command-"${HOME}/_build/prod/rel/teslamate/bin/teslamate"}
teslamate_start(){  ${COMMAND} eval "TeslaMate.Release.migrate"  ${COMMAND} daemon}
start_cmd="${name}_start"stop_cmd="${COMMAND} stop"status_cmd="${COMMAND} pid"

run_rc_command "$1"

Update /etc/rc.conf#

echo teslamate_enable="YES" >> /etc/rc.confecho teslamate_db_host="localhost"  >> /etc/rc.confecho teslamate_port="5432"  >> /etc/rc.confecho teslamate_db_pass="<super secret>" >> /etc/rc.confecho teslamate_disable_mqtt="true" >> /etc/rc.conf

Start service#

service teslamate start

Import Grafana Dashboards#

  1. Visit localhost:3000 and log in. The default credentials are: admin:admin.

  2. Create a data source with the name "TeslaMate":

    Type: PostgreSQLDefault: YESName: TeslaMateHost: localhostDatabase: teslamateUser: teslamate  Password: secretSSL-Mode: disableVersion: 10
  3. Manually import the dashboard files or use the dashboards.sh script:

    $ ./grafana/dashboards.sh restore
    URL:                  http://localhost:3000LOGIN:                admin:adminDASHBOARDS_DIRECTORY: ./grafana/dashboards
    RESTORED locations.jsonRESTORED drive-stats.jsonRESTORED updates.jsonRESTORED drive-details.jsonRESTORED charge-details.jsonRESTORED states.jsonRESTORED overview.jsonRESTORED vampire-drain.jsonRESTORED visited.jsonRESTORED drives.jsonRESTORED projected-range.jsonRESTORED charge-level.jsonRESTORED charging-stats.jsonRESTORED mileage.jsonRESTORED charges.jsonRESTORED efficiency.json
    tip

    To use credentials other than the default, set the LOGIN variable:

    LOGIN=user:password ./grafana/dashboards.sh restore