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.
What can MQTT do....?
So for me an example of some things.
MQTT is the central IoT broker that receives messages and responds to subscriptions.

So let's say I make a small low power (cheap about £10) microcontroller (ESP32) to read temperature of the downstairs in my house.
The controller is v v simple and slow, but I code it to read the temp sensor and send the reading (via it's wifi) to the MQTT broker every 20 sec (or whatever).
That's all the controller will do (forever).

Then another device (raspberry pi in my case (way more powerful)) is coded to subscribe to the same topic that the controller above is publishing to.
every 20s it now knows the temp of the downstairs. My Pi is connected to my heating pumps and motorised valves in the house. So it can now decide to switch on the heating (or not).

but maybe we want to use this temperature reading for other stuff. My car charger does MQTT. Using some code on Node red I could get the temp from the MQTT broker of the downstairs and tell it to charge the car at 10amps if the downstairs is >20C. Why you would want that I don't know, but you can see that you publish a reading once, then reuse it as many times as you want elsewhere.

MQTT is like the central hub of your network where all readings come into and actions take place from there. Even reactions to the actions and so on.
Here's an idea for something as well (something I might tackle) that could be done using this:
Implement some sort of "low charge reminder" - if the car is at home and the SOC is < X% and it's after Y-PM and the car isn't plugged in - let me know!
 
Here's an idea for something as well (something I might tackle) that could be done using this:
Implement some sort of "low charge reminder" - if the car is at home and the SOC is < X% and it's after Y-PM and the car isn't plugged in - let me know!
Follow up this thread:
 
  • Like
Reactions: Dave EV
I changed the code to get the library off the web automatically...
you don't need to mess with that, you just need to set the broker IP address correctly and the topic subscription to match.
edit: I think the subs should match what you have already
Super, thanks! This was indeed the missing "link" I was looking for. It looked like a part of a hyperlink, but it's clearly not :)

I think the documentation of Teslamate could be a lot more detailed here, I assume more people will struggle with this. I know not everybody will have a need for this data, as it's allready integrated in the base Teslamate website and dashboards, but I've made a custom website (on the same server) that displays this data exactly the way that I want.

Pulling it from the postgres database from php was easy, this MQTT data was hard, untill now :) So again, thanks!
 
Last edited:
Let me guess - running TeslaMate on a Raspberry Pi on Debian Buster?
If so, you need to either backport libseccomp2 from backports (Instructions) or upgrade from Buster to Bullseye (How To Upgrade Raspberry Pi OS to Bullseye from Buster)

The former is the easy and safer way to go. The latter - you're almost better off backing up, reinstalling and restoring from backup depending on how much customization you've done to your Pi.
Thank you Dave EV, turns out you are exactly right. I was running a pi and it turns out I was on the old Buster version. The link you provided to upgrade to Bullseye was informative, but it didn't work for me, so I muddied my way through backing up teslamate and copying the file over to my PC, then installing a brand new pi Bullseye distribution and a brand new Teslamate to current version. Works very will - your identification of the issue is much appreciated. Tonight I will hopefully muddy my way through figuring out how to restore the backup data, as last night I was unsuccesfull in that. 👍
 
  • Like
Reactions: cwanja
Here's an idea for something as well (something I might tackle) that could be done using this:
Implement some sort of "low charge reminder" - if the car is at home and the SOC is < X% and it's after Y-PM and the car isn't plugged in - let me know!
yes easy to do in Node Red with MQTT, could send message on email or a messaging app.
once Node Red & MQTT running, bit of code on the web interface of Node Red, maybe 1 hour of coding max.
 
Can somebody please tell me exactly where on my raspberry pi 3B+ that I should put the teslamate backup file, for restoration of the database? Ideally, I'd be using a PC and dragging and dropping the teslamate.bck file into the advised directory on the microsd card. Thank you in advance, as I seem to be stuck at this spot.

