blumeops/argocd/manifests/grafana-config/dashboards/configmap-teslamate-trip.yaml
Erich Blume 0604877db2 Add 'Tesla' prefix to all TeslaMate dashboard titles (#68)
## Summary
- Renamed all 18 TeslaMate Grafana dashboards to include "Tesla" prefix
- Improves organization and discoverability in the dashboard list

## Deployment and Testing
- [ ] Sync grafana-config app: `argocd app set grafana-config --revision feature/rename-tesla-dashboards && argocd app sync grafana-config`
- [ ] Verify dashboards display with "Tesla" prefix in Grafana

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Reviewed-on: https://forge.ops.eblu.me/eblume/blumeops/pulls/68
2026-01-29 06:55:44 -08:00

2819 lines
93 KiB
YAML

apiVersion: v1
kind: ConfigMap
metadata:
name: grafana-dashboard-teslamate-trip
namespace: monitoring
labels:
grafana_dashboard: "1"
annotations:
grafana_folder: "TeslaMate"
data:
teslamate-trip.json: |
{
"annotations": {
"list": [
{
"builtIn": 1,
"datasource": {
"type": "grafana",
"uid": "-- Grafana --"
},
"enable": true,
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"type": "dashboard"
}
]
},
"editable": true,
"fiscalYearStartMonth": 0,
"graphTooltip": 1,
"links": [
{
"icon": "doc",
"tags": [],
"targetBlank": true,
"title": "Select last three drives",
"type": "link",
"url": "/d/FkUpJpQZk/trip?from=$from"
},
{
"icon": "dashboard",
"tags": [],
"title": "TeslaMate",
"tooltip": "",
"type": "link",
"url": "${base_url:raw}"
},
{
"asDropdown": true,
"icon": "external link",
"tags": [
"tesla"
],
"title": "Dashboards",
"type": "dashboards"
}
],
"panels": [
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 4,
"panels": [],
"repeat": "car_id",
"title": "$car_id",
"type": "row"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 15,
"w": 13,
"x": 0,
"y": 1
},
"id": 6,
"maxDataPoints": 500,
"options": {
"basemap": {
"config": {},
"name": "Layer 0",
"type": "osm-standard"
},
"controls": {
"mouseWheelZoom": true,
"showAttribution": true,
"showDebug": false,
"showMeasure": false,
"showScale": false,
"showZoom": true
},
"layers": [
{
"config": {
"arrow": 0,
"style": {
"color": {
"fixed": "dark-blue"
},
"lineWidth": 2,
"opacity": 1,
"rotation": {
"fixed": 0,
"max": 360,
"min": -360,
"mode": "mod"
},
"size": {
"fixed": 3,
"max": 15,
"min": 2
},
"symbol": {
"fixed": "img/icons/marker/circle.svg",
"mode": "fixed"
},
"symbolAlign": {
"horizontal": "center",
"vertical": "center"
},
"textConfig": {
"fontSize": 12,
"offsetX": 0,
"offsetY": 0,
"textAlign": "center",
"textBaseline": "middle"
}
}
},
"name": "Layer 1",
"tooltip": true,
"type": "route"
}
],
"tooltip": {
"mode": "details"
},
"view": {
"allLayers": true,
"id": "fit",
"lat": 0,
"lon": 0,
"zoom": 15
}
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "with unioned_positions as (\n\n -- fetch all positions based on start_date of drives so the map aligns with data shown in other panels\n select p.*\n from positions p\n inner join drives d on p.drive_id = d.id\n where p.car_id = $car_id and $__timeFilter(d.start_date)\n\n union all\n\n -- get all positions logged while not driving\n select *\n from positions p\n where p.car_id = $car_id and drive_id is null and $__timeFilter(date))\n\nSELECT $__timeGroup(date, '5s') AS time,\n avg(latitude) AS latitude,\n avg(longitude) AS longitude\nfrom unioned_positions\nGROUP BY 1\nORDER BY 1 ASC",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"transparent": true,
"type": "geomap"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "distance_km"
},
"properties": [
{
"id": "unit",
"value": "km"
},
{
"id": "displayName",
"value": "Mileage"
}
]
},
{
"matcher": {
"id": "byName",
"options": "distance_mi"
},
"properties": [
{
"id": "unit",
"value": "mi"
},
{
"id": "displayName",
"value": "Mileage"
}
]
}
]
},
"gridPos": {
"h": 2,
"w": 6,
"x": 13,
"y": 1
},
"id": 10,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "area",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showPercentChange": false,
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "SELECT convert_km((max(odometer) - min(odometer))::numeric, '$length_unit') as \"distance_$length_unit\"\nFROM positions\nWHERE car_id = $car_id AND ideal_battery_range_km IS NOT NULL\nand (drive_id in (select id from drives where $__timeFilter(start_date)) or drive_id is null and $__timeFilter(date))\nORDER BY 1",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"type": "stat"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
}
},
"decimals": 1,
"mappings": [],
"unit": "dtdurations"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "charging (AC)"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "#73BF69",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "charging (DC)"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "#FADE2A",
"mode": "fixed"
}
}
]
},
{
"matcher": {
"id": "byName",
"options": "driving"
},
"properties": [
{
"id": "color",
"value": {
"fixedColor": "#5794F2",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 10,
"w": 5,
"x": 19,
"y": 1
},
"id": 38,
"maxDataPoints": 3,
"options": {
"displayLabels": [
"name",
"percent"
],
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true,
"values": [
"value"
]
},
"pieType": "pie",
"reduceOptions": {
"calcs": [
"lastNotNull"
],
"fields": "",
"values": true
},
"tooltip": {
"hideZeros": false,
"maxHeight": 600,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "SELECT\n\tnow() AS time,\n\tsum(extract(epoch FROM end_position.date - start_position.date)) as duration_sec,\n\t'driving' as metric\nFROM\n\tdrives\n\tJOIN positions start_position ON start_position_id = start_position.id\n\tJOIN positions end_position ON end_position_id = end_position.id\nWHERE\n\tdrives.car_id = $car_id\n\tAND $__timeFilter(start_date)\n\tAND end_date IS NOT NULL;",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "WITH charges_current AS (\n SELECT\n\t\tcp.id,\n \textract(epoch FROM LEAST(end_date, $__timeTo()) - GREATEST(start_date, $__timeFrom())) as duration_sec,\n\t\tCASE WHEN NULLIF(mode() within group (order by charger_phases),0) is null THEN 'charging (DC)'\n\t\t\t\t ELSE 'charging (AC)'\n\t\tEND AS current\n\tFROM charging_processes cp\n RIGHT JOIN charges ON cp.id = charges.charging_process_id\n WHERE\n\t cp.car_id = $car_id\n\t AND cp.charge_energy_added > 0\n \tAND ($__timeFilter(start_date) OR $__timeFilter(end_date))\n GROUP BY 1,2\n),\n\ncharges_total AS (\n SELECT\n \tsum(duration_sec) AS duration_sec,\n \tcurrent AS metric\n FROM charges_current\n GROUP BY 2\n ORDER BY metric\n)\n\nSELECT\n\tnow() AS time,\n\tcoalesce(duration_sec, 0) as duration_sec,\n metric\nFROM\n\tcharges_total;",
"refId": "B",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Time spent",
"type": "piechart"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"description": "",
"fieldConfig": {
"defaults": {
"mappings": [
{
"options": {
"match": "null",
"result": {
"text": "N/A"
}
},
"type": "special"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "speed_km"
},
"properties": [
{
"id": "unit",
"value": "velocitykmh"
},
{
"id": "displayName",
"value": "Ø Speed excl. breaks"
}
]
},
{
"matcher": {
"id": "byName",
"options": "speed_mi"
},
"properties": [
{
"id": "unit",
"value": "velocitymph"
},
{
"id": "displayName",
"value": "Ø Speed excl. breaks"
}
]
}
]
},
"gridPos": {
"h": 2,
"w": 6,
"x": 13,
"y": 3
},
"id": 26,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "SELECT\n convert_km(sum(end_position.odometer - start_position.odometer)::numeric, '$length_unit') / (sum(extract(epoch FROM end_position.date - start_position.date)) / 3600) as \"speed_$length_unit\"\nFROM\n\tdrives\n\tJOIN positions start_position ON start_position_id = start_position.id\n\tJOIN positions end_position ON end_position_id = end_position.id\nWHERE\n\tdrives.car_id = $car_id\n\tAND $__timeFilter(start_date)\n\tAND end_date IS NOT NULL;",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"type": "stat"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "speed_km"
},
"properties": [
{
"id": "unit",
"value": "velocitykmh"
},
{
"id": "displayName",
"value": "Ø Speed incl. DC charging"
}
]
},
{
"matcher": {
"id": "byName",
"options": "speed_mi"
},
"properties": [
{
"id": "unit",
"value": "velocitymph"
},
{
"id": "displayName",
"value": "Ø Speed incl. DC charging"
}
]
}
]
},
"gridPos": {
"h": 2,
"w": 6,
"x": 13,
"y": 5
},
"id": 28,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "horizontal",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": false
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "WITH dc_charges AS (\n SELECT\n\t\tcp.id,\n extract(epoch FROM cp.end_date - cp.start_date) as duration_sec,\n\t\tCASE WHEN NULLIF(mode() within group (order by charger_phases),0) is null THEN 'DC'\n\t\t\t\t ELSE 'AC'\n\t\tEND AS current\n\tFROM charging_processes cp\n RIGHT JOIN charges ON cp.id = charges.charging_process_id\n WHERE\n\t cp.car_id = $car_id\n\t AND cp.charge_energy_added > 0\n AND ($__timeFilter(start_date) OR $__timeFilter(end_date))\n GROUP BY 1,2\n),\n\ndata AS (\n (\n SELECT\n sum(end_position.odometer - start_position.odometer) as distance, \n sum(extract(epoch FROM end_position.date - start_position.date)) as duration_sec\n FROM\n drives\n JOIN positions start_position ON start_position_id = start_position.id\n JOIN positions end_position ON end_position_id = end_position.id\n WHERE\n drives.car_id = $car_id\n AND $__timeFilter(start_date)\n ) UNION ALL (\n SELECT\n NULL as distance,\n sum(duration_sec)\n FROM\n dc_charges\n WHERE\n current = 'DC'\n )\n)\n\nSELECT convert_km(sum(distance)::numeric, '$length_unit') / (sum(duration_sec) / 3600) as \"speed_$length_unit\"\nfrom data",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"type": "stat"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "consumption_km"
},
"properties": [
{
"id": "unit",
"value": "Wh/km"
},
{
"id": "displayName",
"value": "Ø Consumption (net)"
}
]
},
{
"matcher": {
"id": "byName",
"options": "consumption_mi"
},
"properties": [
{
"id": "unit",
"value": "Wh/mi"
},
{
"id": "displayName",
"value": "Ø Consumption (net)"
}
]
}
]
},
"gridPos": {
"h": 4,
"w": 3,
"x": 13,
"y": 7
},
"id": 30,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showPercentChange": false,
"text": {},
"textMode": "auto",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "SELECT\n sum((start_${preferred_range}_range_km - end_${preferred_range}_range_km) * car.efficiency * 1000) / \n convert_km(sum(distance)::numeric, '$length_unit') as \"consumption_$length_unit\"\nFROM drives\nJOIN cars car ON car.id = car_id\nWHERE $__timeFilter(start_date) AND car_id = $car_id",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"type": "stat"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "consumption_km"
},
"properties": [
{
"id": "unit",
"value": "Wh/km"
},
{
"id": "displayName",
"value": "Ø Consumption (gross)"
}
]
},
{
"matcher": {
"id": "byName",
"options": "consumption_mi"
},
"properties": [
{
"id": "unit",
"value": "Wh/mi"
},
{
"id": "displayName",
"value": "Ø Consumption (gross)"
}
]
}
]
},
"gridPos": {
"h": 4,
"w": 3,
"x": 16,
"y": 7
},
"id": 32,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "-- Query shared between Charging Stats, Statistics & Trip Dashboards (with minor changes) - ensure to modify in all places when necessary\n\nwith drives_start_event as (\n\n select\n 'drive_start' as event, start_date as date, start_${preferred_range}_range_km as range, start_km as odometer, car_id\n from drives\n where car_id = $car_id and $__timeFilter(start_date) and 48 <= extract(hour FROM to_timestamp(${__to:date:seconds}) - to_timestamp(${__from:date:seconds}))\n\n),\n\ndrives_end_event as (\n\n select\n 'drive_end' as event, end_date as date, end_${preferred_range}_range_km as range, end_km as odometer, car_id\n from drives\n where car_id = $car_id and $__timeFilter(start_date) and 48 <= extract(hour FROM to_timestamp(${__to:date:seconds}) - to_timestamp(${__from:date:seconds}))\n\n),\n\ncharging_processes_start_event as (\n\n select\n 'charging_process_start' as event, start_date as date, start_${preferred_range}_range_km as range, p.odometer, cp.car_id\n from charging_processes cp\n inner join positions p on cp.position_id = p.id\n where cp.car_id = $car_id and $__timeFilter(start_date) and 48 <= extract(hour FROM to_timestamp(${__to:date:seconds}) - to_timestamp(${__from:date:seconds}))\n\n),\n\ncharging_processes_end_event as (\n\n select\n 'charging_process_end' as event, end_date as date, end_${preferred_range}_range_km as range, p.odometer, cp.car_id\n from charging_processes cp\n inner join positions p on cp.position_id = p.id\n where cp.car_id = $car_id and $__timeFilter(start_date) and 48 <= extract(hour FROM to_timestamp(${__to:date:seconds}) - to_timestamp(${__from:date:seconds}))\n\n),\n\npositions as (\n\n select\n case\n when drive_id is not null and lead(drive_id) over w is not null then 'drive_start'\n else 'something'\n end as event,\n date, ${preferred_range}_battery_range_km as range, p.odometer, p.car_id\n from positions p\n where ideal_battery_range_km is not null and car_id = $car_id and 48 > extract(hour FROM to_timestamp(${__to:date:seconds}) - to_timestamp(${__from:date:seconds}))\n and (drive_id in (select id from drives where $__timeFilter(start_date)) or drive_id is null and $__timeFilter(date))\n window w as (order by date)\n\n),\n\ncombined as (\n\n select * from drives_start_event\n union all\n select * from drives_end_event\n union all\n select * from charging_processes_start_event\n union all\n select * from charging_processes_end_event\n union all\n select * from positions\n\n),\n\nfinal as (\n\n select\n car_id,\n lead(odometer) over w - odometer as distance,\n case when event != 'drive_start' then greatest(range - lead(range) over w, 0) else range - lead(range) over w end as range_loss\n from combined\n window w as (order by date asc)\n\n)\n\nselect\n 'Total Energy consumed (gross)' as metric,\n sum(range_loss) * c.efficiency as value,\n (sum(range_loss) * c.efficiency * 1000) / nullif(convert_km(sum(distance)::numeric, '$length_unit'), 0) as consumption_$length_unit\nfrom final\n inner join cars c on car_id = c.id\ngroup by c.efficiency",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"transformations": [
{
"id": "organize",
"options": {
"excludeByName": {
"metric": true,
"value": true
},
"includeByName": {},
"indexByName": {},
"renameByName": {}
}
}
],
"type": "stat"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 2,
"mappings": [
{
"options": {
"match": "null",
"result": {
"text": "N/A"
}
},
"type": "special"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 2,
"w": 6,
"x": 13,
"y": 11
},
"id": 22,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "select sum(cost) as \"Total Charging Cost\" from charging_processes where $__timeFilter(end_date) AND car_id = $car_id;",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"type": "stat"
},
{
"datasource": {
"type": "datasource",
"uid": "-- Mixed --"
},
"description": "",
"fieldConfig": {
"defaults": {
"decimals": 2,
"mappings": [
{
"options": {
"match": "null",
"result": {
"text": "N/A"
}
},
"type": "special"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "#c7d0d9",
"value": 0
}
]
},
"unit": "none"
},
"overrides": []
},
"gridPos": {
"h": 2,
"w": 5,
"x": 19,
"y": 11
},
"id": 43,
"maxDataPoints": 100,
"options": {
"colorMode": "value",
"fieldOptions": {
"calcs": [
"lastNotNull"
]
},
"graphMode": "none",
"justifyMode": "auto",
"orientation": "auto",
"percentChangeColorMode": "standard",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showPercentChange": false,
"textMode": "value_and_name",
"wideLayout": true
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "WITH charges as (\r\n SELECT\r\n sum(cost) / sum(charge_energy_added) as cost_per_kwh\r\n FROM charging_processes\r\n where car_id = $car_id and $__timeFilter(start_date)\r\n),\r\n\r\nmileage as (\r\n SELECT convert_km((max(odometer) - min(odometer))::numeric, '$length_unit') as distance\r\n FROM positions\r\n WHERE car_id = $car_id and ideal_battery_range_km IS NOT NULL\r\n and (drive_id in (select id from drives where $__timeFilter(start_date)) or drive_id is null and $__timeFilter(date))\r\n)\r\n\r\nselect\r\n 'Total Energy consumed (gross)' as metric, -- Hack required for Join Transformation\r\n cost_per_kwh / distance * 100 as cost_mileage\r\nfrom mileage cross join charges",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
},
{
"datasource": {
"type": "datasource",
"uid": "-- Dashboard --"
},
"hide": false,
"panelId": 32,
"refId": "B"
}
],
"title": "",
"transformations": [
{
"id": "joinByField",
"options": {
"byField": "metric",
"mode": "inner"
}
},
{
"id": "calculateField",
"options": {
"alias": "Ø Cost per 100 $length_unit",
"binary": {
"left": {
"matcher": {
"id": "byName",
"options": "cost_mileage"
}
},
"operator": "*",
"right": {
"matcher": {
"id": "byName",
"options": "value"
}
}
},
"mode": "binary",
"reduce": {
"reducer": "sum"
},
"replaceFields": true,
"window": {
"reducer": "mean",
"windowAlignment": "trailing",
"windowSize": 0.1,
"windowSizeMode": "percentage"
}
}
}
],
"type": "stat"
},
{
"datasource": {
"type": "datasource",
"uid": "-- Mixed --"
},
"fieldConfig": {
"defaults": {
"decimals": 2,
"displayName": "${__cell_0}",
"links": [],
"mappings": [],
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "light-yellow",
"value": 0
},
{
"color": "semi-dark-yellow",
"value": 10
},
{
"color": "semi-dark-orange",
"value": 100
}
]
},
"unit": "kwatth"
},
"overrides": []
},
"gridPos": {
"h": 3,
"w": 11,
"x": 13,
"y": 13
},
"id": 40,
"options": {
"displayMode": "gradient",
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": false
},
"maxVizHeight": 300,
"minVizHeight": 10,
"minVizWidth": 0,
"namePlacement": "auto",
"orientation": "horizontal",
"reduceOptions": {
"calcs": [
"mean"
],
"fields": "",
"values": true
},
"showUnfilled": false,
"sizing": "auto",
"valueMode": "color"
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "datasource",
"uid": "-- Dashboard --"
},
"panelId": 32,
"refId": "A"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "WITH charges_current AS (\n SELECT\n\t\tcp.id,\n\t\tcp.charge_energy_added as energy_added,\n\t\tCASE WHEN NULLIF(mode() within group (order by charger_phases),0) is null THEN 'Total Energy added (DC)'\n\t\t\t\t ELSE 'Total Energy added (AC)'\n\t\tEND AS metric\n\tFROM charging_processes cp\n RIGHT JOIN charges ON cp.id = charges.charging_process_id\n WHERE\n\t cp.car_id = $car_id\n\t AND cp.charge_energy_added > 0\n \tAND ($__timeFilter(start_date) OR $__timeFilter(end_date))\n GROUP BY 1,2\n)\n\nSELECT metric, sum(energy_added) AS energy_added\nFROM charges_current\nGROUP BY 1\nORDER BY 1 DESC;",
"refId": "B",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"transformations": [
{
"id": "filterFieldsByName",
"options": {
"include": {
"pattern": "^(?:(?!consumption).)*$"
}
}
}
],
"type": "bargauge"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "continuous-GrYlRd"
},
"custom": {
"axisPlacement": "auto",
"fillOpacity": 100,
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineWidth": 0,
"spanNulls": false
},
"mappings": [
{
"options": {
"0": {
"color": "#6ED0E0",
"index": 0,
"text": "online"
},
"1": {
"color": "#8F3BB8",
"index": 1,
"text": "driving"
},
"2": {
"color": "#F2CC0C",
"index": 2,
"text": "charging"
},
"3": {
"color": "#FFB357",
"index": 3,
"text": "offline"
},
"4": {
"color": "#56A64B",
"index": 4,
"text": "asleep"
},
"5": {
"color": "#6ED0E0",
"index": 5,
"text": "online"
},
"6": {
"color": "#E02F44",
"index": 6,
"text": "updating"
},
"null": {
"index": 7,
"text": "N/A"
}
},
"type": "value"
}
],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
}
]
}
},
"overrides": []
},
"gridPos": {
"h": 2,
"w": 24,
"x": 0,
"y": 16
},
"id": 20,
"options": {
"alignValue": "center",
"legend": {
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"mergeValues": true,
"rowHeight": 1,
"showValue": "never",
"tooltip": {
"hideZeros": false,
"maxHeight": 600,
"mode": "single",
"sort": "none"
}
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "WITH states AS (\n SELECT\n unnest(ARRAY [start_date + interval '1 second', end_date]) AS date,\n unnest(ARRAY [2, 0]) AS state\n FROM charging_processes\n WHERE\n car_id = $car_id AND \n ($__timeFrom() :: timestamp - interval '30 day') < start_date AND \n (end_date < ($__timeTo() :: timestamp + interval '30 day') OR end_date IS NULL)\n UNION\n SELECT\n unnest(ARRAY [start_date + interval '1 second', end_date]) AS date,\n unnest(ARRAY [1, 0]) AS state\n FROM drives\n WHERE\n car_id = $car_id AND \n ($__timeFrom() :: timestamp - interval '30 day') < start_date AND \n (end_date < ($__timeTo() :: timestamp + interval '30 day') OR end_date IS NULL)\n UNION\n SELECT\n start_date AS date,\n CASE\n WHEN state = 'offline' THEN 3\n WHEN state = 'asleep' THEN 4\n WHEN state = 'online' THEN 5\n END AS state\n FROM states\n WHERE\n car_id = $car_id AND \n ($__timeFrom() :: timestamp - interval '30 day') < start_date AND \n (end_date < ($__timeTo() :: timestamp + interval '30 day') OR end_date IS NULL)\n UNION\n SELECT\n unnest(ARRAY [start_date + interval '1 second', end_date]) AS date,\n unnest(ARRAY [6, 0]) AS state\n FROM updates\n WHERE\n car_id = $car_id AND \n ($__timeFrom() :: timestamp - interval '30 day') < start_date AND \n (end_date < ($__timeTo() :: timestamp + interval '30 day') OR end_date IS NULL)\n)\nSELECT date AS \"time\", state\nFROM states\nWHERE \n date IS NOT NULL AND\n ($__timeFrom() :: timestamp - interval '30 day') < date AND \n date < ($__timeTo() :: timestamp + interval '30 day') \nORDER BY date ASC, state ASC;",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "",
"transparent": true,
"type": "state-timeline"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"inspect": false
},
"decimals": 2,
"displayName": "",
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "short"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "start_date"
},
"properties": [
{
"id": "displayName",
"value": "Date"
},
{
"id": "unit",
"value": "dateTimeAsLocal"
},
{
"id": "links",
"value": [
{
"targetBlank": false,
"title": "View drive details",
"url": "/d/zm7wN6Zgz/drive-details?from=${__data.fields.start_date_ts.numeric}&to=${__data.fields.end_date_ts.numeric}&var-car_id=${__data.fields.car_id.numeric}&var-drive_id=${__data.fields.drive_id.numeric}"
}
]
},
{
"id": "custom.width",
"value": 210
}
]
},
{
"matcher": {
"id": "byName",
"options": "consumption_kwh_km"
},
"properties": [
{
"id": "displayName",
"value": "Ø Consumption (net)"
},
{
"id": "unit",
"value": "Wh/km"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 165
}
]
},
{
"matcher": {
"id": "byName",
"options": "consumption_kwh_mi"
},
"properties": [
{
"id": "displayName",
"value": "Ø Consumption (net)"
},
{
"id": "unit",
"value": "Wh/mi"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 165
}
]
},
{
"matcher": {
"id": "byName",
"options": "distance_km"
},
"properties": [
{
"id": "displayName",
"value": "Distance"
},
{
"id": "unit",
"value": "lengthkm"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 80
}
]
},
{
"matcher": {
"id": "byName",
"options": "start_address"
},
"properties": [
{
"id": "displayName",
"value": "Start"
},
{
"id": "links",
"value": [
{
"targetBlank": true,
"title": "Create or edit geo-fence",
"url": "${base_url:raw}/geo-fences/${__data.fields.start_path}"
}
]
},
{
"id": "custom.minWidth",
"value": 200
}
]
},
{
"matcher": {
"id": "byName",
"options": "end_address"
},
"properties": [
{
"id": "displayName",
"value": "Destination"
},
{
"id": "links",
"value": [
{
"targetBlank": true,
"title": "Create or edit geo-fence",
"url": "${base_url:raw}/geo-fences/${__data.fields.end_path}"
}
]
},
{
"id": "custom.minWidth",
"value": 200
}
]
},
{
"matcher": {
"id": "byName",
"options": "duration_min"
},
"properties": [
{
"id": "displayName",
"value": "Duration"
},
{
"id": "unit",
"value": "m"
},
{
"id": "decimals",
"value": 0
},
{
"id": "links",
"value": [
{
"title": "${__data.fields.duration_str}",
"url": ""
}
]
},
{
"id": "custom.width",
"value": 100
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "/.*_ts/"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
},
{
"matcher": {
"id": "byName",
"options": "distance_mi"
},
"properties": [
{
"id": "displayName",
"value": "Distance"
},
{
"id": "unit",
"value": "lengthmi"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 80
}
]
},
{
"matcher": {
"id": "byName",
"options": "% Start"
},
"properties": [
{
"id": "unit",
"value": "percent"
},
{
"id": "custom.align",
"value": "auto"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 75
}
]
},
{
"matcher": {
"id": "byName",
"options": "% End"
},
"properties": [
{
"id": "unit",
"value": "percent"
},
{
"id": "custom.align",
"value": "auto"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 65
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "(start_path|end_path|duration_str|car_id|drive_id)"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
}
]
},
"gridPos": {
"h": 11,
"w": 24,
"x": 0,
"y": 18
},
"id": 2,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true,
"sortBy": [
{
"desc": true,
"displayName": "Date"
}
]
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "WITH data AS (\n SELECT\n round(extract(epoch FROM start_date)) * 1000 AS start_date_ts,\n round(extract(epoch FROM end_date)) * 1000 AS end_date_ts,\n car.id as car_id,\n CASE WHEN start_geofence.id IS NULL THEN CONCAT('new?lat=', start_position.latitude, '&lng=', start_position.longitude)\n WHEN start_geofence.id IS NOT NULL THEN CONCAT(start_geofence.id, '/edit')\n END as start_path,\n CASE WHEN end_geofence.id IS NULL THEN CONCAT('new?lat=', end_position.latitude, '&lng=', end_position.longitude)\n WHEN end_geofence.id IS NOT NULL THEN CONCAT(end_geofence.id, '/edit')\n END as end_path,\n TO_CHAR((duration_min * INTERVAL '1 minute'), 'HH24:MI') as duration_str,\n drives.id as drive_id,\n -- Columns\n start_date,\n COALESCE(start_geofence.name, CONCAT_WS(', ', COALESCE(start_address.name, nullif(CONCAT_WS(' ', start_address.road, start_address.house_number), '')), start_address.city)) AS start_address,\n COALESCE(end_geofence.name, CONCAT_WS(', ', COALESCE(end_address.name, nullif(CONCAT_WS(' ', end_address.road, end_address.house_number), '')), end_address.city)) AS end_address,\n duration_min,\n distance,\n start_position.usable_battery_level as start_usable_battery_level,\n start_position.battery_level as start_battery_level,\n end_position.usable_battery_level as end_usable_battery_level,\n end_position.battery_level as end_battery_level,\n start_position.battery_level != start_position.usable_battery_level OR end_position.battery_level != end_position.usable_battery_level as reduced_range,\n duration_min > 1 AND distance > 1 AND ( \n start_position.usable_battery_level IS NULL OR end_position.usable_battery_level IS NULL\tOR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) as is_sufficiently_precise,\n start_${preferred_range}_range_km - end_${preferred_range}_range_km as range_diff,\n car.efficiency as car_efficiency,\n outside_temp_avg,\n distance / NULLIF(duration_min, 0) * 60 AS avg_speed\n FROM drives\n LEFT JOIN addresses start_address ON start_address_id = start_address.id\n LEFT JOIN addresses end_address ON end_address_id = end_address.id\n LEFT JOIN positions start_position ON start_position_id = start_position.id\n LEFT JOIN positions end_position ON end_position_id = end_position.id\n LEFT JOIN geofences start_geofence ON start_geofence_id = start_geofence.id\n LEFT JOIN geofences end_geofence ON end_geofence_id = end_geofence.id\n LEFT JOIN cars car ON car.id = drives.car_id\n WHERE $__timeFilter(start_date) AND drives.car_id = $car_id\n ORDER BY start_date DESC\n)\nSELECT\n start_date_ts,\n end_date_ts,\n car_id,\n start_path,\n end_path,\n duration_str,\n drive_id,\n -- Columns\n start_date,\n start_address,\n end_address,\n duration_min,\n convert_km(distance::numeric, '$length_unit') AS distance_$length_unit,\n start_battery_level as \"% Start\",\n end_battery_level as \"% End\",\n CASE WHEN is_sufficiently_precise THEN range_diff * car_efficiency / convert_km(distance::numeric, '$length_unit') * 1000\n END AS consumption_kWh_$length_unit\nFROM data;",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Drives",
"type": "table"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {
"align": "auto",
"cellOptions": {
"type": "auto"
},
"inspect": false
},
"decimals": 2,
"displayName": "",
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "short"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "start_date"
},
"properties": [
{
"id": "displayName",
"value": "Date"
},
{
"id": "unit",
"value": "dateTimeAsLocal"
},
{
"id": "links",
"value": [
{
"targetBlank": false,
"title": "View charge details",
"url": "/d/BHhxFeZRz/charge-details?from=${__data.fields.start_date_ts.numeric}&to=${__data.fields.end_date_ts.numeric}&var-car_id=${__data.fields.car_id.numeric}&var-charging_process_id=${__data.fields.id.numeric:raw}"
}
]
},
{
"id": "custom.width",
"value": 210
}
]
},
{
"matcher": {
"id": "byName",
"options": "charge_energy_added"
},
"properties": [
{
"id": "displayName",
"value": "Energy added"
},
{
"id": "decimals",
"value": 2
},
{
"id": "custom.width",
"value": 115
}
]
},
{
"matcher": {
"id": "byName",
"options": "start_battery_level"
},
"properties": [
{
"id": "displayName",
"value": "% Start"
},
{
"id": "unit",
"value": "percent"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 72
}
]
},
{
"matcher": {
"id": "byName",
"options": "end_battery_level"
},
"properties": [
{
"id": "displayName",
"value": "% End"
},
{
"id": "unit",
"value": "percent"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 62
}
]
},
{
"matcher": {
"id": "byName",
"options": "duration_min"
},
"properties": [
{
"id": "displayName",
"value": "Duration"
},
{
"id": "unit",
"value": "m"
},
{
"id": "decimals",
"value": 1
},
{
"id": "custom.width",
"value": 80
}
]
},
{
"matcher": {
"id": "byName",
"options": "cost"
},
"properties": [
{
"id": "displayName",
"value": "Cost"
},
{
"id": "unit",
"value": "none"
},
{
"id": "decimals",
"value": 2
},
{
"id": "links",
"value": [
{
"targetBlank": false,
"title": "Set Cost",
"url": "${base_url:raw}/charge-cost/${__data.fields.id.numeric:raw}"
}
]
},
{
"id": "custom.width",
"value": 70
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "/.*_ts/"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
},
{
"matcher": {
"id": "byName",
"options": "id"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
},
{
"matcher": {
"id": "byName",
"options": "address"
},
"properties": [
{
"id": "displayName",
"value": "Location"
},
{
"id": "links",
"value": [
{
"targetBlank": true,
"title": "Create or edit geo-fence",
"url": "${base_url:raw}/geo-fences/${__data.fields.path}"
}
]
},
{
"id": "custom.minWidth",
"value": 200
}
]
},
{
"matcher": {
"id": "byName",
"options": "range_added_km"
},
"properties": [
{
"id": "displayName",
"value": "Range gained"
},
{
"id": "unit",
"value": "lengthkm"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.width",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "charge_energy_added_per_hour"
},
"properties": [
{
"id": "displayName",
"value": "Ø Power"
},
{
"id": "unit",
"value": "kwatt"
},
{
"id": "decimals",
"value": 1
},
{
"id": "custom.cellOptions",
"value": {
"type": "color-text"
}
},
{
"id": "thresholds",
"value": {
"mode": "absolute",
"steps": [
{
"color": "#96D98D",
"value": 0
},
{
"color": "#56A64B",
"value": 20
},
{
"color": "#37872D",
"value": 55
}
]
}
},
{
"id": "custom.width",
"value": 80
}
]
},
{
"matcher": {
"id": "byName",
"options": "range_added_mi"
},
"properties": [
{
"id": "displayName",
"value": "Range gained"
},
{
"id": "unit",
"value": "lengthmi"
},
{
"id": "decimals",
"value": 0
},
{
"id": "custom.minWidth",
"value": 120
}
]
},
{
"matcher": {
"id": "byName",
"options": "path"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
},
{
"matcher": {
"id": "byName",
"options": "charge_energy_used"
},
"properties": [
{
"id": "displayName",
"value": "Energy used"
},
{
"id": "decimals",
"value": 2
},
{
"id": "custom.width",
"value": 105
}
]
},
{
"matcher": {
"id": "byName",
"options": "car_id"
},
"properties": [
{
"id": "custom.hidden",
"value": true
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 24,
"x": 0,
"y": 29
},
"id": 36,
"options": {
"cellHeight": "sm",
"footer": {
"countRows": false,
"fields": "",
"reducer": [
"sum"
],
"show": false
},
"showHeader": true,
"sortBy": [
{
"desc": true,
"displayName": "Date"
}
]
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "table",
"rawQuery": true,
"rawSql": "WITH data AS (\n SELECT\n (round(extract(epoch FROM start_date) - 10) * 1000) AS start_date_ts,\n (round(extract(epoch FROM end_date) + 10) * 1000) AS end_date_ts,\n start_date,\n end_date,\n CONCAT_WS(', ', COALESCE(addresses.name, CONCAT_WS(' ', addresses.road, addresses.house_number)), addresses.city) AS address,\n g.name as geofence_name,\n g.id as geofence_id,\n p.latitude,\n p.longitude,\n charge_energy_added,\n charge_energy_used,\n duration_min,\n start_battery_level,\n end_battery_level,\n end_${preferred_range}_range_km - start_${preferred_range}_range_km as range_added,\n outside_temp_avg,\n c.id,\n p.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance,\n cars.efficiency,\n c.car_id,\n cost\n FROM\n charging_processes c\n LEFT JOIN positions p ON p.id = c.position_id\n LEFT JOIN cars ON cars.id = c.car_id\n LEFT JOIN addresses ON addresses.id = c.address_id\n LEFT JOIN geofences g ON g.id = geofence_id\nWHERE \n (charge_energy_added IS NULL OR charge_energy_added > 0) AND\n c.car_id = $car_id AND\n $__timeFilter(start_date)\nORDER BY\n start_date\n)\nSELECT\n start_date_ts,\n end_date_ts,\n CASE WHEN geofence_id IS NULL THEN CONCAT('new?lat=', latitude, '&lng=', longitude)\n WHEN geofence_id IS NOT NULL THEN CONCAT(geofence_id, '/edit')\n END as path,\n car_id,\n id,\n -- Columns\n start_date,\n COALESCE(geofence_name, address) as address, \n duration_min,\n cost,\n charge_energy_added,\n charge_energy_used,\n charge_energy_added * 60 / NULLIF (duration_min, 0) AS charge_energy_added_per_hour,\n convert_km(range_added, '$length_unit') AS range_added_$length_unit,\n start_battery_level,\n end_battery_level\nFROM\n data\nWHERE\n (distance >= 0 OR distance IS NULL)\nORDER BY\n start_date DESC;\n ",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Charges",
"transformations": [
{
"id": "merge",
"options": {
"reducers": []
}
}
],
"type": "table"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "opacity",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"decimals": 0,
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "percent"
},
"overrides": [
{
"matcher": {
"id": "byName",
"options": "battery_level"
},
"properties": [
{
"id": "unit",
"value": "percent"
},
{
"id": "displayName",
"value": "SOC"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": ".*_km$"
},
"properties": [
{
"id": "unit",
"value": "lengthkm"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": ".*_mi$"
},
"properties": [
{
"id": "unit",
"value": "lengthmi"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "range_ideal_.*"
},
"properties": [
{
"id": "displayName",
"value": "Range (ideal)"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "range_rated_.*"
},
"properties": [
{
"id": "displayName",
"value": "Range (rated)"
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 0,
"y": 37
},
"id": 42,
"options": {
"legend": {
"calcs": [
"min",
"max",
"lastNotNull"
],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "(\n SELECT $__timeGroup(date, '5s'), avg(battery_level) as battery_level, convert_km(avg(${preferred_range}_battery_range_km), '$length_unit') as range_${preferred_range}_${length_unit}\n FROM positions\n WHERE date BETWEEN ($__timeFrom()::timestamp - interval '1 day') AND ($__timeTo()::timestamp + interval '1 day') AND car_id = $car_id\n GROUP BY 1\n) UNION ALL (\n SELECT $__timeGroup(date, '5s'), avg(battery_level) as battery_level, convert_km(avg(${preferred_range}_battery_range_km), '$length_unit') as range_${preferred_range}_${length_unit}\n FROM charges c\n LEFT JOIN charging_processes p ON c.charging_process_id = p.id\n WHERE date BETWEEN ($__timeFrom()::timestamp - interval '1 day') AND ($__timeTo()::timestamp + interval '1 day') AND p.car_id = $car_id\n GROUP BY 1\n)\nORDER BY 1",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Battery Level & Range",
"type": "timeseries"
},
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "palette-classic"
},
"custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"barWidthFactor": 0.6,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "opacity",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"insertNulls": false,
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 5,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "never",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "off"
}
},
"mappings": [],
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": 0
},
{
"color": "red",
"value": 80
}
]
},
"unit": "short"
},
"overrides": [
{
"matcher": {
"id": "byRegexp",
"options": ".*_m$"
},
"properties": [
{
"id": "unit",
"value": "lengthm"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": ".*_ft$"
},
"properties": [
{
"id": "unit",
"value": "lengthft"
}
]
},
{
"matcher": {
"id": "byRegexp",
"options": "elevation_.*"
},
"properties": [
{
"id": "displayName",
"value": "Elevation"
},
{
"id": "color",
"value": {
"fixedColor": "semi-dark-blue",
"mode": "fixed"
}
}
]
}
]
},
"gridPos": {
"h": 8,
"w": 12,
"x": 12,
"y": 37
},
"id": 8,
"options": {
"legend": {
"calcs": [
"min",
"max",
"lastNotNull"
],
"displayMode": "table",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"hideZeros": false,
"mode": "multi",
"sort": "none"
}
},
"pluginVersion": "12.1.1",
"targets": [
{
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"editorMode": "code",
"format": "time_series",
"rawQuery": true,
"rawSql": "SELECT\n\t$__timeGroup(date, '5s'),\n\tROUND(convert_m(avg(elevation), '$alternative_length_unit')) AS elevation_${alternative_length_unit}\nFROM\n\tpositions\nWHERE\n car_id = $car_id AND\n date BETWEEN ($__timeFrom()::timestamp - interval '1 day') AND ($__timeTo()::timestamp + interval '1 day')\nGROUP BY\n 1\nORDER BY\n 1 ASC",
"refId": "A",
"sql": {
"columns": [
{
"parameters": [],
"type": "function"
}
],
"groupBy": [
{
"property": {
"type": "string"
},
"type": "groupBy"
}
],
"limit": 50
}
}
],
"title": "Elevation",
"type": "timeseries"
}
],
"preload": false,
"refresh": "",
"schemaVersion": 41,
"tags": [
"tesla"
],
"templating": {
"list": [
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, CONCAT('VIN ', vin)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;",
"hide": 2,
"includeAll": true,
"label": "Car",
"name": "car_id",
"options": [],
"query": "SELECT\n id as __value,\n CASE WHEN COUNT(id) OVER (PARTITION BY name) > 1 AND name IS NOT NULL THEN CONCAT(name, ' - ', RIGHT(vin, 6)) ELSE COALESCE(name, CONCAT('VIN ', vin)) end as __text \nFROM cars\nORDER BY display_priority ASC, name ASC, vin ASC;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "select unit_of_temperature from settings limit 1;",
"hide": 2,
"includeAll": false,
"label": "temperature unit",
"name": "temp_unit",
"options": [],
"query": "select unit_of_temperature from settings limit 1;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "select unit_of_length from settings limit 1;",
"hide": 2,
"includeAll": false,
"label": "length unit",
"name": "length_unit",
"options": [],
"query": "select unit_of_length from settings limit 1;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "select case when unit_of_length = 'km' then 'm' when unit_of_length = 'mi' then 'ft' end from settings limit 1;",
"hide": 2,
"includeAll": false,
"name": "alternative_length_unit",
"options": [],
"query": "select case when unit_of_length = 'km' then 'm' when unit_of_length = 'mi' then 'ft' end from settings limit 1;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "select preferred_range from settings limit 1;",
"hide": 2,
"includeAll": false,
"name": "preferred_range",
"options": [],
"query": "select preferred_range from settings limit 1;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "select base_url from settings limit 1;",
"hide": 2,
"includeAll": false,
"name": "base_url",
"options": [],
"query": "select base_url from settings limit 1;",
"refresh": 1,
"regex": "",
"type": "query"
},
{
"current": {},
"datasource": {
"type": "grafana-postgresql-datasource",
"uid": "TeslaMate"
},
"definition": "with last_drives as (select start_date from drives order by start_date desc limit 3)\nselect extract(epoch from min(start_date)) * 1000 from last_drives;",
"hide": 2,
"includeAll": false,
"name": "from",
"options": [],
"query": "with last_drives as (select start_date from drives order by start_date desc limit 3)\nselect extract(epoch from min(start_date)) * 1000 from last_drives;",
"refresh": 1,
"regex": "",
"type": "query"
}
]
},
"time": {
"from": "now-24h",
"to": "now"
},
"timepicker": {},
"timezone": "",
"title": "Tesla Trip",
"uid": "FkUpJpQZk",
"version": 1
}