flobz / psa_car_controller

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

Import trip data and charge data to Home Assisstant #356

Open lucasimons opened 2 years ago

lucasimons commented 2 years ago

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

Additional context

image

kurim commented 2 years ago

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.

lucasimons commented 2 years ago

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

kurim commented 2 years ago

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

lucasimons commented 2 years ago

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?

kurim commented 2 years ago

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.

lucasimons commented 2 years ago

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?

kurim commented 2 years ago

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

lucasimons commented 2 years ago

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

kurim commented 2 years ago

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

lucasimons commented 2 years ago

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

kurim commented 2 years ago

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 commented 2 years ago

Hello again,

I have test it with: HassOS I have installed:

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

lucasimons commented 1 year ago
custom_conf:
  enabled: true
  location: /config/telegraf.conf

Can you import the trip / charge session to influx?