"rawSql":"WITH energy as(\r\nSELECT\r\n\tsum(charge_energy_used) AS charged_kWh\r\nFROM\r\n\tcharging_processes\r\nWHERE\r\n\t$__timeFilter(end_date)\r\n\tAND car_id = $car_id),\r\nsince as (\r\n\tSELECT date FROM positions\r\n\tWHERE car_id = $car_id\r\n\tORDER BY date ASC\r\n\tLIMIT 1\r\n)\r\nSELECT (energy.charged_kWh / $distance_driven) as \"kwh_per_$length_unit\" FROM energy",
"description":"For this section, it's important that you have geo-fences called \"Home\" and \"Work\" if you want to see a bar with the energy charged on those places.",
"fieldConfig":{
"defaults":{
"color":{
"mode":"continuous-GrYlRd"
},
"mappings":[],
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"text",
"value":null
}
]
},
"unit":"kwatth"
},
"overrides":[]
},
"gridPos":{
"h":12,
"w":6,
"x":12,
"y":1
},
"id":49,
"options":{
"displayMode":"gradient",
"maxVizHeight":300,
"minVizHeight":10,
"minVizWidth":0,
"namePlacement":"auto",
"orientation":"vertical",
"reduceOptions":{
"calcs":[],
"fields":"/^energy$/",
"values":true
},
"showUnfilled":false,
"sizing":"auto",
"valueMode":"color"
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"editorMode":"code",
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT location, SUM(charge_energy_used) AS Energy\r\nFROM (\r\nSELECT\r\n CASE\r\n WHEN COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), '')))) ILIKE '%Home%' THEN COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), ''))))\r\n\t WHEN COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), '')))) ILIKE '%Work%' THEN COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), ''))))\r\n\t WHEN COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), '')))) ILIKE '%supercharger%' THEN 'Superchargers'\r\n\t ELSE 'Other'\r\n END AS location, charge_energy_used\r\nFROM\r\n\tcharging_processes c\r\nLEFT JOIN addresses address ON c.address_id = address.id\r\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\r\nWHERE\r\n\t car_id = $car_id\r\n\tAND $__timeFilter(end_date)\r\n\tAND c.charge_energy_used > 0\r\n) ChargeLocations\r\nGROUP BY location\r\nORDER BY Energy DESC",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"sql":{
"columns":[
{
"parameters":[],
"type":"function"
}
],
"groupBy":[
{
"property":{
"type":"string"
},
"type":"groupBy"
}
],
"limit":50
},
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Main locations",
"type":"bargauge"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"This dashboard is meant to have a look of all the charges in a given period (last 10 years by default). You can see the distance driven, number of charges, total charging cost, etc., both in summary or in separated lists.\n\nYou can expand/collapse the rows as needed.\n\nFrom the Monthly Stats row, you will have a table with links to other Teslamate Dashboards to have a look on a specific period, charge or trip.",
"fieldConfig":{
"defaults":{
"color":{
"mode":"palette-classic"
},
"custom":{
"hideFrom":{
"legend":false,
"tooltip":false,
"viz":false
}
},
"decimals":2,
"mappings":[],
"unit":"kwatth"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"AC"
},
"properties":[
{
"id":"color",
"value":{
"fixedColor":"semi-dark-green",
"mode":"fixed"
}
}
]
},
{
"matcher":{
"id":"byName",
"options":"DC"
},
"properties":[
{
"id":"color",
"value":{
"fixedColor":"light-orange",
"mode":"fixed"
}
}
]
}
]
},
"gridPos":{
"h":12,
"w":6,
"x":18,
"y":1
},
"id":51,
"maxDataPoints":3,
"options":{
"displayLabels":["name","percent","value"],
"legend":{
"displayMode":"list",
"placement":"bottom",
"showLegend":false
},
"pieType":"pie",
"reduceOptions":{
"calcs":["lastNotNull"],
"fields":"",
"values":false
},
"tooltip":{
"mode":"single",
"sort":"none"
}
},
"pluginVersion":"8.5.6",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"time_series",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH data AS (\n SELECT\n\t\tcp.id,\n\t\tcp.charge_energy_used,\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_used > 0.01\n\t AND $__timeFilter(start_date)\n GROUP BY 1,2\n)\nSELECT\n\tnow() AS time,\n\tsum(charge_energy_used) AS value,\n\tcurrent AS metric\nFROM data\nGROUP BY 3\nORDER BY metric DESC;",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Summary AC/DC Energy Used",
"type":"piechart"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"Use the dropdown at the top to choose the Geofence to display energy added from",
"fieldConfig":{
"defaults":{
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"distance_km"
},
"properties":[
{
"id":"unit",
"value":"km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"distance_mi"
},
"properties":[
{
"id":"unit",
"value":"mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":0,
"y":4
},
"id":66,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["sum"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["sum"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH free_energy AS (\r\nSELECT sum(charge_energy_used) AS free_charged_kWh\r\nFROM charging_processes cp\r\nINNER JOIN geofences g ON g.id = cp.geofence_id\r\nWHERE\r\n\t$__timeFilter(end_date)\r\n\tAND car_id = $car_id AND g.name = '$geofence'\r\nGROUP BY g.name),\r\nenergy as(\r\nSELECT\r\n\tsum(charge_energy_used) AS charged_kWh\r\nFROM\r\n\tcharging_processes\r\nWHERE\r\n\t$__timeFilter(end_date)\r\n\tAND car_id = $car_id\r\n)\r\nSELECT ($distance_driven * free_energy.free_charged_kWh / energy.charged_kWh) as \"distance_$length_unit\" FROM energy, free_energy",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Added at $geofence",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"",
"fieldConfig":{
"defaults":{
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"distance_km"
},
"properties":[
{
"id":"unit",
"value":"km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"distance_mi"
},
"properties":[
{
"id":"unit",
"value":"mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":3,
"y":4
},
"id":65,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["sum"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["sum"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH free_energy AS (\r\nSELECT sum(charge_energy_used) AS free_charged_kWh\r\nFROM charging_processes\r\nWHERE\r\n\t$__timeFilter(end_date)\r\n\tAND car_id = $car_id\r\n\tAND cost = 0),\r\nenergy as(\r\nSELECT\r\n\tsum(charge_energy_used) AS charged_kWh\r\nFROM\r\n\tcharging_processes\r\nWHERE\r\n\t$__timeFilter(end_date)\r\n\tAND car_id = $car_id\r\n)\r\nSELECT ($distance_driven * free_energy.free_charged_kWh / energy.charged_kWh) as \"distance_$length_unit\" FROM energy, free_energy",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Added free (no cost)",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"",
"fieldConfig":{
"defaults":{
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"distance_km"
},
"properties":[
{
"id":"unit",
"value":"km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"distance_mi"
},
"properties":[
{
"id":"unit",
"value":"mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":6,
"y":4
},
"id":67,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["sum"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["sum"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH suc_data AS (\r\n\tSELECT c.charging_process_id\r\n\tFROM charges c\r\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\r\n\tLEFT JOIN addresses addr ON addr.id = cp.address_id\r\n\tLEFT JOIN geofences geo ON geo.id = geofence_id\r\n\tWHERE \r\n cp.car_id = $car_id AND c.fast_charger_present\r\n\t\tAND COALESCE(geo.name, CONCAT_WS(', ', COALESCE(addr.name, nullif(CONCAT_WS(' ', addr.display_name), '')))) ILIKE '%supercharger%'\r\n AND $__timeFilter(end_date)\r\n\tGROUP BY 1\r\n), suc_energy AS (\r\n SELECT coalesce(sum(charge_energy_used), 0) AS charged_kWh\r\n FROM charging_processes cp\r\n INNER JOIN suc_data ON suc_data.charging_process_id = cp.id\r\n), energy AS(\r\n SELECT\r\n\t sum(charge_energy_used) AS charged_kWh\r\n FROM charging_processes\r\n WHERE $__timeFilter(end_date)\tAND car_id = $car_id\r\n)\r\nSELECT ($distance_driven * suc_energy.charged_kWh / energy.charged_kWh) as \"distance_$length_unit\" FROM energy, suc_energy;\r\n",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Added at SuC",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"",
"fieldConfig":{
"defaults":{
"decimals":0,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"distance_km"
},
"properties":[
{
"id":"unit",
"value":"km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"distance_mi"
},
"properties":[
{
"id":"unit",
"value":"mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":9,
"y":4
},
"id":36,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["sum"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["sum"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT $distance_driven as \"distance_$length_unit\"",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Total Driven",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"decimals":2,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"super-light-blue",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":0,
"y":7
},
"id":56,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["lastNotNull"],
"fields":"/.*/",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n $ACCost\n",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Charging Cost at AC Stations",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"decimals":2,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"super-light-blue",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":3,
"y":7
},
"id":44,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["lastNotNull"],
"fields":"/.*/",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n $DCCost\n",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Charging Cost at DC Stations",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"decimals":2,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"super-light-blue",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":6,
"y":7
},
"id":14,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["lastNotNull"],
"fields":"/.*/",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n $SucCost",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Charging Cost at SuC",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"decimals":2,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"super-light-blue",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":9,
"y":7
},
"id":27,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["lastNotNull"],
"fields":"/.*/",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n $TotalCost\n",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Total Charging Costs",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"decimals":2,
"displayName":"",
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"light-orange",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":0,
"y":10
},
"id":40,
"options":{
"colorMode":"value",
"graphMode":"none",
"justifyMode":"auto",
"orientation":"auto",
"reduceOptions":{
"calcs":["mean"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"auto",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT (\n SELECT sum(cost)\n FROM charging_processes\n WHERE $__timeFilter(end_date) AND car_id = $car_id\n) / $distance_driven * 100",
"refId":"A",
"select":[
[
{
"params":["efficiency"],
"type":"column"
}
]
],
"table":"cars",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Cost per 100 $length_unit",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"color":{
"mode":"thresholds"
},
"decimals":2,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"light-orange",
"value":null
}
]
}
},
"overrides":[]
},
"gridPos":{
"h":3,
"w":3,
"x":3,
"y":10
},
"id":42,
"options":{
"colorMode":"value",
"graphMode":"none",
"justifyMode":"auto",
"orientation":"auto",
"reduceOptions":{
"calcs":["mean"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"auto",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT (\n SELECT sum(cost)\n FROM charging_processes\n WHERE $__timeFilter(end_date) AND car_id = $car_id\n) / (\n SELECT sum(greatest(charge_energy_used, charge_energy_used))\n FROM charging_processes\n WHERE $__timeFilter(end_date) AND car_id = $car_id\n)",
"refId":"A",
"select":[
[
{
"params":["value"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Average kWh Cost",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"Net is the efficiency while driving",
"fieldConfig":{
"defaults":{
"decimals":0,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"light-orange",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"consumption_km"
},
"properties":[
{
"id":"unit",
"value":"Wh/km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"consumption_mi"
},
"properties":[
{
"id":"unit",
"value":"Wh/mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":6,
"y":10
},
"id":69,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["mean"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"select \n sum((start_[[preferred_range]]_range_km - end_[[preferred_range]]_range_km) * cars.efficiency) / sum(distance) * 1000 * \n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nfrom drives \ninner join cars on cars.id = car_id\nwhere \n distance is not null and\n start_[[preferred_range]]_range_km - end_[[preferred_range]]_range_km >= 0.1 and\n car_id = $car_id",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Consumption (net)",
"type":"stat"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"description":"Gross is all consumption (including while idle, phantom drains, sentry mode, etc)",
"fieldConfig":{
"defaults":{
"decimals":0,
"mappings":[],
"noValue":"0",
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"light-orange",
"value":null
}
]
},
"unit":"none"
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"consumption_km"
},
"properties":[
{
"id":"unit",
"value":"Wh/km"
}
]
},
{
"matcher":{
"id":"byName",
"options":"consumption_mi"
},
"properties":[
{
"id":"unit",
"value":"Wh/mi"
}
]
}
]
},
"gridPos":{
"h":3,
"w":3,
"x":9,
"y":10
},
"id":71,
"maxDataPoints":100,
"options":{
"colorMode":"value",
"fieldOptions":{
"calcs":["mean"]
},
"graphMode":"none",
"justifyMode":"auto",
"orientation":"horizontal",
"reduceOptions":{
"calcs":["mean"],
"fields":"",
"values":false
},
"showPercentChange":false,
"textMode":"value",
"wideLayout":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH d1 AS (\n\tSELECT\n\t\tc.car_id,\n\t\tlag(end_[[preferred_range]]_range_km) OVER (ORDER BY start_date) - start_[[preferred_range]]_range_km AS range_loss,\n\t\tp.odometer - lag(p.odometer) OVER (ORDER BY start_date) AS distance\n\tFROM\n\t\tcharging_processes c\n\tLEFT JOIN positions p ON p.id = c.position_id \n\tWHERE\n\t end_date IS NOT NULL AND\n\t c.car_id = $car_id\n\tORDER BY\n\t\tstart_date\n),\nd2 AS (\nSELECT\n\tcar_id,\n\tsum(range_loss) AS range_loss,\n\tsum(distance) AS distance\nFROM\n\td1\nWHERE\n\tdistance >= 0 AND range_loss >= 0\nGROUP BY\n\tcar_id\n)\nSELECT\nrange_loss * c.efficiency / distance * 1000 *\n CASE WHEN '$length_unit' = 'km' THEN 1\n WHEN '$length_unit' = 'mi' THEN 1.60934\n END AS \"consumption_$length_unit\"\nFROM\n\td2\n\tLEFT JOIN cars c ON c.id = car_id",
"refId":"A",
"select":[
[
{
"params":["latitude"],
"type":"column"
}
]
],
"table":"addresses",
"timeColumn":"inserted_at",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Consumption (gross) ",
"type":"stat"
},
{
"collapsed":false,
"gridPos":{
"h":1,
"w":24,
"x":0,
"y":13
},
"id":60,
"panels":[],
"title":"Top 10 Charges",
"type":"row"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"custom":{
"align":"auto",
"cellOptions":{
"type":"auto"
},
"inspect":false
},
"mappings":[],
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
},
{
"color":"red",
"value":80
}
]
}
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"location"
},
"properties":[
{
"id":"displayName",
"value":"Location"
}
]
},
{
"matcher":{
"id":"byName",
"options":"charge_energy_used"
},
"properties":[
{
"id":"displayName",
"value":"Charged"
},
{
"id":"custom.width",
"value":110
},
{
"id":"custom.align",
"value":"right"
}
]
},
{
"matcher":{
"id":"byName",
"options":"Cost"
},
"properties":[
{
"id":"custom.width",
"value":110
},
{
"id":"decimals",
"value":2
}
]
}
]
},
"gridPos":{
"h":12,
"w":6,
"x":0,
"y":14
},
"id":46,
"options":{
"cellHeight":"sm",
"footer":{
"countRows":false,
"fields":"",
"reducer":["sum"],
"show":false
},
"showHeader":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_used) < 1000 THEN SUM(charge_energy_used)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_used) < 1000000 THEN (SUM(charge_energy_used) / 1000)::NUMERIC(9, 3)::VARCHAR || ' MWh' \n WHEN SUM(charge_energy_used) >= 1000000 THEN (SUM(charge_energy_used) / 1000000)::NUMERIC(9, 3)::VARCHAR || ' GWh' \n END as charge_energy_used, sum(cost) as \"Cost\"\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\n\tAND charge_energy_used > 0\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_used) DESC\nLIMIT 10;",
"refId":"A",
"select":[
[
{
"params":["value"],
"type":"column"
}
]
],
"timeColumn":"time",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Top 10 General Charging Stations (Charged)",
"type":"table"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"custom":{
"align":"auto",
"cellOptions":{
"type":"auto"
},
"inspect":false
},
"mappings":[],
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
},
{
"color":"red",
"value":80
}
]
}
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"location"
},
"properties":[
{
"id":"displayName",
"value":"Location"
}
]
},
{
"matcher":{
"id":"byName",
"options":"charge_energy_used"
},
"properties":[
{
"id":"displayName",
"value":"Charged"
},
{
"id":"custom.width",
"value":110
},
{
"id":"custom.align",
"value":"right"
}
]
},
{
"matcher":{
"id":"byName",
"options":"Cost"
},
"properties":[
{
"id":"custom.width",
"value":110
},
{
"id":"decimals",
"value":2
}
]
}
]
},
"gridPos":{
"h":12,
"w":6,
"x":6,
"y":14
},
"id":4,
"options":{
"cellHeight":"sm",
"footer":{
"countRows":false,
"fields":"",
"reducer":["sum"],
"show":false
},
"showHeader":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_used) < 1000 THEN SUM(charge_energy_used)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_used) < 1000000 THEN (SUM(charge_energy_used) / 1000)::NUMERIC(9, 3)::VARCHAR || ' MWh' \n WHEN SUM(charge_energy_used) >= 1000000 THEN (SUM(charge_energy_used) / 1000000)::NUMERIC(9, 3)::VARCHAR || ' GWh' \n END as charge_energy_used, sum(cost) as \"Cost\"\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\n\tAND cost > 0\n\tAND charge_energy_used > 0\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_used) DESC\nLIMIT 10;",
"refId":"A",
"select":[
[
{
"params":["value"],
"type":"column"
}
]
],
"timeColumn":"time",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Top 10 Paid Stations (Charged)",
"type":"table"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"custom":{
"align":"auto",
"cellOptions":{
"type":"auto"
},
"inspect":false
},
"mappings":[],
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
},
{
"color":"red",
"value":80
}
]
}
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"location"
},
"properties":[
{
"id":"displayName",
"value":"Location"
}
]
},
{
"matcher":{
"id":"byName",
"options":"charge_energy_used"
},
"properties":[
{
"id":"displayName",
"value":"Charged"
},
{
"id":"custom.width",
"value":110
},
{
"id":"custom.align",
"value":"right"
}
]
},
{
"matcher":{
"id":"byName",
"options":"Cost"
},
"properties":[
{
"id":"custom.width",
"value":110
},
{
"id":"decimals",
"value":2
}
]
}
]
},
"gridPos":{
"h":12,
"w":6,
"x":12,
"y":14
},
"id":34,
"options":{
"cellHeight":"sm",
"footer":{
"countRows":false,
"fields":"",
"reducer":["sum"],
"show":false
},
"showHeader":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_used) < 1000 THEN SUM(charge_energy_used)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_used) < 1000000 THEN (SUM(charge_energy_used) / 1000)::NUMERIC(9, 3)::VARCHAR || ' MWh' \n WHEN SUM(charge_energy_used) >= 1000000 THEN (SUM(charge_energy_used) / 1000000)::NUMERIC(9, 3)::VARCHAR || ' GWh' \n END as charge_energy_used, sum(cost) as \"Cost\"\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\n\tAND charge_energy_used > 0\n\tAND COALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.display_name), '')))) ILIKE '%supercharger%'\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_used) DESC\nLIMIT 10;",
"refId":"A",
"select":[
[
{
"params":["value"],
"type":"column"
}
]
],
"timeColumn":"time",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
}
],
"title":"Top 10 SuperCharger Stations (Charged)",
"type":"table"
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"fieldConfig":{
"defaults":{
"custom":{
"align":"auto",
"cellOptions":{
"type":"auto"
},
"inspect":false
},
"mappings":[],
"thresholds":{
"mode":"absolute",
"steps":[
{
"color":"green",
"value":null
},
{
"color":"red",
"value":80
}
]
}
},
"overrides":[
{
"matcher":{
"id":"byName",
"options":"location"
},
"properties":[
{
"id":"displayName",
"value":"Location"
}
]
},
{
"matcher":{
"id":"byName",
"options":"charge_energy_used"
},
"properties":[
{
"id":"displayName",
"value":"Charged"
},
{
"id":"custom.width",
"value":120
},
{
"id":"custom.align",
"value":"right"
}
]
},
{
"matcher":{
"id":"byName",
"options":"Cost"
},
"properties":[
{
"id":"custom.width",
"value":110
},
{
"id":"decimals",
"value":2
}
]
}
]
},
"gridPos":{
"h":12,
"w":6,
"x":18,
"y":14
},
"id":32,
"options":{
"cellHeight":"sm",
"footer":{
"countRows":false,
"fields":"",
"reducer":["sum"],
"show":false
},
"showHeader":true
},
"pluginVersion":"10.4.0",
"targets":[
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"metricColumn":"none",
"rawQuery":true,
"rawSql":"SELECT\n\tCOALESCE(geofence.name, CONCAT_WS(', ', COALESCE(address.name, nullif(CONCAT_WS(' ', address.road, address.house_number), '')), address.city)) AS location,\n\tCASE\n WHEN SUM(charge_energy_used) < 1000 THEN SUM(charge_energy_used)::NUMERIC(4,0)::VARCHAR || ' kWh' \n WHEN SUM(charge_energy_used) < 1000000 THEN (SUM(charge_energy_used) / 1000)::NUMERIC(9, 3)::VARCHAR || ' MWh' \n WHEN SUM(charge_energy_used) >= 1000000 THEN (SUM(charge_energy_used) / 1000000)::NUMERIC(9, 3)::VARCHAR || ' GWh' \n END as charge_energy_used, sum(cost) as \"Cost\"\nFROM\n\tcharging_processes c\nLEFT JOIN addresses address ON c.address_id = address.id\nLEFT JOIN geofences geofence ON geofence_id = geofence.id\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\n\tAND charge_energy_used > 0\n\tAND cost = 0\nGROUP BY\n\t1\nORDER BY\n\tSUM(charge_energy_used) DESC\nLIMIT 10;",
"rawSql":"WITH data AS (\nSELECT\n duration_min > 1 AND\n distance > 1 AND\n ( \n start_position.usable_battery_level IS NULL OR\n (end_position.battery_level - end_position.usable_battery_level) = 0 \n ) AS is_sufficiently_precise,\n NULLIF(GREATEST(start_ideal_range_km - end_ideal_range_km, 0), 0) AS range_diff,\n date_trunc('month', (start_date::TIMESTAMP WITHOUT TIME ZONE) AT TIME ZONE '$timezone') as local_period,\n drives.*\nFROM drives\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)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n convert_km(max(end_km)::integer - min(start_km)::integer, '$length_unit') AS sum_distance_$length_unit,\n convert_celsius(avg(outside_temp_avg), '$temp_unit') AS avg_outside_temp_$temp_unit,\n sum(distance)/sum(range_diff) AS efficiency\nFROM data WHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date DESC",
"refId":"A",
"select":[
[
{
"params":["start_km"],
"type":"column"
}
]
],
"table":"drives",
"timeColumn":"start_date",
"timeColumnType":"timestamp",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"hide":false,
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH data AS (\n SELECT\n charging_processes.*,\n date_trunc('month', (start_date::TIMESTAMP WITHOUT TIME ZONE) AT TIME ZONE '$timezone') as local_period\n FROM charging_processes)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(greatest(charge_energy_used,charge_energy_used)) AS sum_consumption_kwh,\n sum(greatest(charge_energy_used,charge_energy_used)) / count(*) AS avg_consumption_kwh,\n sum(cost) AS cost_charges,\n count(*) AS cnt_charges\nFROM data WHERE\n car_id = $car_id AND\n (charge_energy_used IS NULL OR charge_energy_used > 0.1)\nGROUP BY date\nORDER BY date",
"refId":"B",
"select":[
[
{
"params":["value"],
"type":"column"
}
]
],
"timeColumn":"time",
"where":[
{
"name":"$__timeFilter",
"params":[],
"type":"macro"
}
]
},
{
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"format":"table",
"group":[],
"hide":false,
"metricColumn":"none",
"rawQuery":true,
"rawSql":"WITH data AS (\n SELECT\n drives.*,\n date_trunc('month', (start_date::TIMESTAMP WITHOUT TIME ZONE) AT TIME ZONE '$timezone') as local_period\n FROM drives)\nSELECT\n EXTRACT(EPOCH FROM date_trunc('month', local_period))*1000 AS date_from,\n EXTRACT(EPOCH FROM date_trunc('month', local_period + ('1 ' || 'month')::INTERVAL))*1000 AS date_to,\n CASE 'month'\n WHEN 'month' THEN to_char(local_period, 'YYYY Month')\n WHEN 'year' THEN to_char(local_period, 'YYYY')\n WHEN 'week' THEN 'week ' || to_char(local_period, 'WW') || ' starting ' || to_char(local_period, 'YYYY-MM-DD')\n ELSE to_char(local_period, 'YYYY-MM-DD')\n END AS display,\n local_period AS date,\n sum(GREATEST(start_[[preferred_range]]_range_km - end_[[preferred_range]]_range_km, 0) * car.efficiency * 1000) / \n convert_km(sum(distance)::numeric, '$length_unit') as efficiency_net_$length_unit\nFROM data\nJOIN cars car ON car.id = car_id\nWHERE\n car_id = $car_id\nGROUP BY date\nORDER BY date",
"definition":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tLEFT JOIN addresses addr ON addr.id = cp.address_id\n\tLEFT JOIN geofences geo ON geo.id = geofence_id\n\tWHERE \n\t cp.car_id = $car_id AND c.fast_charger_present\n\t\tAND COALESCE(geo.name, CONCAT_WS(', ', COALESCE(addr.name, nullif(CONCAT_WS(' ', addr.display_name), '')))) ILIKE '%supercharger%'\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost), 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);",
"hide":2,
"includeAll":false,
"multi":false,
"name":"SucCost",
"options":[],
"query":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tLEFT JOIN addresses addr ON addr.id = cp.address_id\n\tLEFT JOIN geofences geo ON geo.id = geofence_id\n\tWHERE \n\t cp.car_id = $car_id AND c.fast_charger_present\n\t\tAND COALESCE(geo.name, CONCAT_WS(', ', COALESCE(addr.name, nullif(CONCAT_WS(' ', addr.display_name), '')))) ILIKE '%supercharger%'\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost), 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);",
"refresh":2,
"regex":"",
"skipUrlSync":false,
"sort":0,
"type":"query"
},
{
"current":{},
"datasource":{
"type":"grafana-postgresql-datasource",
"uid":"TeslaMate"
},
"definition":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n cp.car_id = $car_id AND c.fast_charger_present\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) - $SucCost , 0)\t\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);",
"hide":2,
"includeAll":false,
"multi":false,
"name":"DCCost",
"options":[],
"query":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n cp.car_id = $car_id AND c.fast_charger_present\n\tGROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) - $SucCost , 0)\t\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.id IN (data.charging_process_id);",
"definition":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n\t\tcp.car_id = $car_id AND c.charger_voltage != 2\n AND c.fast_charger_present IS NOT true\n GROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) , 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.cost IS NOT NULL\n AND cp.id IN (data.charging_process_id);",
"query":"WITH data AS (\n\tSELECT c.charging_process_id \n\tFROM charges c\n\tLEFT JOIN charging_processes cp ON cp.id = c.charging_process_id\n\tWHERE \n\t\tcp.car_id = $car_id AND c.charger_voltage != 2\n AND c.fast_charger_present IS NOT true\n GROUP BY 1\n)\nSELECT\n coalesce(sum(cp.cost) , 0)\nFROM\n\tcharging_processes cp, data\nWHERE\n $__timeFilter(end_date)\n AND cp.cost IS NOT NULL\n AND cp.id IN (data.charging_process_id);",
"definition":"select current_setting('TIMEZONE'), name from pg_timezone_names where abbrev ~ '^[a-zA-Z]{3,4}$' and name not like 'posix%' order by 2;",
"hide":2,
"includeAll":false,
"multi":false,
"name":"timezone",
"options":[],
"query":"select current_setting('TIMEZONE'), name from pg_timezone_names where abbrev ~ '^[a-zA-Z]{3,4}$' and name not like 'posix%' order by 2;",
"definition":"SELECT ROUND(convert_km((max(end_km) - min(start_km))::numeric, '$length_unit'),0) as \"Mileage\"\nFROM drives WHERE car_id = $car_id AND $__timeFilter(end_date)",
"query":"SELECT ROUND(convert_km((max(end_km) - min(start_km))::numeric, '$length_unit'),0) as \"Mileage\"\nFROM drives WHERE car_id = $car_id AND $__timeFilter(end_date)",