An adaptive charging controller for your Tesla, enabling you to direct excess solar energy to your car.
- Tesla vehicle
- Configured Tesla Vehicle Command SDK environment with tesla-control available OR use the TeslaBleHttpProxy (NEW!)
- TeslaMate
- eGauge solar monitoring with a CT on the charger circuit
- Linux computer with Bluetooth, such as a Raspberry Pi Zero 2 W
- Home Assistant or another MQTT client to adjust the options for after-dark charging, and delayed charging
PVCharge uses tesla-control in the Tesla Vehicle Command SDK to communicate with your car over local Bluetooth
Here are a few hints to help complete the tesla-control installation
Create the directory "keyrings" to hold your private key: mkdir /home/pi/.local/share/keyrings Setting the key: tesla-keygen -key-file /home/pi/.local/share/keyrings/private_key.pem create > public_key.pem While in the car, pair with this command: tesla-control -ble add-key-request public_key.pem owner cloud_key
To use TeslaBleHttpProxy (not required if you are using tesla-control), please follow the installation & configuration instructions here
- Add the PROXY_HOST parameter to your .env file (see example.env)
- Enable use of the proxy by adding the ENABLE_TESLA_PROXY parameter to your config.toml file (see example_config.toml)
- Note, when TeslaBleHttpProxy is running it seems to take over local bluetooth hardware. Please stop the proxy before switching back to the tesla-control library.
- Install Python (3.11+) and Git using your package manager
- Clone the repo
git clone https://github.com/sftman18/PVCharge.git
- In the PVCharge directory, configure the Python virtual environment and install the requirements
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt
- Create your own copy of example.env, and example_config.toml
cp example.env .env cp example_config.toml config.toml Change all values to match your equipment settings and preferences
- Copy included PVCharge.service to the proper path (systemd shown)
sudo cp PVCharge.service /etc/systemd/system/
- Activate the service and start it:
sudo systemctl enable PVCharge.service sudo systemctl start PVCharge.service
- Check to ensure it is running:
sudo systemctl status PVCharge.service
PVCharge waits for 3 conditions to be communicated over MQTT from Teslamate
- Car location is "Home"
teslamate/cars/$car_id/geofence
- Car is plugged in
teslamate/cars/$car_id/plugged_in
- Car battery level is below the App limit
teslamate/cars/$car_id/battery_level
When those conditions are satisfied, it will attempt to start charging, when solar energy is available
PVCharge publishes status on MQTT
- Charging report
topic_base/status
- Current charge rate
topic_base/new_charge_rate
- The behavior of after-hours charging is controlled by MQTT:
topic_base/prevent_non_solar_charging
- True
- PVCharge will prevent charging when insufficient PV output is available
- False
- PVCharge will ignore charging when insufficient PV output is available (default, Configurable in config.toml)
- The ability to delay charging is controlled by:
topic_base/charge_delay
- "delay"
- charging is delayed for 1 hour
- "##" (number)
- charging is delayed by the indicated number of minutes
- other text (i.e. "cancel")
- resume normal charging
Enable more verbose logging by changing the LOG_LEVEL to DEBUG in config.toml
- Check PVCharge.log for any unexpected output