-
Notifications
You must be signed in to change notification settings - Fork 766
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
Status: 500. Message: db query error: pq: invalid input syntax for type json #4445
Comments
All it needed was more data, a couple of charging sessions helped populate the data slowly. However, if anyone can include error handling when the data is NULL that would be something good to have. |
@dayal18 - i guess the problem no longer exists for you but opened a PR that improves the behavior. |
Wait for the next release or charge your car ;) |
As you can see, i've already charged my car 4 times in this current installation? |
Oh, is it an lfp battery ? What percentage have you charged to? |
No, i have the NMC-battery (Model Y 2024 Long Range RWD) . But i see that LFP battery is enabled in the Teslamate settings... For now disabled. I hope the data will be recovered soon. |
🤔 i wonder why it happens in your case... can you go into dashboard settings -> Variable -> aux and see the preview of the value? is it completely empty? - what shows up if you change the sql to this one: WITH Aux AS
(
SELECT
car_id,
COALESCE(efficiency,
(SELECT efficiency
FROM cars WHERE id = $car_id) * 100) AS efficiency
FROM (
SELECT ROUND((charge_energy_added / NULLIF(end_rated_range_km - start_rated_range_km, 0))::numeric, 3) * 100 as efficiency,
COUNT(*) as count, $car_id AS car_id
FROM charging_processes
WHERE car_id = $car_id
AND duration_min > 10
AND end_battery_level <= 95
AND start_rated_range_km IS NOT NULL
AND end_rated_range_km IS NOT NULL
AND charge_energy_added > 0
GROUP BY 1
ORDER BY 2 DESC
LIMIT 1
) AS DerivatedEfficiency
),
CurrentCapacity AS
(
SELECT AVG(Capacity) AS Capacity
FROM (
SELECT
c.rated_battery_range_km * aux.efficiency / c.usable_battery_level AS Capacity
FROM charging_processes cp
INNER JOIN charges c
ON c.charging_process_id = cp.id
INNER JOIN aux ON cp.car_id = aux.car_id
WHERE cp.car_id = $car_id
AND cp.end_date IS NOT NULL
AND cp.charge_energy_added >= aux.efficiency
AND c.usable_battery_level > 0
ORDER BY cp.end_date DESC LIMIT 10) AS lastCharges
),
MaxCapacity AS
(
SELECT
MAX(c.rated_battery_range_km * aux.efficiency / c.usable_battery_level) AS Capacity
FROM charging_processes cp
INNER JOIN (
SELECT charging_process_id, MAX(date) as date FROM charges WHERE usable_battery_level > 0 GROUP BY charging_process_id) AS gcharges
ON cp.id = gcharges.charging_process_id
INNER JOIN charges c
ON c.charging_process_id = cp.id AND c.date = gcharges.date
INNER JOIN aux ON cp.car_id = aux.car_id
WHERE cp.car_id = $car_id
AND cp.end_date IS NOT NULL
AND cp.charge_energy_added >= aux.efficiency
),
CurrentRange AS
(
SELECT (range * 100.0 / usable_battery_level) AS range
FROM (
(SELECT date, ${preferred_range}_battery_range_km AS range, usable_battery_level AS usable_battery_level
FROM positions WHERE car_id = $car_id AND ideal_battery_range_km IS NOT NULL AND usable_battery_level > 0 ORDER BY date DESC LIMIT 1)
UNION ALL
(SELECT date, ${preferred_range}_battery_range_km AS range, usable_battery_level as usable_battery_level
FROM charges c JOIN charging_processes p ON p.id = c.charging_process_id
WHERE p.car_id = $car_id AND usable_battery_level > 0 ORDER BY date DESC LIMIT 1)
) AS data
ORDER BY date DESC
LIMIT 1
),
MaxRange AS
(
SELECT
floor(extract(epoch from date)/86400)*86400 AS time,
CASE WHEN sum(usable_battery_level) = 0 THEN sum(${preferred_range}_battery_range_km) * 100
ELSE sum(${preferred_range}_battery_range_km) / sum(usable_battery_level) * 100
END AS range
FROM (
SELECT battery_level, usable_battery_level, date, ${preferred_range}_battery_range_km from charges c
JOIN charging_processes p ON p.id = c.charging_process_id
WHERE p.car_id = $car_id AND usable_battery_level IS NOT NULL) AS data
GROUP BY 1
ORDER BY 2 DESC
LIMIT 1
),
Base as (
select null
)
SELECT
json_build_object(
'MaxRange', convert_km(MaxRange.range,'$length_unit'),
'CurrentRange', convert_km(CurrentRange.range,'$length_unit'),
'MaxCapacity', MaxCapacity.Capacity,
'CurrentCapacity', CASE WHEN CurrentCapacity.Capacity IS NULL THEN 1 ELSE CurrentCapacity.Capacity END,
'RatedEfficiency', aux.efficiency
)
FROM Base, MaxRange, CurrentRange, Aux, MaxCapacity, CurrentCapacity |
You need to go to the battery health dashboard first |
just open the variable labeled "aux" and check it's output (bottom -> Preview) and post it here. Afterwards you can modify the query and recheck the output. |
🤔what version of postgres are you using? |
14 should be fine (while we recommend the latest (17)) - Don't understand why at least the updated query is not returning a valid json string. |
I don't know :-( . I can give you remote access to the environment if you want? I just don't know how to share the login details with you. |
I wouldn't have asked but do appreciate the trust. You could send over the secrets via saltify by making use of my commit email. |
Don't feel obligated. I'm already glad you're so eager to help! :) I'll send it to hello att saltify.io . Give me 15 minutes :) |
no, it's just the service you can use. sorry causing any misunderstanding. you can find the email in the second line here: https://github.com/teslamate-org/teslamate/commit/c7770ec12199afc1239266d968f25ca22cc432c9.patch |
Thanks, it's send! :) |
Ok, found it. Learned that #4448 is not fully fixing the issue as CROSS JOIN cannot be used if one of the tables is empty. Opened #4463 and patched your local dashboard ;) To reliably calculate Efficiency you have to charge for min 10 minutes and max 95%. Afterwards other dashboards will also fully populate (e.g. Efficiency Dashboard). I will look into ways to further improve the Query tomorrow but glad to have found an explanation. |
Glad you were able to find it, and that I could make a small contribution to it! :) I will keep an eye on the dashboard in the coming days to see if everything works well. Thanks again for your help! :) |
Is there an existing issue for this?
What happened?
Followed the exact steps mentioned here:
https://docs.teslamate.org/docs/installation/docker
Description: Ubuntu 24.04.1 LTS
Release: 24.04
Codename: noble
Docker version 27.3.1, build ce12230
teslamate:
image: teslamate/teslamate:latest
database:
image: postgres:17
grafana:
image: teslamate/grafana:latest
mosquitto:
image: eclipse-mosquitto:2
Expected Behavior
The dashboards are supposed to show data
Steps To Reproduce
Relevant log output
Screenshots
Additional data
No response
Type of installation
Docker
Version
Latest (v1.32)
The text was updated successfully, but these errors were encountered: