Peugeot Citroen DS cars - Connected Car

Hi All,

the latest version 2023.6.0 has shown warnings in regards to the way that the sensors and switch platform is current being written.
I’ve tried following the guide but can’t seems to get it parse properly. Anyone had any luck in getting this through?

if yes, can I please see how you’ve done it? Cheers

I updated mine like this:

# PSA
# Peugeot e208
sensor e208:
  - platform: rest
    name: peugeot_e208
    resource: http://IPADDRESS:5001/get_vehicleinfo/VINNUMBER?from_cache=1
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - energy
     - timed_odometer
     - battery
  - platform: template
    sensors:
      e208_battery_voltage:
        friendly_name: "e208 Battery Voltage"
        unit_of_measurement: "V"
        value_template: '{{ states.sensor.peugeot_e208.attributes["battery"]["voltage"] * 4 }}'
      e208_battery_level:
        friendly_name: "e208 Battery"
        unit_of_measurement: "%"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["level"] }}'
      e208_battery_autonomy:
        friendly_name: "e208 Autonomy"
        unit_of_measurement: "km"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["autonomy"] }}'
       # Uncomment for miles instead of km
       #e008_battery_autonomy:
        #friendly_name: "Autonomy"
        #unit_of_measurement: "m"    
        #value_template: "{{ ((state_attr('sensor.peugeot_e208', 'energy')[0]['autonomy']) / 1.609) | round(0)}}"
      e208_charging_status:
        friendly_name: "e208 Charging Status"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["charging"]["status"] }}'
      e208_mileage:
        friendly_name: "Mileage"
        unit_of_measurement: "km"
        value_template: '{{ states.sensor.peugeot_e208.attributes["timed_odometer"]["mileage"] }}'
       # Uncomment for miles instead of km
       #e208_mileage:
        #friendly_name: "Mileage"
        #unit_of_measurement: "m"
        #value_template: "{{ ((state_attr('sensor.peugeot_e208', 'timed_odometer')['mileage']) / 1.609) | round(2)}}"
# Peugeot e208 charge_control
sensor e208_charge_control:
  - platform: rest
    name: peugeot_e208_charge_control
    resource: http://IPADDRESS:5001/charge_control?vin=VINNUMBER&?always_check=true
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - _next_stop_hour
     - percentage_threshold
  - platform: template
    sensors:
      e208_stop_hour:
        friendly_name: "e208 Next Stop Time"
        value_template: '{{ states.sensor.peugeot_e208_charge_control.attributes["_next_stop_hour"]}}'
      e208_threshold:
        friendly_name: "e208 Threshold"
        unit_of_measurement: "%"
        value_template: '{{ states.sensor.peugeot_e208_charge_control.attributes["percentage_threshold"] }}'

# e208 communication
#switch:
#  - platform: command_line
command_line:
  - switch:
#    switches:
      name: e208_change_threshold
      command_on: curl -s "http://IPADDRESS:5001/charge_control?vin=VINNUMBER&percentage=90"
      command_off: curl -s "http://IPADDRESS:5001/charge_control?vin=VINNUMBER&percentage=100"
  - switch:
      name: e208_change_charge_hour
      command_on: curl -s "http://IPADDRESS:5001/charge_control?vin=VINNUMBER&hour=5&minute=0"
      command_off: curl -s "http://IPADDRESS:5001/charge_control?vin=VINNUMBER&hour=0&minute=0"
  - switch:
      name: e208_clim
      command_on: curl -s "http://IPADDRESS:5001/preconditioning/VINNUMBER/1"
      command_off: curl -s "http://IPADDRESS:5001/preconditioning/VINNUMBER/0"
       
# e208 WakeUp
rest_command:
  e208_wakeup:
    url: "http://IPADDRESS:5001/wakeup/VINNUMBER"

# e208 custom charging threshold
  e208_change_charge_threshold:
    url: "http://IPADDRESS:5001/charge_control?vin=VINNUMBER&percentage={{ states('input_number.e208_charge_threshold_slider') | int }}"
    method: GET

input_number:
  e208_charge_threshold_slider:
    name: e208 Charging threshold
    initial: 80
    min: 50
    max: 100
    step: 1
    unit_of_measurement: "%"

input_button:
  e208_apply_charge_threshold_button:
    name: e208 Set charging threshold
    icon: mdi:battery-charging

What does that always_check=true do?
Also where do I need to sign up if I want last-position to work?

1 Like

Hi,

After restore I get this what to do?

Hello
First I have a Opel Mocca-e and try since few days to implement this peugot-integration. The Addon work fine local without the Map.

