Welcome to Tesla Motors Club
Discuss Tesla's Model S, Model 3, Model X, Model Y, Cybertruck, Roadster and More.
Register

TeslaMate [megathread]

This site may earn commission on affiliate links.
As promised (although delayed, working from home and home schooling a 6 year old haven't done much for my productivity!) an updated guide for the Google Drive backups.

If you haven't set them up yet, then just crack on. If you've already got this running, then complete the Get a Google Client ID and Client Secret section, then scroll down to the bottom to edit your existing rclone config :)

How to perform an automated TeslaMate backup to Google Drive - TeslaEV.co.uk

Thanks to @StuC and @spooksman for helping me test the instructions and proving some helpful feedback.

Tried this last night and couldn't get it to work however I think it was user error, as i've tired a test upload and its worked fine. Will see how the cron job runs tonight @ 03:00.

Many thanks for taking the time to find a work around / update the guide.

Is your understanding Google is capping it over a period of say 24 hours, so if you did your update earlier to midnight (assumedly US time?) it might work as a bypass
 
The issue with htpasswd files is that Apache doesn't do any sort of rate-limiting to prevent someone from bruteforcing your credentials. If you're watching your logs you will certainly see this going on, but if you're not checking or alerting on that activity you'll never know.

You could look to layer some additional protection by using something like Cloudflare in-front of your VPS, they have a guide on implementing rate limiting, and then blocking all traffic not originating from Cloudflare or your house. My preferred route for internet facing systems is to use something like the CSF firewall in combination with Webmin, and use the "Dynamic DNS" feature in CSF to automatically update the firewall whenever your home IP changes. CSF also includes port-scanning detection and will automatically ban IP addresses attempting to detect services on your system. You can also configure CSF to watch Apache's log files and ban IP addresses attempting to bruteforce you (similar to how Fail2Ban works).

In reality though the safest (and simplest) solution is to not permit any external access to your Teslamate installation. This is the approach I have taken, but crucially with OpenVPN so that I can dial back into my home network (I self host) while I'm away if I need to access my data. That can also be done on a VPS too, something like OpenVPN Access Server is ideal, it gives you a GUI to manage OpenVPN and without the hassle of managing lots of CLI config. It's intended for businesses but you get two concurrent connections free which is plenty for home use. If I'm out and about and need access to Teslamate, I just fire up the OpenVPN app on my phone, connect back to my house, and then login to Teslamate. Adds about 20-30 seconds... but that could even be automated if I was bothered enough by it!

Have tried this as its something I wanted remote access too but was put off by the idea of having it internet facing (can't be too careful these days)

I have tried following the steps on the OpenVPN setup pages but I keep getting an error. I think it might be because the file its looking up to has changed but I don't have the experience to 'fix' it.

Step 1 & 2 go fine then it breaks, Any thoughts?

-------
2) INSTALL OPENVPN ACCESS SERVER VIA REPOSITORY

Copy and paste these commands and execute them with root privileges. They will add the repository to your system.

1) apt update && apt -y install ca-certificates wget net-tools gnupg
2) wget -qO - https://as-repository.openvpn.net/as-repo-public.gpg | apt-key add -
3) echo "deb http://as-repository.openvpn.net/as/debian buster main">/etc/apt/sources.list.d/openvpn-as-repo.list
4) apt update && apt -y install openvpn-as

