Peugeot Citroen DS cars - Connected Car

Another Link for a feedom Plugin:

1 Like

Flobz Python Server ist working Well. But i saw that PSA ist using a mqtt Broker.maybe the easiest and best way is to Connect psa mqtt with HA mqtt?

From what i have read the MQTT client is using the token gathered from the API to authenticate with PSA MQTT broker.
It therefor require a special type of MQTT client, and i don’t believe the one in HA is made for.

Plus they seam to be some control only available through the API. A full implementation, maybe without the sql storage of the trip, look like a better option.

Sadly it look like we don’t have a lot of Python dev with a recent PSA car, and time to implement this right now.

1 Like

I managed to get the data through flobz Server and restful Sensors and commands in HA. For the Moment this is a workaround,but it is ok for me.

What sadden me is the lack of token renewal on this project.
You have to purge the app to avoid it from renewing it early, but also have to get a new one from scratch after a little bit.
With all the helper in HA, i’m sure it could be trivial for someone who know what they are doing to implement it. But we aren’t enough to need this. the dev time isn’t worth it to someone who don’t have a car using this.

@vlycop: Thank you for your feedback and i fully understand it.
That’s ok, i think there are thing with more importance!
Maybe you can give me a hint to optimize the workaround.
The server allows only one request euch minute, thats why it would be cool to combine the json subfolders into one request, i that possible? if yes how can i do that??

The flobz plugin, is not working the expected way. i’ve read that the openhab community already developed a binding.
Maybe anyone can port this to home assistant?

1 Like

New version with self updating token.works great again

In my opinion, better wait for the new API.
I Checked today, but still not published yet.

Car (e208 GT) is arriving very soon now. Time for some preparation ^^
So I have a few questions left unanswered.
Regarding the login data from the APK file backup, does that mean I can use the app OR flobz’, solution or both at the same time?
Does the login keep working/refreshing itself or do I have to redo the login data extraction again and again after specific time periods?

I can answer a few question by myself already. Both work fine in parallel. Login seems to refresh itself if needed by now.

New one: @ds1707 can you paste your restful sensors please? I never tinkered with restful at all yet…

Yes of course i can share my RESTFUL Sensor config.
The API only allows a request every 2 minutes that’s why i am facing the follwing problem.
I wanted to include also other sub directories of the JSON path, to put it in one request, maybe you can solve it.

And here is the config:

  - platform: rest
    name: car_corsa_energy
    json_attributes_path: "$['energy'][0]"
#    json_attributes_path: "$"    
    json_attributes:
#      - battery.current
#      - battery.voltage
      - charging.charging_rate
      - level
      - autonomy
      - updated_at
    resource: http://192.168.17.2:5000/get_vehicleinfo/VIN
#    value_template: '{{ value_json.level }}'
    value_template: '{{ value_json.energy.level }}'
    scan_interval: 750
  - platform: template
    sensors:
      battery_soc:
        friendly_name: 'Batteriestand'
        value_template: "{{ state_attr('sensor.car_corsa_energy', 'level') }}"
        unit_of_measurement: '%'
      autonomy:
        friendly_name: 'Reichweite'
        value_template: "{{ state_attr('sensor.car_corsa_energy', 'autonomy') }}"
        unit_of_measurement: 'km'
rest_command:
  charge_control100:
    url: 'http://192.168.17.2:5000/charge_control?vin=VIN&percentage=100'
  charge_control90:
    url: 'http://192.168.17.2:5000/charge_control?vin=VIN&percentage=90'
  charge_control80:
    url: 'http://192.168.17.2:5000/charge_control?vin=VIN&percentage=80'
1 Like

I tried anything to get it stay in root with it’s dictionary, but no dice. It causes nothing but errors and non working sensors. So I did what you wanted to not do in the end:

configuration.yaml

  - platform: rest
    name: car_208e_energy
    json_attributes_path: "$.energy[0]"
    json_attributes:
      - level
      - autonomy
      - updated_at
    resource: http://192.168.181.50:5000/get_vehicleinfo/FID
    value_template: '{{ value_json.energy[0].level }}'
    scan_interval: 180
  - platform: rest
    name: car_208e_battery
    json_attributes_path: "$.battery"
    json_attributes:
      - current
      - voltage
    resource: http://192.168.181.50:5000/get_vehicleinfo/FID
    value_template: '{{ value_json.battery.current }}'
    scan_interval: 180
  - platform: rest
    name: car_208e_charging
    json_attributes_path: "$.energy[0].charging"
    json_attributes:
      - charging_rate
      - charging_mode
      - plugged
      - status
    resource: http://192.168.181.50:5000/get_vehicleinfo/FID
    value_template: '{{ value_json.energy[0].charging.status }}'
    scan_interval: 180
  - platform: template
    sensors:
      energy_level:
        friendly_name: 'Batteriestand'
        value_template: "{{ state_attr('sensor.car_208e_energy', 'level') }}"
        unit_of_measurement: '%'
      energy_autonomy:
        friendly_name: 'Reichweite'
        value_template: "{{ state_attr('sensor.car_208e_energy', 'autonomy') }}"
        unit_of_measurement: 'km'
      battery_current:
        friendly_name: 'Batteriestatus'
        value_template: "{{ state_attr('sensor.car_208e_battery', 'current') }}"
      battery_voltage:
        friendly_name: 'Batterie Wearing'
        value_template: "{{ state_attr('sensor.car_208e_battery', 'voltage') }}"
        unit_of_measurement: '%'
      charging_charging_rate:
        friendly_name: 'Laderate'
        value_template: "{{ state_attr('sensor.car_208e_charging', 'charging_rate') }}"
      charging_charging_rate_kw:
        friendly_name: 'Laderate'
        value_template: "{{ state_attr('sensor.car_208e_charging', 'charging_rate') * 0.29 }}"
        unit_of_measurement: 'kW'
      charging_charging_mode:
        friendly_name: 'Lademodus'
        value_template: "{{ state_attr('sensor.car_208e_charging', 'charging_mode') }}"
      charging_plugged:
        friendly_name: 'Ladegerät Eingesteckt'
        value_template: "{{ state_attr('sensor.car_208e_charging', 'plugged') }}"
      charging_status:
        friendly_name: 'Ladevorgang Status'
        value_template: "{{ state_attr('sensor.car_208e_charging', 'status') }}"
rest_command:
  stop_charge:
    url: "http://192.168.181.50:5000/charge_now/FID/0"
  max_charge_100:
    url: "http://192.168.181.50:5000/charge_control?vin=FID&percentage=100"
  max_charge_90:
    url: "http://192.168.181.50:5000/charge_control?vin=FID&percentage=90"
  max_charge_85:
    url: "http://192.168.181.50:5000/charge_control?vin=FID&percentage=85"
  max_charge_80:
    url: "http://192.168.181.50:5000/charge_control?vin=FID&percentage=80"

Calling the website for information does not fire a refresh from flobz server solution to PSA as far as I can see, so this works quite fine. Ugly, but fine.

Only thing I still wanna have… device_tracker made off the coordinates in the REST output. But this seems to be quite impossible.

EDIT: And I have a working Device Tracker :smiley:

configuration.yaml

  - platform: rest
    name: car_208e_mapdata
    json_attributes_path: "$.last_position.geometry"
    json_attributes:
      - coordinates
    resource: http://192.168.181.50:5000/get_vehicleinfo/FID
    value_template: '{{ value_json.last_position.geometry.coordinates[2] }}'
    scan_interval: 180

automaion.yaml

- id: car_track
  alias: Tracker Car
  trigger:
  - entity_id: sensor.car_208e_mapdata
    platform: state
  - event: start
    platform: homeassistant
  action:
  - data:
      dev_id: car
      battery: '{{states.sensor.energy_level.state}}'
      gps_accuracy: '15'
      gps:
      - '{{state_attr(''sensor.car_208e_mapdata'', ''coordinates'')[1]}}'
      - '{{state_attr(''sensor.car_208e_mapdata'', ''coordinates'')[0]}}'
    service: device_tracker.see
  mode: single

known_devices.yaml

car:
  name: Mein 208e
  icon: mdi:car-hatchback
  picture: /local/peugeot.png
  track: true

image

1 Like

Awesome, thanks for the work on this everyone.

Got the SOC and range of our e208 on my dashboard now… fab!!! :+1:

After my car suddently started to feel like being a Hybrid car aka the API changed as it seems, I updated a few things + flobz’ server and I went some other way I was recommended by flobz regarding HA integration: GitHub - Flodu31/HomeAssistant-PeugeotIntegration: Integration between Peugeot API and Home Assistant

Pro: Only one call to the server (@ds1707 this is for ya)
Con: A bit more complicated at first.

configuration.yaml

sensor:
  - platform: rest
    name: peugeot_e208
    resource: http://192.168.181.50:5000/get_vehicleinfo/VRXXXXXXXXXXXXXXX
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - energy
     - timed_odometer
     - battery
     - last_position
  - platform: template
    sensors:
      e208_battery_voltage:
        friendly_name: "Batterie Spannung"
        unit_of_measurement: "V"
        value_template: '{{ states.sensor.peugeot_e208.attributes["battery"]["voltage"] * 4 }}'
      e208_battery_level:
        friendly_name: "Batterie"
        unit_of_measurement: "%"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["level"] }}'
      e208_battery_autonomy:
        friendly_name: "Autonomie"
        unit_of_measurement: "km"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["autonomy"] }}'
      e208_charging_mode:
        friendly_name: "Lademodus"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["charging"]["charging_mode"] }}'
      e208_charging_rate:
        friendly_name: "Laderate"
        unit_of_measurement: "km/h"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["charging"]["charging_rate"] }}'
      e208_charging_plugged:
        friendly_name: "Ladegerät Eingesteckt"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["charging"]["plugged"] }}'
      e208_charging_status:
        friendly_name: "Ladestatus"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][1]["charging"]["status"] }}'
      e208_mileage:
        friendly_name: "Kilometerstand"
        unit_of_measurement: "km"
        value_template: '{{ states.sensor.peugeot_e208.attributes["timed_odometer"]["mileage"] }}'
      e208_mapdata:
        friendly_name: "Kartendaten"
        value_template: '{{ states.sensor.peugeot_e208.attributes["last_position"]["geometry"]["coordinates"] }}'

known_devices.yaml

car:
  name: Mein 208e
  icon: mdi:car-hatchback
  picture: /local/peugeot.png
  track: true

automation.yaml

- id: car_track
  alias: Tracker Car
  trigger:
  - entity_id: sensor.e208_mapdata
    platform: state
  - event: start
    platform: homeassistant
  action:
  - data:
      dev_id: car
      battery: '{{states.sensor.e208_battery_level.state}}'
      gps_accuracy: '15'
      gps:
      - '{{ (states.sensor.peugeot_e208.attributes["last_position"]["geometry"]["coordinates"][1]) }}'
      - '{{ (states.sensor.peugeot_e208.attributes["last_position"]["geometry"]["coordinates"][0]) }}'
    service: device_tracker.see
  mode: single

P.S. It seems like I have to use [“energy”][1] as my car is on identity crisis and thinks it’s a hybrid car and [“energy”][0] is the nulled fuel information in my case. Use what works for you

P.P.S. And now I am back to [0] O_o

Awesome workaround, works like a charm, thank you for sharing!

Is it also possible to show the position tracking in a card?

You were able to. But PSA is plain stupid right now. "kinetic" and "last_position" fields are empty · Issue #50 · flobz/psa_car_controller · GitHub

The last position is not empty for me. I own an open Corsa. The coordinates are in home assistant, but I don’t have any experiences showing coordinates nor tracks in the card?
Can you give me a hint?

Aww crap, I forgot this one in my howto:

known_devices.yaml

car:
  name: Mein 208e
  icon: mdi:car-hatchback
  picture: /local/peugeot.png
  track: true

Did you add the automation I posted above? This one will fill the self made device tracker. Then it should have the coordinates and you can add it in a map lovelace tile. Worked nicely until my car went to coordinates = null mode… Solution not found yet, but likely it happened due to registering to a Telemaintenance service inside the app. If you can register such service, too… DONT (yet) ^^