MartijnvanGeffen13 / Volvo4evcc

MIT License
4 stars 0 forks source link

Configure Multiple Cars #20

Open christoph-ng opened 1 week ago

christoph-ng commented 1 week ago

How could I arrange a connection of multiple cars?

If I have to start the script twice, a different port should be specified.

MartijnvanGeffen13 commented 1 week ago

Hi christoph,

As this is still early development and i don't really have 2 cars to test with i would atm indeed just install the module in 2 separate folders and start it from those 2 folders (Note all config and tokens are saved from where you start so make sure you start from the right path ). and search in the code for the 6060 port and update to something like 6061.

If you run into issues let me know,

I can put this request on the roadmap to see if i can implement support for multiple cars. Should not be to hard seen i already running with parallel instances.

christoph-ng commented 1 week ago

I've created two subdirs in my users home and copied the volco4evcc directory and all config into this directory.

The start failed:

Import-Module: /root/XC90/volvo4evcc/start.ps1:2
Line |
   2 |  Import-Module "$($pwd.path)/volvo4evcc/Volvo4evcc.psd1"
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | The specified module '/root/volvo4evcc/Volvo4evcc.psd1' was not loaded because no valid module file was found in any module directory.
Start-Volvo4Evcc: /root/XC90/volvo4evcc/start.ps1:14

If I changed the directory before I start to ~/XC90 it works. After that I will try the second car. I will keep you informed.

MartijnvanGeffen13 commented 1 week ago

yep forgot about that one that is still static path, its on the back log to see how linux handles dynamic paths and than migrate all files interactions to dynamic paths.

I just realize that the automatic process termination will probably also kill the first instance when the second instance starts.

MartijnvanGeffen13 commented 1 week ago

How are you cars configured on the volvo site, Is that 2 cars in 1 account or do you have a separate account per car ?

christoph-ng commented 1 week ago

Yeah i've got both cars in one account. Actually I'm using volvo2mqtt, and have no VIN in my volvo2mqtt config. I'm get the information about boths registered VIN's.

MartijnvanGeffen13 commented 1 week ago

let me see what i can do might take a few days

christoph-ng commented 1 week ago

Both instances are working separately, but if I start the second one in parallel to the first, the first one get's killed. How do you identify the process on startup to kill the old one?

vm-volvo4evcc:~/XC40# ~/XC40/volvo4evcc_XC40.sh Token loaded from Disk succesfull Startup with Connected:True - Charging:False Killed

vm-volvo4evcc:~/XC90# /root/XC90/volvo4evcc_XC90.sh Token loaded from Disk succesfull Startup with Connected:True - Charging:False Just a Evcc pull and token test no action taken - Token valid for another : 7.2 minutes

christoph-ng commented 1 week ago

I've changes start.ps1 to have the path of the script in Get-Process, then it's working

#    Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
    Get-Process 'pwsh' | Where-Object -FilterScript {$_.Commandline -like "*$($pwd.path)/volvo4evcc/start.ps1" -and $_.id -ne $pid } | Stop-Process -Force
MartijnvanGeffen13 commented 4 days ago

@christoph-ng

I have started analysing what is needed for multi car support ( i have assigned a test branch for this development and will keep you posted with progress.),

Am i assuming correctly that on the volvo API the only difference is the VIN numbers ? you currently setup this module twice configuring the VIN as the difference.

Progress update:

  1. Config is supporting multiple vehicles
  2. Web service and runspaces are dynamically spawned based on amount of vehicles

Todo:

  1. Update the main loop to support multi vehicle
  2. update startup import of vehicle data last pull to start with backup of last time
  3. update start script and tear down
  4. Update weather module to support multi vehicle
jobe39 commented 3 days ago

Am i assuming correctly that on the volvo API the only difference is the VIN numbers ?

As what I have seen, yes. That is why I included the VIN in my version (volvo2evcc - which I will remove, when yours is final, since it is the better approach). I used jq in evcc to parse the result for the correct VIN then.

soc: source: http uri: http://192.168.0.1:8182/data method: GET jq: .data.YOUR_VIN.battery_charge_level

MartijnvanGeffen13 commented 3 days ago

