-
Notifications
You must be signed in to change notification settings - Fork 750
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature] Add total kWh Used/ recovered due to regenerative braking to drive details #4375
Comments
Hi, I tried with the query below - please try in your scenario. As we are calculating this based on positions data and ranges are only included for non streamed data (gathered every 15 seconds) I doubt in beeing that useful (most breaks should be shorter, so it's collecting only longer periods of driving downwards. WITH data AS (
SELECT
p.car_id,
lag(p.rated_battery_range_km) OVER (ORDER BY p.date) - p.rated_battery_range_km AS range_loss,
p.odometer - lag(p.odometer) OVER (ORDER BY p.date) AS distance
from positions p
WHERE
p.drive_id = {{DRIVE_ID_ENTER_HERE}} and ideal_battery_range_km is not null
ORDER BY date
)
SELECT
SUM(range_loss * car.efficiency * 1000) / convert_km(sum(distance)::numeric, 'km') as consumption_km
FROM data
JOIN cars car on car.id = car_id
WHERE range_loss < 0 |
Hey, first of all, thanks for the quick response. But, i also think the query is not what i am searching for. I want the exact kWh power added/removed from the battery not the KM which theoretically got added/removed. I tried to query this data on my own by getting the power for each second the car drove. which outputs exactly how much kW the car used/added per second (sometimes multiple entries per second, or only one per few seconds). I tried it with a 58.06km drive, which teslamate showed me it used 10.60kWh of energy. I tried this by going to
|
@jameskitt616 - thanks, going by power is better in that case as it's sampled as part of the streaming data and therefore shows short periods of regenerative breaking! Going with an AVG instead of SUM within the subquery should provide better results. to correctly account for period length and not using ang AVG (and deal with periods longer than 1 seconds correctly) here is an updated query: make sure to replace the drive id with data as (
select
case when power < 0 then 'regen' else 'use' end as action,
p.date,
p.power,
extract (second from p.date - lag(p.date) over (order by p.date)) as seconds
from positions p
where drive_id = 1519
)
select action, sum(power * (seconds / 3600)) from data where seconds is not null group by 1 testing this query on a drive i had this morning gives these results i guess that energy consumed (net) is incl. heating / cooling etc. while going by power is engine power only. happy to end it, think it's a great addition - as we are scanning positions for this query to work i think it should be included on drive details only for now (perf reasons). i suggest also adding a description on how the numbers are calculated and that it's important to have high data granularity for good results (e.g. enable streaming data). would you like to open a PR or do you want me to take over? |
add. comment: the query currently carries the last value forward. don't know if that is ok or if we should exclude periods of the drive where no data is sampled at all. for example if a new data point is missing for 3 seconds we exclude this power value from the results. with data as (
select
case when power < 0 then 'regen' else 'use' end as action,
p.date,
p.power,
extract (second from p.date - lag(p.date) over (order by p.date)) as seconds
from positions p
where drive_id = 1519
)
select action, sum(power * (seconds / 3600)) from data where seconds is not null and seconds < 3 group by 1 |
Thanks for the queries! |
feel free to tag me within the PR for reviewing / testing. |
PR opened in #4386 |
Is there an existing issue for this?
What happened?
I would love to see a feature where it would be calculated how much energy in kWh was used or recovered by regenerative braking in total for a single drive.
I know the drive details already show an "Energy Used" but this is rather a combination from both.
So if the car used 20 kWh for the drive and recovered 10 kWh by regenerative braking it would show 10 kWh Energy Used.
Expected Behavior
No response
Steps To Reproduce
No response
Relevant log output
Screenshots
No response
Additional data
No response
Type of installation
Docker
Version
v1.31.1
The text was updated successfully, but these errors were encountered: