Peugeot Citroen DS cars - Connected Car

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) ^^

Hello Daniel,
i have added your automation:

alias: Garage Corsa Position
description: ''
trigger:
  - entity_id: sensor.car_corsa_charge_mapdata
    platform: state
  - event: start
    platform: homeassistant
condition: []
action:
  - data:
      dev_id: car
      battery: '{{states.sensor.car_corsa_battery_level.state}}'
      gps_accuracy: '15'
      gps:
        - >-
          {{
          (states.sensor.car_corsa.attributes["last_position"]["geometry"]["coordinates"][1])
          }}
        - >-
          {{
          (states.sensor.car_corsa.attributes["last_position"]["geometry"]["coordinates"][0])
          }}
    service: device_tracker.see
mode: single

And there were coorinates in the sensor.car_corsa_charge_mapdata, but i don’t have any device tracker that i can visualize in any map.
Can you help me out?

See above. You need to add the block I pasted into known_devices.yaml

Ah understood, but I don’t have this file. Shall I create it? Where and do I need to link the configuration.yaml to it?

I created the file with the input, now i am waiting for the next movement of the car, to receive data.

Strange… Maybe becuase of that:
Once device_tracker is enabled, a file will be created in your configuration dir named known_devices.yaml . Edit this file to adjust which devices to be tracked.

Has anyone managed to get the flobz app_decoder working for a Vauxhall Corsa-e in the UK at all? I’m struggling - I’ve tried a few different versions of the APK (from 1.27.0 up to 1.29.2) and I just get kicked out after entering GB as the country code:

What is your country code ? (ex: FR, GB, DE, ES...)                                                                 
GB                                                                                                                  
Traceback (most recent call last):                                                                                  
  File "/psa_car_controller/psa_car_controller/app_decoder.py", line 112, in <module>                               
    token = res.json()["accessToken"]                                                                               
KeyError: 'accessToken'                                                                                             
HOST_BRANDID : https://id-dcr.vauxhall.co.uk/mobile-services sitecode: 0V_GB_ESP                                    
{"returnCode":"NEED_ACTIVATION"}

Has anyone managed to overcome this at all?

Add a ticket to the project. I had a similar issue that was sorted, a faulty URL or something like that.

1 Like

In case anyone is interested, I’ve put psa_car_controller into a Docker container and it’s running quite nicely so far:
https://hub.docker.com/r/flobz/psa_car_controller

And the readme is here:
https://github.com/flobz/psa_car_controller/blob/master/docs/Docker.md

There’s a small amount of hassle for the first-run SMS/PIN routine, but it’s all documented in the readme.
(updated because my container code has been merged with the main psa_car_controller repo, and a new Docker Image repo set up to reflect that).

I too have to keep switching between [0] and [1}. Found a solution yet?

Build a template that reades the type attribute in the JSON and use that in the template for the Electric or Fuel depending on the value in object 0 and 1.

I use a sensor to pick the correct energy object in the list and use it in the rest of my templates

    car_ds7_electric_stats:
      friendly_name: DS7 Electric stats
      value_template: >-
        {%if states.sensor.car_ds7_combined.attributes["energy"][1]["type"] == "Electric" %}
        1
        {%else%}
        0
        {% endif %}
    car_ds7_fuel_stats:
      friendly_name: DS7 Fuelstats
      value_template: >-
        {%if states.sensor.car_ds7_combined.attributes["energy"][1]["type"] != "Electric" %}
        1
        {%else%}
        0
        {% endif %}

    ds7_energy_autonomy:
      friendly_name: "Räckvidd el"
      value_template: >-
        {{ states.sensor.car_ds7_combined.attributes["energy"][states.sensor.car_ds7_electric_stats.state|int]["autonomy"] }}

Also You can now install psa_car_controller as an addons of ha:

https://github.com/flobz/psacc-ha/blob/c2b64227a68e0f10730131382f40c60543d74006/psacc-ha/README.md

1 Like

Aweseome!! Works like a charm, thank you!

After upgrading (FLOBZ server and HA) or maybe reconfiguring my HA config i have a problem with the device tracker, maybe @Daniel_Reimer you can help me?
The problem is the device tracker seems to not receive the coordinates.
I see the coordinates in the attributes of the car.
And also the automation is running with:

alias: Garage Corsa Position
description: ''
trigger:
  - entity_id: sensor.car_corsa_charge_mapdata
    platform: state
  - event: start
    platform: homeassistant
condition: []
action:
  - data:
      dev_id: car
      battery: '{{states.sensor.car_corsa_battery_level.state}}'
      gps_accuracy: '15'
      gps:
        - >-
          {{
          (states.sensor.car_corsa.attributes["last_position"]["geometry"]["coordinates"][1])
          }}
        - >-
          {{
          (states.sensor.car_corsa.attributes["last_position"]["geometry"]["coordinates"][0])
          }}
    service: device_tracker.see
mode: single

This is also triggering, and the known_devices is also setup:

car:
  name: Corsa
  icon: mdi:car-hatchback
  picture: /local/pics/corsa.png
  track: true

But when i have a look in the device tracker this is empy:

Automation gives my this failure:

2021-06-30 11:43:26 ERROR (MainThread) [homeassistant.components.automation.garage_corsa_position] Garage Corsa Position: Error executing script. Invalid data for call_service at pos 1: expected int for dictionary value @ data['battery']
2021-06-30 11:43:26 ERROR (MainThread) [homeassistant.components.automation.garage_corsa_position_2] Garage Corsa Position #2: Error executing script. Invalid data for call_service at pos 1: expected int for dictionary value @ data['battery']
2021-06-30 11:43:26 ERROR (MainThread) [homeassistant.components.automation.garage_corsa_position] Error while executing automation automation.garage_corsa_position: expected int for dictionary value @ data['battery']
2021-06-30 11:43:26 ERROR (MainThread) [homeassistant.components.automation.garage_corsa_position_2] Error while executing automation automation.garage_corsa_position_2: expected int for dictionary value @ data['battery']

So problem solved with deleting the battery entry

When I start the HA module I have this error in the log :

Containerised psa_car_controller loading...
Traceback (most recent call last):
  File "/psa_car_controller/server.py", line 8, in <module>
    import web.app
  File "/psa_car_controller/web/app.py", line 3, in <module>
    import dash_bootstrap_components as dbc
ModuleNotFoundError: No module named 'dash_bootstrap_components'