HomeAssistant-PeugeotIntegration icon indicating copy to clipboard operation
HomeAssistant-PeugeotIntegration copied to clipboard

use home assistant package and other goodies to ease the installation

Open sanzoghenzo opened this issue 8 months ago • 4 comments

Hi there! Thanks a lot for this documentation, it has been helpful to start tinkering with my opel corsa-e and home assistant!

Trying to keep things as tidy as possible in my home assistant config, I discovered one can use packages to group various entities, automation and so on in a single file/folder.

I also combined the rest and template sensors using the restful integration, and added input_texts/secrets to set the URL and VIN.

I'm still testing this, but that's what I got so far. If you want, you can use it to update the documentation!

This is my opel_corsa.yaml file:

# Opel Corsa integration using psa-car-controller

input_text:
  psacc_url:
    name: "PSA Car Controller URL"
    initial: !secret psacc_url
  psacc_vin:
    name: "PSA Car Controller VIN"
    initial: !secret psacc_vin

rest:
  - resource_template: "{{ states('input_text.psacc_url') }}/get_vehicleinfo/{{ states('input_text.psacc_vin') }}?from_cache=1"
    scan_interval: 60
    timeout: 30
    sensor:
      - name: "Battery Voltage"
        unique_id: corsa_battery_voltage
        json_attributes:
          - battery
        unit_of_measurement: "V"
        value_template: '{{ value_json["battery"]["voltage"] * 4 }}'
      - name: "Battery"
        unique_id: corsa_battery_level
        json_attributes:
          - energy
        unit_of_measurement: "%"
        value_template: '{{ value_json["energy"][0]["level"] }}'
      - name: "Autonomy"
        unique_id: corsa_autonomy
        json_attributes:
          - energy
        unit_of_measurement: "km"
        value_template: '{{ value_json["energy"][0]["autonomy"] }}'
      - name: "Charging Status"
        unique_id: corsa_charging_status
        json_attributes:
          - energy
        value_template: '{{ value_json["energy"][0]["charging"]["status"] }}'
      - name: "Mileage"
        unique_id: corsa_mileage
        json_attributes:
          - timed_odometer
        unit_of_measurement: "km"
        value_template: '{{ value_json["timed_odometer"]["mileage"] }}'

  - resource_template: "{{ states('input_text.psacc_url') }}/charge_control?vin={{ states('input_text.psacc_vin') }}&?always_check=true"
    scan_interval: 60
    timeout: 30
    sensor:
      - name: "Next Stop Time"
        unique_id: corsa_next_stop_hour
        json_attributes:
          - _next_stop_hour
        value_template: '{{ value_json["_next_stop_hour"]}}'
      - name: "Threshold"
        unique_id: corsa_charge_threshold
        unit_of_measurement: "%"
        json_attributes:
          - percentage_threshold
        value_template: '{{ value_json["percentage_threshold"] }}'

# this one should be changed to use shell command + template switch to allow templating
command_line:
  - switch:
      name: corsa_clima
      unique_id: corsa_clima
      command_on: curl -s "http://YOURADDRESS:PORT/preconditioning/YOURVIN/1"
      command_off: curl -s "http://YOURADDRESS:PORT/preconditioning/YOURVIN/0"

rest_command:
  # WakeUp command
  corsa_wakeup:
    url: "{{ states('input_text.psacc_url') }}/wakeup/{{ states('input_text.psacc_vin') }}"

  # custom charging threshold
  corsa_change_charge_threshold:
    url: "{{ states('input_text.psacc_url') }}/charge_control?vin={{ states('input_text.psacc_vin') }}&percentage={{ states('input_number.corsa_charge_threshold_slider') | int }}"
    method: GET

  corsa_change_charge_hour:
    url: "{{ states('input_text.psacc_url') }}/charge_control?vin={{ states('input_text.psacc_vin') }}&hour={{ states('input_number.corsa_charge_delay_hour') }}&minute=0"

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

  corsa_charge_delay_hour:
    name: Charging delay
    initial: 0
    min: 0
    max: 24
    step: 1
    unit_of_measurement: "h"

input_button:
  corsa_apply_charge_threshold_button:
    name: Set charging threshold
    icon: mdi:battery-charging

# state initalization
homeassistant:
  customize:
    switch.corsa_clima:
      assumed_state: false

automation:
  - alias: WakeUp corsa
    trigger:
      - platform: time
        at: '6:00:00'
    condition: []
    action:
      - service: rest_command.corsa_wakeup
    mode: single
  - alias: Change charging threshold corsa
    trigger:
      - platform: state
        entity_id:
          - input_button.corsa_apply_charge_threshold_button
    condition: []
    action:
      - service: rest_command.corsa_change_charge_threshold
        data: {}
    mode: single

in configuration.yaml, you just need to:

homeassistant:
  packages:
    opel_corsa: !include opel_corsa.yaml

and in secrets.yaml - note that this is not needed if you set the initial value of the input_texts to a string

psacc_url: http://YOURADDRESS:PORT
psacc_vin: YOURVIN

sanzoghenzo avatar Jun 10 '24 19:06 sanzoghenzo