Looks like we have a first test build for you to test @christoph-ng @jobe39 ,
https://github.com/MartijnvanGeffen13/Volvo4evcc/tree/MultipleCarsSimpler

Do note you have to remove the old module and log and config files that where created to be able to migrate successfull to this version

than rerun config and update evcc yaml to match the cars.

Please let me know any bugs asap as i don`t have 2 cars i can only fake my car twice hence it will get the same data from API.

Import-module "$($HOME)/Volvo4Evcc/Volvo4Evcc.psd1"
Set-volvoconfig
Set-volvoconfig -WeatherInfo

image

christoph-ng commented 1 day ago

That looks good, I'm getting the status of my two cars.

Do I have to set the follwing in EVCC? Is it possible to replace Car0/Car1 by the VIN to identify the cars?

MartijnvanGeffen13 commented 17 hours ago

That looks good, I'm getting the status of my two cars.

Do I have to set the follwing in EVCC? Is it possible to replace Car0/Car1 by the VIN to identify the cars?

Looking at the yaml code I thing i did fix all the casing meaning you would need to use all lower case for all "value" fields in the JQ queries.

Thats some good feedback to use VIN as identifier, but i was actually aiming to not expose any PII data in the module, I know a lot of modules for EVCC as very insecure as they expose all data unencrypted and even credentials. Maybe i can thing of something as a name placeholder that i can add.

As this is a beta build i am planning to incorporate all feedback you can give inc some of the fixes from the main branch and then release it as a 2.0 of the addon.

christoph-ng commented 15 hours ago

I've tested connection of both cars and do a summarize of the events. It seems that the detection after connection a new car is quite slow and takes some minutes. You can see the protocoll of my testing above. There is no refresh after the car gets disconnected and I got some errors in evcc. Please have a look, perhaps it helps you.

The timestamps in volvo4evcc are not in my local time 09:07 => 10:07. You have to add one hour to my times and the evcc times.

-> Car1 Connected

    "chargingSystemStatus": {
      "value": "CHARGING_SYSTEM_IDLE",
      "timestamp": "2024-11-28T09:07:25Z"
    },
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_CONNECTED_AC",
      "timestamp": "2024-11-28T09:07:25Z"
    },
    "EvccStatus": {
      "value": "B"

-> Disconnect Car1 on 10:17

[lp-1 ] INFO 2024/11/28 10:17:19 car disconnected
[lp-1 ] INFO 2024/11/28 10:17:19 vehicle updated: XC90volvo4evcc -> unknown
[lp-1 ] DEBUG 2024/11/28 10:17:19 set battery boost: false
[lp-1 ] DEBUG 2024/11/28 10:17:19 set session soc limit: 0
[lp-1 ] DEBUG 2024/11/28 10:17:19 set session energy limit: 0
[push ] ERROR 2024/11/28 10:17:19 invalid message template for disconnect: wanted: [vehicleTitle], got: [auth battery batteryBoost batteryCapacity batteryDischargeControl batteryEnergy batteryGridChargeActive batteryGridChargeLimit batteryMode batteryPower batterySoc bufferSoc bufferStartSoc chargeCurrent chargeCurrents chargeDuration chargePower chargeRemainingEnergy chargeTotalImport chargedEnergy chargerFeatureHeating chargerFeatureIntegratedDevice chargerIcon chargerPhases1p3p chargerPhysicalPhases chargerStatusReason charging connected connectedDuration currency disableDelay disableThreshold effectiveLimitSoc effectiveMaxCurrent effectiveMinCurrent effectivePlanSoc effectivePlanTime effectivePriority enableDelay enableThreshold enabled fatal greenShareHome greenShareLoadpoints gridConfigured gridCurrents gridEnergy gridPower gridPowers hems homePower influx interval limitEnergy limitSoc loadpoint maxCurrent minCurrent mode mqtt network phaseAction phaseRemaining phasesActive phasesConfigured phasesEnabled planEnergy planOverrun planProjectedEnd planProjectedStart planTime priority prioritySoc pv pvAction pvEnergy pvPower pvRemaining residualPower sessionCo2PerKWh sessionEnergy sessionPrice sessionPricePerKWh sessionSolarPercentage siteTitle smartCostActive smartCostNextStart smartCostType sponsor statistics tariffFeedIn tariffGrid tariffPriceHome tariffPriceLoadpoints title vehicleClimaterActive vehicleDetectionActive vehicleLimitSoc vehicleName vehicleOdometer vehicleRange vehicleSoc vehicleWelcomeActive vehicles version]

-> ReConnect Car1 10:21

[main ] DEBUG 2024/11/28 10:21:19 vehicle status: A (XC40volvo4evcc)
[main ] DEBUG 2024/11/28 10:21:19 vehicle status: B (XC90volvo4evcc)
[lp-1 ] INFO 2024/11/28 10:21:19 vehicle updated: unknown -> XC90volvo4evcc
[lp-1 ] DEBUG 2024/11/28 10:21:19 vehicle status: B
  "Car1": {
    "chargingSystemStatus": {
      "value": "CHARGING_SYSTEM_IDLE",
      "timestamp": "2024-11-28T09:21:20Z"
    },
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_CONNECTED_AC",
      "timestamp": "2024-11-28T09:21:20Z"
    },
    "EvccStatus": {
      "value": "B"

Timestamp of chargingConnectionStatus hasn't changed to 10:21. It seems that volvo4evv does not recognize the reconnect

-> Disconnect Car1 at 10:24

lp-1 ] DEBUG 2024/11/28 10:24:49 charger status: A
[lp-1 ] INFO 2024/11/28 10:24:49 car disconnected
[lp-1 ] INFO 2024/11/28 10:24:49 vehicle updated: XC90volvo4evcc -> unknown
  "Car1": {
    "chargingSystemStatus": {
      "value": "CHARGING_SYSTEM_IDLE",
      "timestamp": "2024-11-28T09:21:20Z"
    },
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_CONNECTED_AC",
      "timestamp": "2024-11-28T09:21:20Z"
    },
    "EvccStatus": {
      "value": "B"

10:27: unchanged CHARGING_SYSTEM_IDLE, CONNECTION_STATUS_CONNECTED_AC, EVCC Status B

10:38: unchanged CHARGING_SYSTEM_IDLE, CONNECTION_STATUS_CONNECTED_AC, EVCC Status B

11:13: Car1 gets disconnected in Volvo4evcc, this is the event of 10:24

Car1
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_DISCONNECTED",
      "timestamp": "2024-11-28T09:24:43Z"
    },
    "EvccStatus": {
      "value": "A"

11:14: Car0 connected

  "Car0": {
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_DISCONNECTED",
      "timestamp": "2024-11-28T10:06:35Z"
    },
    "EvccStatus": {
      "value": "A"

  "Car1": {
     "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_DISCONNECTED",
      "timestamp": "2024-11-28T09:24:43Z"
    },
    "EvccStatus": {
      "value": "A"

11:15 GuestCar shown in EVCC EVCC Log:

[push ] ERROR 2024/11/28 11:14:49 invalid message template for connect: wanted: [vehicleTitle], got: [auth battery batteryBoost batteryCapacity batteryDischargeControl batteryEnergy batteryGridChargeActive batteryGridChargeLimit batteryMode batteryPower batterySoc bufferSoc bufferStartSoc chargeCurrent chargeCurrents chargeDuration chargePower chargeRemainingDuration chargeRemainingEnergy chargeTotalImport chargedEnergy chargerFeatureHeating chargerFeatureIntegratedDevice chargerIcon chargerPhases1p3p chargerPhysicalPhases chargerStatusReason charging connected connectedDuration currency disableDelay disableThreshold effectiveLimitSoc effectiveMaxCurrent effectiveMinCurrent effectivePlanSoc effectivePlanTime effectivePriority enableDelay enableThreshold enabled fatal greenShareHome greenShareLoadpoints gridConfigured gridCurrents gridEnergy gridPower gridPowers hems homePower influx interval limitEnergy limitSoc loadpoint maxCurrent minCurrent mode mqtt network phaseAction phaseRemaining phasesActive phasesConfigured phasesEnabled planEnergy planOverrun planProjectedEnd planProjectedStart planTime priority prioritySoc pv pvAction pvEnergy pvPower pvRemaining residualPower sessionCo2PerKWh sessionEnergy sessionPrice sessionPricePerKWh sessionSolarPercentage siteTitle smartCostActive smartCostNextStart smartCostType sponsor statistics tariffFeedIn tariffGrid tariffPriceHome tariffPriceLoadpoints title vehicleClimaterActive vehicleDetectionActive vehicleLimitSoc vehicleName vehicleOdometer vehicleRange vehicleSoc vehicleWelcomeActive vehicles version]
[push ] ERROR 2024/11/28 11:14:49 invalid message template for start: wanted: [vehicleTitle], got: [auth battery batteryBoost batteryCapacity batteryDischargeControl batteryEnergy batteryGridChargeActive batteryGridChargeLimit batteryMode batteryPower batterySoc bufferSoc bufferStartSoc chargeCurrent chargeCurrents chargeDuration chargePower chargeRemainingDuration chargeRemainingEnergy chargeTotalImport chargedEnergy chargerFeatureHeating chargerFeatureIntegratedDevice chargerIcon chargerPhases1p3p chargerPhysicalPhases chargerStatusReason charging connected connectedDuration currency disableDelay disableThreshold effectiveLimitSoc effectiveMaxCurrent effectiveMinCurrent effectivePlanSoc effectivePlanTime effectivePriority enableDelay enableThreshold enabled fatal greenShareHome greenShareLoadpoints gridConfigured gridCurrents gridEnergy gridPower gridPowers hems homePower influx interval limitEnergy limitSoc loadpoint maxCurrent minCurrent mode mqtt network phaseAction phaseRemaining phasesActive phasesConfigured phasesEnabled planEnergy planOverrun planProjectedEnd planProjectedStart planTime priority prioritySoc pv pvAction pvEnergy pvPower pvRemaining residualPower sessionCo2PerKWh sessionEnergy sessionPrice sessionPricePerKWh sessionSolarPercentage siteTitle smartCostActive smartCostNextStart smartCostType sponsor statistics tariffFeedIn tariffGrid tariffPriceHome tariffPriceLoadpoints title vehicleClimaterActive vehicleDetectionActive vehicleLimitSoc vehicleName vehicleOdometer vehicleRange vehicleSoc vehicleWelcomeActive vehicles version]
[main ] DEBUG 2024/11/28 11:14:49 vehicle status: A (XC40volvo4evcc)
[main ] DEBUG 2024/11/28 11:14:49 vehicle status: A (XC90volvo4evcc)

11:18: EVCC gets the info that XC40 (CAR0) gets connected - 4 Minutes after connection

[lp-1 ] DEBUG 2024/11/28 11:18:49 charger status: B
[lp-1 ] DEBUG 2024/11/28 11:18:49 vehicle api refresh
[main ] DEBUG 2024/11/28 11:18:49 vehicle status: B (XC40volvo4evcc)
[main ] DEBUG 2024/11/28 11:18:49 vehicle status: A (XC90volvo4evcc)
[lp-1 ] INFO 2024/11/28 11:18:49 vehicle updated: unknown -> XC40volvo4evcc
[lp-1 ] DEBUG 2024/11/28 11:18:49 vehicle status: B
  "Car0": {
    "chargingSystemStatus": {
      "value": "CHARGING_SYSTEM_IDLE",
      "timestamp": "2024-11-28T10:14:52Z"
    },
    "chargingConnectionStatus": {
      "value": "CONNECTION_STATUS_CONNECTED_AC",
      "timestamp": "2024-11-28T10:14:52Z"
    },
    "EvccStatus": {
      "value": "B"
MartijnvanGeffen13 commented 14 hours ago

Thx, So in essence it seems to work but its slow atm , (This is due to the saving of API calls with a single car )

Let me see if i can add some enhanced logic to speed it up without generating excessive API calls.

For the EVCC error, no clue here on my end looks like that the messaging part but i don't have enough experience with EVCC to know why that generates , did you have that with other modules ? not sure why it would relate other than using a custom vehicle VS a templated one. but the use the same base YAML