close multiple drives at once #2364
Replies: 2 comments 11 replies
-
|
It's been a long time since I wrote a shell script, but just knocked this one up: Requires a file called unclosed-drives.sql which contains: I'm sure these should be put into one script, but I've done enough today :) |
Beta Was this translation helpful? Give feedback.
-
|
I've implemented Teslamate on Unraid 7.2.x (yeah I know: it's not official supported, but got it working anyway). I needed to close more than 1050 drives and 1400 charges. So, some automation was very welcome! Build some more scripts for Teslamate on Unraid; need to find a place to publish them for the greater good; any suggestions? #!/usr/bin/env bash
set -euo pipefail
DB_CONTAINER="postgresql17"
TM_CONTAINER="teslamate"
DB_NAME="teslamate"
DB_USER="teslamate"
echo "=== TeslaMate Batch Fix (Unraid) ==="
echo "Fetching incomplete drives..."
drive_ids=$(docker exec -i "$DB_CONTAINER" psql \
-U "$DB_USER" -d "$DB_NAME" -t -c \
"SELECT id FROM drives WHERE end_date IS NULL;" | sed '/^\s*$/d')
echo "Fetching incomplete charging processes..."
charge_ids=$(docker exec -i "$DB_CONTAINER" psql \
-U "$DB_USER" -d "$DB_NAME" -t -c \
"SELECT id FROM charging_processes WHERE end_date IS NULL;" | sed '/^\s*$/d')
echo "Drives to fix: $(echo "$drive_ids" | wc -l)"
echo "Charges to fix: $(echo "$charge_ids" | wc -l)"
for id in $drive_ids; do
echo "Closing drive ID $id"
docker exec -i "$TM_CONTAINER" bin/teslamate rpc \
"TeslaMate.Repo.get!(TeslaMate.Log.Drive, $id) |> TeslaMate.Log.close_drive()"
done
for id in $charge_ids; do
echo "Closing charge ID $id"
docker exec -i "$TM_CONTAINER" bin/teslamate rpc \
"TeslaMate.Repo.get!(TeslaMate.Log.ChargingProcess, $id) |> TeslaMate.Log.complete_charging_process()"
done
echo "=== TeslaMate batch repair completed successfully ===" |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have to regularly (and i mean daily) go on teslamate and look for missing drives in grafana, look at the missing ID number from the overlay url and then run the "close drive script" manually for the missing ID. is there by any chance a small script that could run a "for loop" to clean it up? i could cron the script and have a clean up state of trips.... It should not be that difficult but i am not sure what is the query needed to look for the missing trips...
this is what i run manually (as per the docs: https://docs.teslamate.org/docs/maintenance/manually_fixing_data
sudo docker-compose exec teslamate bin/teslamate rpc "TeslaMate.Repo.get!(TeslaMate.Log.Drive,1125) |> TeslaMate.Log.close_drive()"Beta Was this translation helpful? Give feedback.
All reactions