Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remote control features #677

Merged
merged 2 commits into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,49 @@
[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/f4082f146ad044bb900e1683035a540b)](https://www.codacy.com/gh/flobz/psa_car_controller/dashboard?utm_source=github.com&utm_medium=referral&utm_content=flobz/psa_car_controller&utm_campaign=Badge_Coverage)
[![Publish Docker image](https://github.com/flobz/psa_car_controller/actions/workflows/Docker_build.yml/badge.svg?branch=master)](https://hub.docker.com/repository/docker/flobz/psa_car_controller)
[![Donate](https://img.shields.io/badge/Donate-PayPal-blue.svg)](https://www.paypal.com/donate?hosted_button_id=SM652WPXFNCXS)
### This is a python program to control and get information from a PSA car.
I test it with a Peugeot e-208, but it works with others PSA vehicles (Citroen, Opel, Vauxhall, DS).
### This is a Python program to control and get information from a PSA car.
I test it with a Peugeot e-208, but it works with other PSA vehicles (Citroen, Opel, Vauxhall, DS).

With this app you will be able to :
With this app you will be able to:
- get the status of the car (battery level for electric vehicle, position ... )
- start and stop the charge
- set a charge threshold to limit the battery level to a certain percentage
- set a stop hour to charge your vehicle only on off-peak hours
- control air conditioning
- control lights and horn if your vehicle is compatible (mine isn't)
- get consumption statistic
- control lights and horn if your vehicle is compatible
- lock and unlock doors
- get consumption statistics
- visualize your trips on a map or in a table
- get the list of car charging
- visualize battery charging curve
- visualize altitude trip curve
- get car charging co2 emission
- get car charging CO2 emission
- get car charging price
- send live data to ABetterRoutePlanner

The official api is documented [here](https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article) but it is not totally up to date, and contains some errors.
The official API is documented [here](https://developer.groupe-psa.io/webapi/b2c/quickstart/connect/#article) but it is not totally up to date, and contains some errors.


## I. Installation
- [Installation on Linux or Windows](docs/Install.md)
- [Instalation as Home Assistant addon](https://github.com/flobz/psacc-ha/blob/main/psacc-ha/README.md)
- [Installation as Home Assistant addon](https://github.com/flobz/psacc-ha/blob/main/psacc-ha/README.md)
- [Installation in Docker](docs/Docker.md)
- [Installation on Raspberry Pi with docker-compose (external Tutorial)](https://return2.net/opel-peugeot-electric-vehicle-set-charging-threshold-limit/)
## II. Use the app

2.1 Get the car state :
2.1 Get the car state
http://localhost:5000/get_vehicleinfo/YOURVIN

2.2 Get the car state from cache to avoid to use psa api too much
2.2 Get the car state from cache to avoid to use PSA API too much
http://localhost:5000/get_vehicleinfo/YOURVIN?from_cache=1

2.2 Stop charge
http://localhost:5000/charge_now/YOURVIN/0

2.3 Set hour to stop the charge to 6am
http://localhost:5000/charge_control?vin=yourvin&hour=6&minute=0
2.3 Set hour to stop the charge to 6 am
http://localhost:5000/charge_control?vin=YOURVIN&hour=6&minute=0

2.4 Change car charge threshold to 80 percent
2.4 Change car charge threshold to 80%
http://localhost:5000/charge_control?vin=YOURVIN&percentage=80

2.5 See the dashboard (only if record is enabled)
Expand All @@ -53,11 +54,20 @@ The official api is documented [here](https://developer.groupe-psa.io/webapi/b2c
2.6 Refresh car state (ask car to send its state):
http://localhost:5000/wakeup/YOURVIN

2.7 Start/Stop preconditioning
2.7 Start (1)/Stop (0) preconditioning
http://localhost:5000/preconditioning/YOURVIN/1 or 0

2.8 Change charge hour (for example: set it to 22h30)
http://127.0.0.1:5000/charge_hour?vin=YOURVIN&hour=22&minute=30
http://localhost:5000/charge_hour?vin=YOURVIN&hour=22&minute=30

2.9 Honk the horn
http://localhost:5000/horn/YOURVIN/count

2.10 Flash the lights (Duration is always roughly 10 seconds, regardless of set duration)
http://localhost:5000/lights/YOURVIN/duration

2.11 Lock (1)/Unlock (0) the doors
http://localhost:5000/lock_door/YOURVIN/1 or 0


## III. Use the dashboard
Expand All @@ -70,8 +80,8 @@ You will be able to visualize your trips, your consumption and some statistics:


![Screenshot_20210128_104519](https://user-images.githubusercontent.com/48728684/106119895-01c98d80-6156-11eb-8969-9e8bc24f3677.png)
- You have to add an api key from https://home.openweathermap.org/ in your config file, to be able to see your consumption vs exterior temperature.
- You have to add an api key from https://co2signal.com/ to have your C02 emission by KM (in France the key isn't needed).
- You have to add an API key from https://home.openweathermap.org/ in your config file, to be able to see your consumption vs exterior temperature.
- You have to add an API key from https://co2signal.com/ to have your CO2 emission by KM (in France the key isn't needed).
### IV. Charge price calculation
The dashboard can give you the price by kilometer and price by kw that you pay.
You just have to set the price in the config file.
Expand All @@ -80,7 +90,7 @@ After a successful launch of the app, a config.ini file will be created.
In this file you can set the price you pay for electricity in the following format "0.15".

If you have a special price during the night you can set "night price", "night hour start" and "night hour end".
Hours need to be in the following format "23h12"?
Hours need to be in the following format "23h12".

You can modify a price manually in the dashboard. It can be useful if you use public charge point.
## V. Connection to other services:
Expand All @@ -91,7 +101,7 @@ You can modify a price manually in the dashboard. It can be useful if you use pu
- [Grafana](https://github.com/flobz/psa_car_controller/issues/161)

## FAQ
If you have a problem, or a question please check if the answer isn't in the [FAQ](FAQ.md).
If you have a problem or a question, please check if the answer isn't already in the [FAQ](FAQ.md).

## Contribute
If you need information to contribute or edit this program go [here](docs/Develop.md).
Expand Down
20 changes: 20 additions & 0 deletions psa_car_controller/web/view/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,27 @@ def after_request(response):
header['Access-Control-Allow-Origin'] = '*'
return response

@app.route('/horn/<string:vin>/<int:count>')
def horn(vin, count):
try:
return jsonify(APP.myp.remote_client.horn(vin, count))
except RateLimitException:
return jsonify({"error": "Horn rate limit exceeded"})

@app.route('/lights/<string:vin>/<int:duration>')
def lights(vin, duration):
try:
return jsonify(APP.myp.remote_client.lights(vin, duration))
except RateLimitException:
return jsonify({"error": "Lights rate limit exceeded"})

@app.route('/lock_door/<string:vin>/<int:lock>')
def lock_door(vin, lock):
try:
return jsonify(APP.myp.remote_client.lock_door(vin, lock))
except RateLimitException:
return jsonify({"error": "Locks rate limit exceeded"})

def update_trips():
global trips, chargings, cached_layout, min_date, max_date, min_millis, max_millis, step, marks
logger.info("update_data")
Expand Down
Loading