Code:
root@raspberrypi:~# wget -qO - https://as-repository.openvpn.net/as-repo-public.gpg | apt-key add -
OK
root@raspberrypi:~# echo "deb http://as-repository.openvpn.net/as/debian buster main">/etc/apt/sources.list.d/openvpn-as-repo.list
root@raspberrypi:~# apt update && apt -y install openvpn-as
Hit:1 http://raspbian.raspberrypi.org/raspbian buster InRelease
Hit:2 http://archive.raspberrypi.org/debian buster InRelease
Hit:3 http://packages.microsoft.com/repos/code stable InRelease
Get:4 http://as-repository.openvpn.net/as/debian buster InRelease [3,185 B]
Hit:5 https://download.docker.com/linux/raspbian buster InRelease
Fetched 3,185 B in 2s (1,923 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
1 package can be upgraded. Run 'apt list --upgradable' to see it.
N: Skipping acquire of configured file 'main/binary-armhf/Packages' as repository 'http://as-repository.openvpn.net/as/debian buster InRelease' doesn't support architecture 'armhf'
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package openvpn-as
root@raspberrypi:~#
 
Tried this last night and couldn't get it to work however I think it was user error, as i've tired a test upload and its worked fine. Will see how the cron job runs tonight @ 03:00.

Many thanks for taking the time to find a work around / update the guide.

Is your understanding Google is capping it over a period of say 24 hours, so if you did your update earlier to midnight (assumedly US time?) it might work as a bypass

I don’t think there’s a time limit as such, I think it’s more about how much others are using rclone to send to Google Drive at the time. When I was Googling it, the amount of data being rcloned to GDrive is huge!

Not 100% convinced this is the solution yet sadly, testing another version of it at the moment, as there’s a possibility that the test user token expires after 7 days.

Will update again when I know more, if not I’ll figure out how to do it to DropBox instead.
 
@Godsense
I used pivpn to install the VPN on my Pi (PIVPN: Simplest way to setup a VPN) - just a scripted install, although I went for the Wireguard option rather than OpenVPN. Works well for me (using IPv6 as I don't have an internet routable IPv4 address from my ISP as I'm behind CG-NAT).
In the end it's just a set of wrapper scripts for installing OpenVPN or WireGuard and handling some of the set up tasks like adding new clients etc.
 
Have tried this as its something I wanted remote access too but was put off by the idea of having it internet facing (can't be too careful these days)

I have tried following the steps on the OpenVPN setup pages but I keep getting an error. I think it might be because the file its looking up to has changed but I don't have the experience to 'fix' it.

Step 1 & 2 go fine then it breaks, Any thoughts?

Ah damn, my bad. OpenVPN AS isn't supported on ARM architectures at the moment, so that counts out the Pi. I'm running it on x86 and so don't see that!

If you don't mind using the command line to manage it, you can use PiVPN which is a scripted install for OpenVPN.
PIVPN: Simplest way to setup a VPN

Alternatively you could look to install a Desktop on your Pi, and then install the OpenVPN management tools.
 
  • Helpful
Reactions: Godsense
Tesla have turned off the old V2 Auth and replaced with the V3, so if you don't do this and your token runs out, the data will stop flowing to TeslaMate until you update and sign back in.
Yep - I missed two days of data, including a long drive with DC supercharging. Bummer! Was surprised to be met with a login screen instead of the normal view of the cars. All updated, easy as.
 
  • Like
Reactions: DaveW
I often move the car around the yard to wash it, move away from the charger etc.
This creates lots of very small 'drives' in teslamate, which are just annoying.
So I'm planning to run, on a cronjob a drives delete for drives < 1 mile every night.
I need someone who knows better than me to check my code and tell me of any issues:
Code:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd /root/teslamate
sudo /usr/local/bin/docker-compose exec database psql teslamate teslamate
DELETE FROM drives WHERE distance < 1.6;
would this work from a script file via cron?
Do I need a final line to disconnect (gracefully) from the database?
Thanks
 
Just checking you've noticed the minimum distance filter at the top of the drives page?
I have to admit, didn't notice that.
That only filters them out. doesn't remove them from database and thus the calculations?
testing a code mod:
Code:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd /root/teslamate
sudo /usr/local/bin/docker-compose exec -T database psql teslamate teslamate <<END
DELETE FROM drives WHERE distance < 1.6;
END
I think this works? Please don't test on your own database, I'm just trying stuff.
 
I have to admit, didn't notice that.
That only filters them out. doesn't remove them from database and thus the calculations?
testing a code mod:
Code:
#!/bin/bash
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd /root/teslamate
sudo /usr/local/bin/docker-compose exec -T database psql teslamate teslamate <<END
DELETE FROM drives WHERE distance < 1.6;
END
I think this works? Please don't test on your own database, I'm just trying stuff.

Let us know if this works. I've just got home and had a "drive" I need to delete (a few others historically too) - I was just at the Woodall Superchargers and most were full, so started charging next to somebody, and then after about 10 minutes the 2 cars in the next bays both left, so I moved over by a bay so both I and the guy next to me could get max charge rates, so I now have a 0.01 mile drive in my history!
 
Let us know if this works. I've just got home and had a "drive" I need to delete (a few others historically too) - I was just at the Woodall Superchargers and most were full, so started charging next to somebody, and then after about 10 minutes the 2 cars in the next bays both left, so I moved over by a bay so both I and the guy next to me could get max charge rates, so I now have a 0.01 mile drive in my history!
Yeah those less than 1 mile drives are annoying.
I put the code into a sh file and ran it.
Since I live and work at home on the farm, the tesla hasn't been out since I setup Teslamate. (lockdown etc etc)
It did delete the 2 drives to my pressure washer, however there weren't any other drives in there.
So you could argue it deleted all the drives.
If you fancy testing it, make a backup first, I'm not responsible for lost data.
 
DELETE works fine (I ran manually via CLI as opposed to via script). For reference for folks:

Code:
sudo docker-compose exec -T database psql teslamate teslamate
SELECT * FROM drives WHERE distance < 1.5 ORDER BY distance;
DELETE FROM drives WHERE distance < 1.5;
 
Just updated the Google Drive backup guide for what I hope is the last time (what a pain!)

Quick context, if your GDrive backups stopped working it's highly likely because Google have been rate limiting rclone activities to GDrive, hard to know when this will happen, as you're at the mercy of what other internet users are up to.

The way round this is to create your own Client ID and Secret. After plenty of trial and error and thanks to @spooksman and @StuC for helping me test it, I've updated the guide again for what I hope will be the final time!

How to perform an automated TeslaMate backup to Google Drive - TeslaEV.co.uk

Worth following the updating steps I've put on there if you are already using the automated backup as you don't need to start from scratch :)
 
Just updated the Google Drive backup guide for what I hope is the last time (what a pain!)
Thanks Dave, I just tried this for the first time and it works perfectly, great guide!

There are only a couple of minor points I found:
- rclone config option for gdrive seems to have moved from 13 to 15 (at least in my install, I run Docker via openmediavault on my pi); I also used 'Option 3' after entering client secret which seems fine.
- I use an external USB drive on my pi (as I use it it for Time Machine backups also), which is where I set my Docker storage to save wear on the microSD card and created a folder to store the backups for the same reason. I'm pretty new to Docker and found I had to run the docker-compose command in the backup script from the directory where docker-compare.yml is located (should be obvious I suppose!)

Thanks again for all your hard work!
 
  • Like
Reactions: DaveW
Thanks Dave, I just tried this for the first time and it works perfectly, great guide!

There are only a couple of minor points I found:
- rclone config option for gdrive seems to have moved from 13 to 15 (at least in my install, I run Docker via openmediavault on my pi); I also used 'Option 3' after entering client secret which seems fine.
- I use an external USB drive on my pi (as I use it it for Time Machine backups also), which is where I set my Docker storage to save wear on the microSD card and created a folder to store the backups for the same reason. I'm pretty new to Docker and found I had to run the docker-compose command in the backup script from the directory where docker-compare.yml is located (should be obvious I suppose!)

Thanks again for all your hard work!

Thanks for that @Zigway - I'll need to try and update my version of rclone and see if the options change as it's still 13 for Google Drive on the version I'm running.
 
Just updated my bulk import post on my site with the three latest Superchargers to go live :)