But this integation no sensor work. When fill in my browser he get_vehicleinformation, i get some Information. But the sensor are empty
grafik

The protocol of the addon say running on 0.0.0.0


But with 0.0.0.0 i didn’t get nor date with vehicleinfo.

The problem shoud be the template error (but why, other user have no problem):

Logger: homeassistant.helpers.template_entity
Source: helpers/template_entity.py:422
First occurred: 22:36:38 (35 occurrences)
Last logged: 23:13:21

TemplateError(‘UndefinedError: ‘None’ has no attribute ‘attributes’’) while processing template ‘Template<template=({{ states.sensor.peugeot_e2008.attributes[“energy”][0][“autonomy”] }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.e2008_battery_autonomy’
TemplateError(‘UndefinedError: ‘None’ has no attribute ‘attributes’’) while processing template ‘Template<template=({{ states.sensor.peugeot_e2008.attributes[“energy”][0][“charging”][“status”] }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.e2008_charging_status’
TemplateError(‘UndefinedError: ‘None’ has no attribute ‘attributes’’) while processing template ‘Template<template=({{ states.sensor.peugeot_e2008.attributes[“timed_odometer”][“mileage”] }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.e2008_mileage’
TemplateError(‘UndefinedError: ‘None’ has no attribute ‘attributes’’) while processing template ‘Template<template=({{ states.sensor.peugeot_e2008_charge_control.attributes["_next_stop_hour"]}}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.e2008_stop_hour’
TemplateError(‘UndefinedError: ‘None’ has no attribute ‘attributes’’) while processing template ‘Template<template=({{ states.sensor.peugeot_e2008_charge_control.attributes[“percentage_threshold”] }}) renders=4>’ for attribute ‘_attr_native_value’ in entity ‘sensor.e2008_threshold’

So I didn’t know, what to do

Try to replace 0.0.0.0 with the actual IP address of the machine it’s running on.

Do you get a sensor from the rest platform you set up? This is my config (note that I’m running the add-on on port 5001 and I’m pulling some additional attributes):

# PSA
# Peugeot e208
sensor e208:
  - platform: rest
    name: peugeot_e208
    resource: http://LOCAL.IP.OF.SERVER:5001/get_vehicleinfo/VINNUMBER?from_cache=1
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - energy
     - timed_odometer
     - battery
     # nkh addition
     - environment
     - kinetic
     - preconditionning

and it gives me this sensor which is then fed into the template sensors that breaks out the individual values:

Did you find any solution?

I’m especially interested in getting the mileage working. Battery and charging status are working nicely.

I’ve the base model Active of the e-2008. I’m wondering if there is a difference in infotainment system in terms of what data is available.

Yes, I work with the Ip of HA 192.168.178.xx

But I didn’t have the sensor “peugot_2008”!!! Why?

In the Browser I get Data with get_vehicleinformation!

The differenz between your Coding and my (and the coding of Flodu31) is, i have no line “sensor 2008:”
Do you have your coding in sensor.yaml or configuration.yaml?

In the sensor.yaml it is not possible for to insert this line. So I insert only this sensor in the configuration.yaml. That works!
Than I inserted all sensor in the configuration.yaml, it works!

But I did not want to insert all sensor in the configuration.yaml. What was your way?

Later I see, with the inserting all sensors in configuration.yaml I did not get any errors, but no sensor was generated!?

What is the way you assign the attributes of your 208-Sensor to the single sensor eg batery_level?

I have everything in configuration.yaml with no sensor.yaml, so I don’t know why it works in one place but not the other. But it’s good that it’s working now.

I posted an example of a configuration here: Peugeot Citroen DS cars - Connected Car - #302 by NKH where it breaks out individual sensors including battery level.

There are some more sensors you can include if you list environment and preconditionning under json_attributes in your main sensor (like I did here: Peugeot Citroen DS cars - Connected Car - #306 by NKH )

      e208_charging_charging_mode:
        friendly_name: "e208 Charging Mode"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["charging"]["charging_mode"] }}'
      e208_charging_charging_rate:
        friendly_name: "e208 Charging Rate"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["charging"]["charging_rate"] }}'
      e208_charging_plugged:
        friendly_name: "e208 Charging Plugged"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["charging"]["plugged"] }}'
      e208_charging_remaining_time:
        friendly_name: "e208 Charging Remaining Time"
        value_template: '{{ states.sensor.peugeot_e208.attributes["energy"][0]["charging"]["remaining_time"] }}'
      e208_air_temp:
        friendly_name: "e208 Air Temp"
        unit_of_measurement: "C"
        value_template: '{{ states.sensor.peugeot_e208.attributes["environment"]["air"]["temp"] }}'
      e208_luminosity_day_true:
        friendly_name: "e208 Luminosity Day True"
        value_template: '{{ states.sensor.peugeot_e208.attributes["environment"]["luminosity"]["day"] }}'
      e208_preconditionning_status:
        friendly_name: "e208 Preconditionning Status"
        value_template: '{{ states.sensor.peugeot_e208.attributes["preconditionning"]["air_conditioning"]["status"] }}'

and if you want an ongoing estimation of what the maximum range of the car with a 100% charge is you can do something like this:

      e208_theoretical_max_autonomy:
        friendly_name: "e208 Theoretical max autonomy when fully charged"
        unit_of_measurement: "km"
        value_template: "{{ ((float(states('sensor.e208_battery_autonomy')) / float(states('sensor.e208_battery_level'))) * 100)|round(2) }}"

I noticed that PSA Car Controller now (sometimes) include the location of the car, this can be added to HA if you add last_position in the list under json_attributes in the main sensor, then add a sensor like this (it can also be condensed into the automation, but I like to have the “raw” output):

e208_last_position:
        friendly_name: "e208 Last Position Coordinates"
        value_template: '{{ states.sensor.peugeot_e208.attributes["last_position"]["geometry"]["coordinates"] }}'

And then create an automation that updates a device tracker with the location every minute:

alias: e208 - Update location from PSA Car Controller
description: ""
trigger:
  - platform: time_pattern
    minutes: /1
condition: []
action:
  - service: device_tracker.see
    data:
      host_name: e208 PSA GPS
      dev_id: e208_psa_gps
      gps:
        - >-
          {{ states.sensor.e208_last_position.state.split(", ")[1] |
          replace("[","") | replace("]","") | float() }}
        - >-
          {{ states.sensor.e208_last_position.state.split(", ")[0] |
          replace("[","") | replace("]","") | float() }}
mode: single

This gives me a device tracker called device_tracker.e208_psa_gps that shows the location of the car.

1 Like

Hey
yesterday night was i able to solve the problem. The problem, i moved the code of sensor.yaml to configuration.yaml. So I had 2x rest and 2x template, but without errors.

It works, thank you verry much!

Your sensor I will look again.

And your solution with the device tracker is interesting. which one do you use?

I only just implementet the device tracker, so currently I’m only seeing the inaccuracy of the GPS (I hope…), but it’s showing up nicely on a map and it looks like it’s updating very frequently:

2 Likes

It’s interesting how the car estimates it’s own position when it can’t see any satelites (parked in a parking garage) :grinning:

Hey, I am using the home assistant add-on and I don’t know exactly which IP should I use… since it’s a docker container I imagine localhost won’t work, neither my Raspberry Pi local IP right? Should I use the IP it shows in the logs when I launch the add-on? Mine says:

2023-08-04 22:59:22,035 :: INFO :: update_data
2023-08-04 22:59:24,307 :: INFO ::  * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)

I use the hostname. So when you open PSA Controller addon page and you see all the toggles “start on boot”, “watchdog”, etc. In the same place, you’ll see also hostname field. That’s the value I use plus the :5000 port.

1 Like

I wonder does the country code make a difference who will get GPS coordinates and who is not.

My privacy setting is “none” and I have never seen any location information on the PSACC map.

And do you also use the official app at the same time with PSACC?

yeah, you need the official app to keep the connection to the car (the car will dropp the connection if the it drives for a while without being connected to your phone).

I got some location info on the 21st. of July, then nothing and the consistantly since the 27th. of July.

1 Like

Thanks for the information. I will install the official app and try again. Let’s see will I get some coordinates :smiley:

Preconditioning program

Is possible to activate a preconditioning program using this API?

So if I have schedule for 8am, I would like to be able active/deactivate it. In summer time using HA to trigger the preconditioning on/off is not much of an issue, but I’m more thinking about the winter where I assume the outside temperature plays more a role in the preconditioning duration.

My PSA integration failed for the first time in ages .

I discovered for what ever reason the local IP address had changed in the add-on and none of my sensors were working.

This cost me over £3.00 as my programs failed to stop the charge at the correct time :frowning:

So I suggest everybody who is running the integration and using the local IP address

http://LOCAL.IP.OF.SERVER:5000/get_vehicleinfo/VINNUMBER?from_cache=1

change the IP address to the host name . This can be found on the info screen of the add-on in my case b9f12d83-psacc.

This will work regardless of the local IP and should not change unless the add-on is removed and re-added