Alternately I can put the file there by SCP file transfer. I tried moving it there already by this method in the command prompt on my windows PC to the pi at:
scp C:\Temp\teslamate.bck file2.txt [email protected].[last#]:\[filelocation]\
but where is the [filelocation]? So far at the root the restore doesn't seem to see it?
 
Last edited:
Can somebody please tell me exactly where on my raspberry pi 3B+ that I should put the teslamate backup file, for restoration of the database? Ideally, I'd be using a PC and dragging and dropping the teslamate.bck file into the advised directory on the microsd card. Thank you in advance, as I seem to be stuck at this spot.

Alternately I can put the file there by SCP file transfer. I tried moving it there already by this method in the command prompt on my windows PC to the pi at:
scp C:\Temp\teslamate.bck file2.txt [email protected].[last#]:\[filelocation]\
but where is the [filelocation]? So far at the root the restore doesn't seem to see it?
What command are you using to restore the backup? If using these instructions then you run the command wherever the file is. It doesn't
really matter where you put it as long as you can see it when you're logged into the pi. Usually /home/pi if that's the name of your pi user

Edit: I think your slashes are the wrong way around for the destination location - not used Windoze for a couple of years but think it should be:

scp c:\temp\teslamate.bck [email protected]:/home/pi/
 
Last edited:
  • Like
Reactions: Morristhecat
What command are you using to restore the backup? If using these instructions then you run the command wherever the file is. It doesn't
really matter where you put it as long as you can see it when you're logged into the pi. Usually /home/pi if that's the name of your pi user

Edit: I think your slashes are the wrong way around for the destination location - not used Windoze for a couple of years but think it should be:

scp c:\temp\teslamate.bck [email protected]:/home/pi/
Thank you @init6, appreciate it. You are right about the slashes.
Got the backup moved into my pi with the following command in the windows command prompt:

pscp.exe -P 22 c:\Temp\teslamate.bck [email protected]:\home\pi\

Seemed to work perfectly. I have been following the instructions you linked, but now I'm having another couple of issues.
1. How do I find the value in the .env file if I have one? Where is such a file?
2. I run the following command ok:

docker-compose stop teslamate

Then I run:

docker-compose exec -T database psql -U teslamate

This is where it hangs. I think it is related to my question 1 above. Anyone know how to do this? The instructions in the above link aren't very clear....
Thank you.
 
Then I run:

docker-compose exec -T database psql -U teslamate
It's not hung, psql is waiting for you to type in more commands. :)

Copy this whole snippet (including the trailing period!) and paste it into your terminal to drop your existing data and reinitialize the database:

Code:
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';
.
 
Thank you both very much @Dave EV & @init6 . You are both very helplfull. Thanks to you I finally muddied my way through it and got the new version of Teslamate installed on my pi and restored my backup.

I figured out that the reason why I couldn't figure out how to get the backup file into the proper directory on the pi is because I was using a command like:

pscp.exe -P 22 c:\Temp\teslamate.bck [email protected]:\home\pi\

This actually changes the name of the backup file to "\home\pi\"! So when I was trying to convert the database it kept telling me no such file or directory exists, when it was looking for the file "teslamate.bck". What I actually should have done to move the backup into the pi is the following command at the command prompt in windows:

pscp.exe -P 22 c:\Temp\teslamate.bck [email protected]:teslamate.bck
(substitute 9 for whatever your local IP you pi is on)

However, for some reason, this only works after you run the 1st two commands in the restoration process.

Sooooo, to sum it all up, to restore the teslamate backup on your raspberry pi 3B+ from your windows PC:

1. Log into your Raspberry Pi 3B+ via Putty on your windows PC.
2.Run the following first 2 steps of the restoration process
# Stop the teslamate container to avoid write conflicts
docker-compose stop teslamate

# Drop existing data and reinitialize
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';
.


3. Open up the windows command prompt window. Make sure your backup is located at "c:\temp\teslamate.bck" and enter the command prompt window, then enter the following command
pscp.exe -P 22 c:\Temp\teslamate.bck [email protected]:teslamate.bck
Let it run it's course, it has a progress bar. Took me about 2 minutes.

4. Go back to your Putty screen and switch over your database with the following command:

# Restore
docker-compose exec -T database psql -U teslamate -d teslamate < teslamate.bck
This took me about 10 to 15 minutes.

5. Finally restart Teslamate in the putty screen.
# Restart the teslamate container
docker-compose start teslamate

Boy, that sure was a pain to figure out, but glad it is finally up and running again. Thanks again.
 
  • Like
Reactions: init6 and Dave EV
I can't update the electric rate for my home. After changing the cost in the "home" geofence, and pressing Save, this appears. Pressing any one of the two buttons or close box has no effect, and after about 30 seconds, the message disappears and the cost reverts to the previous value.

The four charging sessions with no cost associated are supercharger sessions. They have no cost as my 2015 S has free supercharging. Any suggestions? I'm running 1.26.1.

Screen Shot 2022-01-31 at 11.32.39 AM.jpg
 
slightly off topic... but someone may find this handy... as I had teslamate and a couple of different projects running on my 4gb pi4 it was feeling a bit slow and I decided it was time for an upgrade or a second one. If you hadn't noticed, the larger memory versions are quite difficult to get hold of right now, so I had a look at other options and found a plethora of lightly-used small x86 PCs on ebay. NUC's still seem to be expensive, but maybe due to many businesses moving/shuttering offices recently it seems like a lot tiny "enterprise" (Lenovo, HP, Dell etc) PCs have found their way into the secondhand market.

for example, I picked up an HP Elitedesk g2 for £100 - given that an 8GB Pi4 is £70 as it is, and you still need to add storage, PSU and likely a case. it's a bit of a bargain... for basically the same price I ended up with an i5-6500T, 8GB RAM and a 256GB SSD. It has a 35w TDP vs the 7.5w of the Pi, so will use a bit more power, but it's small, quiet, and super speedy compared to the pi. Prices seem to vary quite a lot, but if you shop around there are some real bargains to be had.

1643973335034.png
 
HP Elitedesk g2
Yeah, those are great - servethehome.com has been running a series where they have been testing a whole bunch of different makes/models of these refurbed/used "mini-micro" desktop systems with the idea of running them as small, low power servers. Only challenge is finding them at a reasonable price on eBay or similar.

Another option for a low power server are the Protectli line of systems - cost is a bit higher than a used/refurbed mini-micro, but pretty easy to spec out and you can get them with Ubuntu pre-installed so it's ready to go. There are similar systems to the Protectli off Aliexpress and eBay for similar if you shop around as well.

Let us know how much power your g2 uses at idle. One nice thing of the Pi is that the idle power is <= 4 W if I remember right, but I'm always worried about the SD card wearing out / crashing - SSDs are a lot more reliable in my experience.