Code:
INSERT INTO public.geofences (name, latitude, longitude, radius, inserted_at, updated_at, cost_per_kwh, session_fee) VALUES ('Wyboston Supercharger', 52.202366, -0.291631, 35, '2020-08-27 05:36:00 ', '2020-08-27 05:36:00 ', 0.24, NULL);
INSERT INTO public.geofences (name, latitude, longitude, radius, inserted_at, updated_at, cost_per_kwh, session_fee) VALUES ('Hilton Park, Southbound Supercharger', 52.644065, -2.054251, 35, '2020-08-09 05:29:00 ', '2020-08-09 05:29:00 ', 0.24, NULL);
INSERT INTO public.geofences (name, latitude, longitude, radius, inserted_at, updated_at, cost_per_kwh, session_fee) VALUES ('Leeds-Whitehouse Street Supercharger', 53.784556, -1.532498, 35, '2020-08-09 05:27:00 ', '2020-08-09 05:27:00 ', 0.24, NULL);

Full post here if anyone who hasn't done the bulk import wants to (or just needs a reminder of the instructions to add the above), I've also updated the Washington Supercharger location, the supplied latitude / longitude were incorrect:

TeslaMate - How to bulk import UK Supercharger locations - TeslaEV.co.uk

Thanks for the instructions, @DaveW - very easy to follow.

I've imported all the supercharger geofences, but do you know if there's a way of going back through historical charges and adding how much it cost? I don't have many so it shouldn't be too laborious to add the data manually with reference to my tesla account. Just would be nice to be able to have the cost data available to analyse. Cheers.