Skip to content

Commit

Permalink
feat: direct charge
Browse files Browse the repository at this point in the history
  • Loading branch information
jasper-seinhorst committed Feb 18, 2024
1 parent 308af04 commit c621ec0
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 41 deletions.
24 changes: 18 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
# Homebridge Porsche Taycan
# Homebridge Porsche EV
[![verified-by-homebridge](https://badgen.net/badge/homebridge/verified/purple)](https://github.com/homebridge/homebridge/wiki/Verified-Plugins)

This Homebrudge plugin offers a range of useful features for your Porsche Taycan and Macan EV, including real-time monitoring of battery level, charging status and charging power. Moreover, it also enables you to easily toggle the direct climatisation option on or off and automate your home with your vehicles location.

## Supported cars:
## Supported vehicles:
- Taycan (MY19 and newer)
- Macan EV (MY25 and newer)

## Key features
- Switch for **Precool / heat**
- Switch for **Direct Charge**
- Sensor for your **Charger** with **SoC**
<sub><sup>A *contact sensor* will indicate if your vehicle is charging, SoC (battery level) is available as accessory characteristic or as separate sensor</sub></sup>
- Sensor for the **Charging Power** (Optional)
<sub><sup>A *light (lux)* sensor will show current charging power. E.g. 10 lux means your vehicles charges with a speed of 10 kwh.</sub></sup>
- Sensor for the **Location** fo your vehicle (Optional)
<sub><sup>An *occupancy sensor* indicates if your vehicle is at home when the location of your vehicle is within 300 meters of your home</sub></sup>
- Sensor for the **SoC** (optional)
<sub><sup>By default SoC is available as characteristic of the charger sensor. Optionally the SoC can be exposed as *humidity sensor*.</sub></sup>

## Installation
To install Homebridge Porsche Taycan follow these steps:
To install the *Homebridge Porsche Taycan* plugin follow these steps:

- Follow the instructions on the [Homebridge Wiki](https://homebridge.io/how-to-install-homebridge) to install Node.js and Homebridge;
- Install the Homebridge Porsche Tycan plugin through Homebridge Config UI X or manually by:
- Install the *Homebridge Porsche Taycan* plugin through Homebridge Config UI X or manually;
```
$ sudo npm -g i homebridge-porsche-taycan
```
- Edit config.json and add the Porsche Taycan platform. For example,
- Edit config.json and add the *Porsche Taycan* platform. E.g;
```
{
"username": "<<Porsche Connect username>>",
Expand All @@ -40,4 +52,4 @@ To install Homebridge Porsche Taycan follow these steps:
## Credits
This plugin is not an official plugin from Porsche. The usage of Porsche Connect API endpoints are reverse engineered on MyPorsche with help of Google Chrome Dev tools. It uses the unofficial 'porsche-connect' node package to communicate to Porsches servers.

This plugin started as a hobby project but is now available to the public. Pull requests to improve the plugins are welcome.
This plugin started as a hobby project but is now available to the public. Pull requests to improve the plugins are more than welcome.
2 changes: 1 addition & 1 deletion config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"type": "string",
"required": false,
"default": "",
"description": "When your (home) location as latitude/longitude is filled in an occupancy sensor is exposed to indicate if your vehicle is at home. Your vehicle is recognized as being at home if the distance between it and the specified location is within 300 meters (approximately 0.2 miles). Use https://www.latlong.net/ to get the latitude and logitude of your address."
"description": "When your (home) location as latitude/longitude is filled in an occupancy sensor is exposed to indicate if your vehicle is at home. Your vehicle is recognized as being at home if the distance between the vehicle and the specified location is within 300 meters (approximately 0.2 miles). Use https://www.latlong.net/ to get the latitude and logitude of your address."
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge Porsche Taycan",
"name": "homebridge-porsche-taycan",
"version": "0.17.0",
"version": "0.18.0",
"description": "Control your Porsche Taycan through the home app",
"license": "Apache-2.0",
"author": "Jasper Seinhorst",
Expand Down Expand Up @@ -46,6 +46,6 @@
"typescript": "^4.9.5"
},
"dependencies": {
"porsche-connect": "^0.0.14"
"porsche-connect": "^0.0.15"
}
}
4 changes: 1 addition & 3 deletions src/Accessories/DirectCharge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ export default class DirectCharge implements PorscheAccessory {

this.switchService = this.accessory.getService(this.Service.Switch) || this.accessory.addService(this.Service.Switch);
this.switchService.getCharacteristic(this.Characteristic.On).on('set', this.setStatus.bind(this));
this.switchService.setCharacteristic(this.Characteristic.On, false);
}

private async setStatus(value, callback) {
// Only call API when status is not changed during heartbeat
if (this.vehicle && !this.heartBeatActive) {
if (value) {
this.log.debug('Connecting with API to initiate Direct charge');
Expand All @@ -36,7 +34,7 @@ export default class DirectCharge implements PorscheAccessory {
callback();
}

public beat(emobilityInfo: VehicleEMobility, positionInfo : VehiclePosition, vehicle: Vehicle) {
public beat(emobilityInfo: VehicleEMobility, positionInfo: VehiclePosition, vehicle: Vehicle) {
this.heartBeatActive = true;
this.vehicle = vehicle;

Expand Down
4 changes: 1 addition & 3 deletions src/Accessories/PrecoolHeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ export default class PrecoolHeat implements PorscheAccessory {

this.switchService = this.accessory.getService(this.Service.Switch) || this.accessory.addService(this.Service.Switch);
this.switchService.getCharacteristic(this.Characteristic.On).on('set', this.setStatus.bind(this));
this.switchService.setCharacteristic(this.Characteristic.On, false);
}

private async setStatus(value, callback) {
// Only call API when status is not changed during heartbeat
if (this.vehicle && !this.heartBeatActive) {
if (value) {
this.log.debug('Connecting with API to start Precool/heat');
Expand All @@ -36,7 +34,7 @@ export default class PrecoolHeat implements PorscheAccessory {
callback();
}

public beat(emobilityInfo: VehicleEMobility, positionInfo : VehiclePosition, vehicle: Vehicle) {
public beat(emobilityInfo: VehicleEMobility, positionInfo: VehiclePosition, vehicle: Vehicle) {
this.heartBeatActive = true;
this.vehicle = vehicle;

Expand Down
22 changes: 10 additions & 12 deletions src/Platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,17 @@ export class PorscheTaycanPlatform implements DynamicPlatformPlugin {
}

// Register Direct charge
if (this.config.directChargeDevice === true) {
const directChargeUuid = this.api.hap.uuid.generate(`${vehicle.vin}-direct-charge`);
const directChargeExistingAccessory = this.accessories.find(accessory => accessory.UUID === directChargeUuid);
const directChargeUuid = this.api.hap.uuid.generate(`${vehicle.vin}-direct-charge`);
const directChargeExistingAccessory = this.accessories.find(accessory => accessory.UUID === directChargeUuid);

if (directChargeExistingAccessory) {
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, directChargeExistingAccessory));
} else {
this.log.info('Direct charge added as accessory');
const accessory = new this.api.platformAccessory('Direct charge', directChargeUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}
if (directChargeExistingAccessory) {
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, directChargeExistingAccessory));
} else {
this.log.info('Direct charge added as accessory');
const accessory = new this.api.platformAccessory('Direct charge', directChargeUuid);
accessory.context.device = vehicle;
platformVehicle.accessories.push(new DirectCharge(this.config, this.log, this.api, accessory));
this.api.registerPlatformAccessories('homebridge-porsche-taycan', 'PorscheTaycan', [accessory]);
}

// (Optionally) Register Battery
Expand Down

0 comments on commit c621ec0

Please sign in to comment.