flobz / psa_car_controller

Control psa car with connected_car v4 API.
GNU General Public License v3.0
391 stars 199 forks source link

Get info if delayed time charge activated and deactivate it #546

Closed Matssa56 closed 1 year ago

Matssa56 commented 1 year ago

Hi,

I'm doing some automations under Home Assistant to automatically activate the delayed time in order to charge my car at 2am.

When getting the vehicle status, we can get the delayed time that is sent to the car (energy --> charging time --> next_delayed_time). However, we don't have any value saying that it is activated or not (at least not in the get vehicle information). Therefore I can't check if my command is correctly sent and used by my car or not.

When checking the application logs, apparently we can manage to get this information :

2023-05-04 22:42:17,781 :: INFO :: veh_charge_request: topic: psa/RemoteServices/from/cid/OV-ACNTXXXXXX/VehCharge: {'program': {'hour': '2', 'minute': '0'}, 'type': 'delayed'}

How can we get this info in a sensor for Home Assistant? Is there a way to get this json value, maybe another link that we can ping? Currently I get the information from the two following links : http://localhost:5000/get_vehicleinfo/VIN?from_cache=1 http://localhost:5000/charge_control?vin=VIN&?always_check=true

Another thing, is there a way to send a command to disable the delayed hour?

I checked the API ddocumentation and I didn't manage to find anything, maybe I need to check the fleet API?

Thanks!

Ilpo55 commented 1 year ago

I use this.

My rest sensor:

sensor:
  - platform: rest
    name: peugeot_e3008
    resource: http://b9f12dxx-psacc:5000/get_vehicleinfo/VF3M45GBUxxxxxxxx?from_cache=1
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - energy
     - timed_odometer
     - battery
     - preconditionning

My value_template for the time in the car.:

      e3008_lataus_ajastusaika:
        friendly_name: "Latauksen ajastusaika"
        value_template: >-
          {% set la = states.sensor.peugeot_e3008.attributes["energy"][0]["charging"]["next_delayed_time"] %}
          {% set la = la | replace("PT","") | replace("H",",") | replace("M",",") | replace("S",",") %}
          {% set h = la.split(",")[0] %}
          {% set m = la.split(",")[1] %}
          {% if (h | length) == 1 %}
          {% set h = "0"+h %}
          {% endif %}
          {% if (m | length) == 1 %}
          {% set m = "0"+m %}
          {% elif (m | length) == 0 %}
          {% set m = "00" %}
          {% endif %}
          {{h}}:{{m}}

(Edit and test the value_template code in Template editor).

Matssa56 commented 1 year ago

I use this.

My rest sensor:

sensor:
  - platform: rest
    name: peugeot_e3008
    resource: http://b9f12dxx-psacc:5000/get_vehicleinfo/VF3M45GBUxxxxxxxx?from_cache=1
    scan_interval: 60
    timeout: 30
    value_template: 'OK'
    json_attributes:
     - energy
     - timed_odometer
     - battery
     - preconditionning

My value_template for the time in the car.:

      e3008_lataus_ajastusaika:
        friendly_name: "Latauksen ajastusaika"
        value_template: >-
          {% set la = states.sensor.peugeot_e3008.attributes["energy"][0]["charging"]["next_delayed_time"] %}
          {% set la = la | replace("PT","") | replace("H",",") | replace("M",",") | replace("S",",") %}
          {% set h = la.split(",")[0] %}
          {% set m = la.split(",")[1] %}
          {% if (h | length) == 1 %}
          {% set h = "0"+h %}
          {% endif %}
          {% if (m | length) == 1 %}
          {% set m = "0"+m %}
          {% elif (m | length) == 0 %}
          {% set m = "00" %}
          {% endif %}
          {{h}}:{{m}}

(Edit and test the value_template code in Template editor).

Thanks for your feedback, the issue is that the value is set in the sensor isn't activated

If I check the Opel app on my phone, the delayed time is correctly set l, however it isn't activated. And in the Opel car sensor, there isn't any value to see if the delayed charge it set or not.

Ilpo55 commented 1 year ago

I use these commands to put the car into immediate charge (lataus_on:) / delayed charge (lataus_off:) :

rest_command:
  e3008_lataus_on:
    url: "http://b9f12dxx-psacc:5000/charge_now/VF3M45GBUxxxxxxxx/1"
    method: GET
  e3008_lataus_off:
    url: "http://b9f12dxx-psacc:5000/charge_now/VF3M45GBUxxxxxxxx/0"
    method: GET
Matssa56 commented 1 year ago

I use these commands to put the car into immediate charge (lataus_on:) / delayed charge (lataus_off:) :

rest_command:
  e3008_lataus_on:
    url: "http://b9f12dxx-psacc:5000/charge_now/VF3M45GBUxxxxxxxx/1"
    method: GET
  e3008_lataus_off:
    url: "http://b9f12dxx-psacc:5000/charge_now/VF3M45GBUxxxxxxxx/0"
    method: GET

Hi, Not the issue that I'm talking about. When setting the value for delayed charging, there isn't any value saying that it is currently taken into account or not.

Example : when I set the value, the charging stops and it delays until the given hour. When I unplug the car and plug it back in, the set delayed time doesn't change but isn't taking into account. Checking the delayed hour is therefore not sufficient to see it is really delayed or not.

Ilpo55 commented 1 year ago

Setting the value does not activate the delayed charging, you have to activate it after setting it. That is the same with the phone app. With HA you can make an automation to activate delayed chargin, after you have set the delayed charging time.

This what I do with my car (Peugeot 3008 Hybrid4). When I unplug and then plug it back in, the car goes always into immediate cahrging mode (= greean flash ligth around the plug). After that I have to activate the delayed charging again: Pressing the button next to the plug until the ligth starts to flash blue or using HA to send the command to activate delayed charging or using the app to activate delayed charging. HA gets information when the car is pluged in, so you can make an automation to put the car back to delayed charging.

Checking the delayed hour is therefore not sufficient to see it is really delayed or not.

No, but you can check if the car is charging. If it is charging the the delayed charging is not activated.

So I think that this is not an psacc issue.

Matssa56 commented 1 year ago

Setting the value does not activate the delayed charging, you have to activate it after setting it. That is the same with the phone app. With HA you can make an automation to activate delayed chargin, after you have set the delayed charging time.

This what I do with my car (Peugeot 3008 Hybrid4). When I unplug and then plug it back in, the car goes always into immediate cahrging mode (= greean flash ligth around the plug). After that I have to activate the delayed charging again: Pressing the button next to the plug until the ligth starts to flash blue or using HA to send the command to activate delayed charging or using the app to activate delayed charging. HA gets information when the car is pluged in, so you can make an automation to put the car back to delayed charging.

Checking the delayed hour is therefore not sufficient to see it is really delayed or not.

No, but you can check if the car is charging. If it is charging the the delayed charging is not activated.

So I think that this is not an psacc issue.

Thanks for the feedback, just saw how the stop REST command works... Didn't see that it launched the delayed charge... Other question concerning the threshold, do you set it at each charging or not? I'm not sure that the threshold is respected since I'm putting it at 87% and it regularly goes to 89% (I even added a HA check to stop the charging as soon as it is >87)

flobz commented 1 year ago

not psacc issue