psa_car_controller icon indicating copy to clipboard operation
psa_car_controller copied to clipboard

Import trip data and charge data to Home Assisstant

Open lucasimons opened this issue 2 years ago • 13 comments

Hi, I would like to import the data of the charging sessions and trips, I have installed both influx and grafana but I cannot read the data I have installed everything as a Home Assistant addon

**Environment **

  • OS: HassOS
  • Peugeot e208

Additional context

image

lucasimons avatar Apr 26 '22 16:04 lucasimons

Hi lucasimons,

did you enable the external port? To open them in influx/grafana. image

If you want transfer data from other source like manual installation to HASS it is quite complicated, because you need to replace the .db file to get those data in HASS.

kurim avatar Apr 27 '22 18:04 kurim

I have enabled the port in fact I can see the data but I don't know how to import the trip and charge data inside Home Assistant as sensors . I wanted to create a sensor that counted how many kWh I lcharged and how many kilometers I did, for example, monthly or daily

lucasimons avatar Apr 27 '22 19:04 lucasimons

Ok~ you can use node red to import the data for example. This is what I do, it is more flexible then the other options like creating sensors in config

thats what i have create for me: image

kurim avatar Apr 27 '22 20:04 kurim

Did you manage to read the charge data via node red? For example, how much energy did you charge in the last session? Could I share the nodes?

lucasimons avatar Apr 27 '22 21:04 lucasimons

Good point, no that's nothing I test so far, since i just use this API: /get_vehicleinfo/ to read those data you see.

Here is my NodeRedFlow: flows.zip

About calculating charge value for charge session, I think you can do it like this: Check when Charge start + current SOC and check charge end then calculate the value between soc start+end. or flobz need to create an api which provide those data as well.

kurim avatar Apr 28 '22 06:04 kurim

thanks

this is what I would like to do...

https://grafana.szambetti.it/d/CPrt7kvnk/e208?orgId=1&kiosk=tv

@flobz is it possible with psa car controller installed as addon?

lucasimons avatar Apr 28 '22 07:04 lucasimons

You can analyse the panels, as far as I can see they do some SQL query's to get the data.

SELECT
    strftime('%Y-%m-%dT%H:%M:%S', start_at) || "Z00:00" AS start_time,
    COUNT(*) AS times,
    SUM((end_level - start_level) * .42) AS kwh_charged,
    SUM(((end_level - start_level) * .42) / ((strftime('%s', stop_at) - strftime('%s', start_at)) / 3600.0000))
	COUNT(*) AS average_kw
FROM
    battery
WHERE
    ((end_level - start_level) * .42) /((strftime('%s', stop_at) - strftime('%s', start_at)) / 3600.0000) < 22

Many things you might be able to do with NodRed as well, but you may need a database to store the values. But this is a different approach.

Notice: 42 seems not correct because battery has 46kWh (for Corsa-E) instead of 42kWh

kurim avatar Apr 28 '22 09:04 kurim

It is a different approach in fact I wanted to know if it was possible to do the same thing through the addon, surely the data is in a db but I don't know how to extrapolate the data

lucasimons avatar Apr 28 '22 09:04 lucasimons

Btw. why not follow this: https://github.com/flobz/psa_car_controller/issues/161 Since it is just another install way

kurim avatar May 01 '22 11:05 kurim

Because I have only a rpi with HassOS installed and I works fine, I doesn't have a Linux system to use this method...

lucasimons avatar May 01 '22 11:05 lucasimons

the problem is you don't have telegraf which seems to be essential for data transfer. For me i have it done by rednode+mysql: image

But it seems telegraf exist for Hass: https://community.home-assistant.io/t/telegraf-addon-for-hassio-glances-alternative/144662

kurim avatar May 01 '22 11:05 kurim

Hello again,

I have test it with: HassOS I have installed:

  • PSA 3.0.3
  • InfluxDB (https://addons.community)
  • Telegraf (https://github.com/Sabuto/hassio-repo)
  • Grafana (https://addons.community)

After install everything you need to change the configs:

InfluxDB:

auth: false
certfile: fullchain.pem
envvars:
  - name: INFLUXDB_HTTP_LOG_ENABLED
    value: 'true'
keyfile: privkey.pem
reporting: true
ssl: true
log_level: info

Telegraf:

custom_conf:
  enabled: true
  location: /config/telegraf.conf

Rest of this config can be ignored

After this open [File Editor] or [VSCode] and create the telegraf.conf in conf folder. (like mentioned in Grafana Guide) image

After this step you can Start InfluxDB + Telegraf + Grafana. Everytime you need to wait till everything loads complete (first time it take a while). Now open Grafana and use instead of localhost the fqdn of you device like: http://homeassistant.fritz.box:8086 And now you can create panels like in your example: image

kurim avatar May 01 '22 18:05 kurim

custom_conf:
  enabled: true
  location: /config/telegraf.conf

Can you import the trip / charge session to influx?

lucasimons avatar May 27 '23 11:05 lucasimons