{
    "__elements": {},
    "__requires": [
        {
            "type": "panel",
            "id": "bargauge",
            "name": "Bar gauge",
            "version": ""
        },
        {
            "type": "grafana",
            "id": "grafana",
            "name": "Grafana",
            "version": "10.4.0"
        },
        {
            "type": "datasource",
            "id": "grafana-postgresql-datasource",
            "name": "PostgreSQL",
            "version": "1.0.0"
        },
        {
            "type": "panel",
            "id": "piechart",
            "name": "Pie chart",
            "version": ""
        },
        {
            "type": "panel",
            "id": "stat",
            "name": "Stat",
            "version": ""
        },
        {
            "type": "panel",
            "id": "table",
            "name": "Table",
            "version": ""
        }
    ],
    "annotations": {
        "list": [
            {
                "$$hashKey": "object:75",
                "builtIn": 1,
                "datasource": "-- Grafana --",
                "definition": "TeslaMate|U2FsdGVkX1/cEWK+8cz7pjEKXtzJnDN7b21ZDXt1MGneFGPWTLqOPtxKmu02mJPLzi/f29I+NBHd3vi0FB8R4Xn0+GtobWDgk6VAVSBTdSNniOKO8i2WPlhRaOsl2+hG7gnZ7wrf1Th2nxR7f1uYCrbwOek0IzkfLzrkjh7gkr6inT6bbDuJqrmogZajLxmAMrQ6V+/vHxBRGiwjJhgiEeq3hM1q2h04JKkNiZ8RHbsF5Cd/xd8Q9u0JVrZzIrtnhM/SFlaApU7RtRMu8CSj1llTX7WEOj6VDZAMSf+XUAanWdk725kEPN9MNu89o2zEq5P3E3cju8IbbBdPzXLV3oVuzD6/tMnxFToIIV1E/BrpF7s2RtNa8+KJJ1PF8xgs6m+/KTD2hy+WsP0636AgObRAmYg7+qotGrgNvpNPdE0EgrB7WHYlV7R/1q66bcq6tCe51X1Un70k+zo+K6AK0o4B1H6IyMlEVuRH/Fz8QVl9aYu2ztd08RbuKJlYVKpkH+pxVETAO9MclYQ90tzE6TfwDZrQZzsAlMenr4s1ZB1OlFXjLjVjnddnUilzO76cqv4yI2THQEuyQ47nuVQ4gUbx02K59vMQhns3C01JOAYokOaSXe66Y7QYdMlk09Lf|aes-256-cbc",
                "enable": true,
                "hide": true,
                "iconColor": "rgba(0, 211, 255, 1)",
                "name": "Annotations & Alerts",
                "target": {
                    "limit": 100,
                    "matchAny": false,
                    "tags": [],
                    "type": "dashboard"
                },
                "type": "dashboard"
            }
        ]
    },
    "editable": true,
    "fiscalYearStartMonth": 0,
    "graphTooltip": 1,
    "id": null,
    "links": [
        {
            "icon": "dashboard",
            "tags": [],
            "title": "TeslaMate",
            "tooltip": "",
            "type": "link",
            "url": "[[base_url:raw]]"
        },
        {
            "asDropdown": true,
            "icon": "external link",
            "tags": ["tesla"],
            "title": "Dashboards",
            "type": "dashboards"
        },
        {
            "asDropdown": true,
            "icon": "external link",
            "includeVars": false,
            "keepTime": false,
            "tags": ["TeslamateCustomDashboards"],
            "targetBlank": false,
            "title": "Custom Dashboards",
            "tooltip": "",
            "type": "dashboards",
            "url": ""
        }
    ],
    "liveNow": false,
    "panels": [
        {
            "collapsed": false,
            "datasource": "TeslaMate",
            "gridPos": {
                "h": 1,
                "w": 24,
                "x": 0,
                "y": 0
            },
            "id": 12,
            "panels": [],
            "title": "Summary",
            "type": "row"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "noValue": "0",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "light-yellow",
                                "value": null
                            }
                        ]
                    },
                    "unit": "kwatth"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 3,
                "w": 3,
                "x": 0,
                "y": 1
            },
            "id": 10,
            "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\tsum(charge_energy_used)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id;\n",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["efficiency"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "cars",
                    "timeColumn": "inserted_at",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Total Energy Used",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "noValue": "0",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "light-yellow",
                                "value": null
                            }
                        ]
                    },
                    "unit": "kwatth"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 3,
                "w": 3,
                "x": 3,
                "y": 1
            },
            "id": 33,
            "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\tsum(charge_energy_used)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id\n\tAND cost = 0;\n",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["efficiency"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "cars",
                    "timeColumn": "inserted_at",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Total Free Energy",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "noValue": "0",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "light-yellow",
                                "value": null
                            }
                        ]
                    },
                    "unit": "kwatth"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 3,
                "w": 3,
                "x": 6,
                "y": 1
            },
            "id": 64,
            "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 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",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["efficiency"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "cars",
                    "timeColumn": "inserted_at",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "kWh per $length_unit",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "noValue": "0",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "light-yellow",
                                "value": null
                            }
                        ]
                    },
                    "unit": "times"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 3,
                "w": 3,
                "x": 9,
                "y": 1
            },
            "id": 38,
            "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\tcount(*)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND charge_energy_used > 0.01\n\tAND car_id = $car_id;",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["efficiency"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "cars",
                    "timeColumn": "inserted_at",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Number of Charges",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "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;",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Top 10 Free Stations (Charged)",
            "type": "table"
        },
        {
            "collapsed": false,
            "gridPos": {
                "h": 1,
                "w": 24,
                "x": 0,
                "y": 26
            },
            "id": 62,
            "panels": [],
            "title": "Monthly Stats",
            "type": "row"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "description": "",
            "fieldConfig": {
                "defaults": {
                    "custom": {
                        "align": "left",
                        "cellOptions": {
                            "type": "auto"
                        },
                        "filterable": false,
                        "inspect": false,
                        "width": 120
                    },
                    "mappings": [],
                    "noValue": "--",
                    "thresholds": {
                        "mode": "percentage",
                        "steps": [
                            {
                                "color": "red",
                                "value": null
                            },
                            {
                                "color": "#EAB839",
                                "value": 50
                            },
                            {
                                "color": "green",
                                "value": 90
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Time driven"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "clocks"
                            },
                            {
                                "id": "decimals",
                                "value": 1
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Period"
                        },
                        "properties": [
                            {
                                "id": "links",
                                "value": [
                                    {
                                        "targetBlank": true,
                                        "title": "Trip",
                                        "url": "d/FkUpJpQZk/trip?from=${__data.fields.date_from}&to=${__data.fields.date_to}&var-car_id=$car_id"
                                    }
                                ]
                            },
                            {
                                "id": "custom.width"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Efficiency"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "percentunit"
                            },
                            {
                                "id": "custom.cellOptions",
                                "value": {
                                    "type": "color-text"
                                }
                            },
                            {
                                "id": "thresholds",
                                "value": {
                                    "mode": "percentage",
                                    "steps": [
                                        {
                                            "color": "super-light-orange",
                                            "value": null
                                        },
                                        {
                                            "color": "light-orange",
                                            "value": 65
                                        },
                                        {
                                            "color": "light-green",
                                            "value": 99
                                        }
                                    ]
                                }
                            },
                            {
                                "id": "custom.align",
                                "value": "auto"
                            },
                            {
                                "id": "decimals",
                                "value": 1
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Energy used"
                        },
                        "properties": [
                            {
                                "id": "decimals",
                                "value": 1
                            },
                            {
                                "id": "links",
                                "value": [
                                    {
                                        "targetBlank": true,
                                        "title": "Charging stats",
                                        "url": "d/-pkIkhmRz/charging-stats?from=${__data.fields.date_from}&to=${__data.fields.date_to}&var-car_id=$car_id"
                                    }
                                ]
                            },
                            {
                                "id": "unit",
                                "value": "kwatth"
                            },
                            {
                                "id": "custom.align",
                                "value": "auto"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Avg charged"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "kwatth"
                            },
                            {
                                "id": "decimals",
                                "value": 1
                            },
                            {
                                "id": "custom.align",
                                "value": "auto"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Costs"
                        },
                        "properties": [
                            {
                                "id": "decimals",
                                "value": 2
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "# charges"
                        },
                        "properties": [
                            {
                                "id": "links",
                                "value": [
                                    {
                                        "targetBlank": true,
                                        "title": "Charges",
                                        "url": "d/TSmNYvRRk/charges?from=${__data.fields.date_from}&to=${__data.fields.date_to}&var-car_id=$car_id"
                                    }
                                ]
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "# drives"
                        },
                        "properties": [
                            {
                                "id": "links",
                                "value": [
                                    {
                                        "targetBlank": true,
                                        "title": "Drives",
                                        "url": "d/Y8upc6ZRk/drives?from=${__data.fields.date_from}&to=${__data.fields.date_to}&var-car_id=$car_id"
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/sum_distance_km/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "km"
                            },
                            {
                                "id": "displayName",
                                "value": "Distance"
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            },
                            {
                                "id": "custom.cellOptions",
                                "value": {
                                    "mode": "basic",
                                    "type": "gauge"
                                }
                            },
                            {
                                "id": "color",
                                "value": {
                                    "mode": "continuous-GrYlRd"
                                }
                            },
                            {
                                "id": "max",
                                "value": 8000
                            },
                            {
                                "id": "custom.width"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/avg_outside_temp_c/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "celsius"
                            },
                            {
                                "id": "displayName",
                                "value": "Temperature"
                            },
                            {
                                "id": "custom.cellOptions",
                                "value": {
                                    "type": "color-text"
                                }
                            },
                            {
                                "id": "thresholds",
                                "value": {
                                    "mode": "absolute",
                                    "steps": [
                                        {
                                            "color": "super-light-blue",
                                            "value": null
                                        },
                                        {
                                            "color": "super-light-green",
                                            "value": 10
                                        },
                                        {
                                            "color": "super-light-red",
                                            "value": 20
                                        }
                                    ]
                                }
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/sum_distance_mi/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "mi"
                            },
                            {
                                "id": "displayName",
                                "value": "Distance"
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            },
                            {
                                "id": "custom.cellOptions",
                                "value": {
                                    "mode": "basic",
                                    "type": "gauge"
                                }
                            },
                            {
                                "id": "color",
                                "value": {
                                    "mode": "continuous-GrYlRd"
                                }
                            },
                            {
                                "id": "max",
                                "value": 8000
                            },
                            {
                                "id": "custom.width"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/efficiency_net_mi/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Avg consumption (drives)"
                            },
                            {
                                "id": "unit",
                                "value": "Wh/mi"
                            },
                            {
                                "id": "custom.width",
                                "value": 200
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/efficiency_charged_net_mi/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Avg consumption (charges)"
                            },
                            {
                                "id": "unit",
                                "value": "Wh/mi"
                            },
                            {
                                "id": "custom.width",
                                "value": 203
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/.* at/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "dateTimeAsSystem"
                            },
                            {
                                "id": "custom.width"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/efficiency_net_km/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Avg consumption (drives)"
                            },
                            {
                                "id": "unit",
                                "value": "Wh/km"
                            },
                            {
                                "id": "custom.width",
                                "value": 200
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/efficiency_charged_net_km/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Avg consumption (charges)"
                            },
                            {
                                "id": "unit",
                                "value": "Wh/km"
                            },
                            {
                                "id": "custom.width",
                                "value": 203
                            },
                            {
                                "id": "noValue",
                                "value": "--"
                            },
                            {
                                "id": "mappings",
                                "value": [
                                    {
                                        "options": {
                                            "NaN": {
                                                "index": 0,
                                                "text": "--"
                                            }
                                        },
                                        "type": "value"
                                    }
                                ]
                            },
                            {
                                "id": "custom.align",
                                "value": "center"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/avg_outside_temp_f/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "fahrenheit"
                            },
                            {
                                "id": "displayName",
                                "value": "Temperature"
                            },
                            {
                                "id": "custom.cellOptions",
                                "value": {
                                    "type": "color-text"
                                }
                            },
                            {
                                "id": "thresholds",
                                "value": {
                                    "mode": "absolute",
                                    "steps": [
                                        {
                                            "color": "super-light-blue",
                                            "value": null
                                        },
                                        {
                                            "color": "super-light-green",
                                            "value": 50
                                        },
                                        {
                                            "color": "super-light-red",
                                            "value": 68
                                        }
                                    ]
                                }
                            },
                            {
                                "id": "custom.align",
                                "value": "auto"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "date_from"
                        },
                        "properties": [
                            {
                                "id": "custom.hidden",
                                "value": true
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "date_to"
                        },
                        "properties": [
                            {
                                "id": "custom.hidden",
                                "value": true
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 15,
                "w": 24,
                "x": 0,
                "y": 27
            },
            "id": 58,
            "maxPerRow": 2,
            "options": {
                "cellHeight": "sm",
                "footer": {
                    "countRows": false,
                    "enablePagination": true,
                    "fields": "",
                    "reducer": ["sum"],
                    "show": false
                },
                "frameIndex": 1,
                "showHeader": true,
                "sortBy": []
            },
            "pluginVersion": "10.4.0",
            "repeatDirection": "h",
            "targets": [
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "format": "table",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "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",
                    "refId": "C",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Stats per month",
            "transformations": [
                {
                    "id": "merge",
                    "options": {}
                },
                {
                    "id": "seriesToColumns",
                    "options": {
                        "byField": "date"
                    }
                },
                {
                    "id": "calculateField",
                    "options": {
                        "alias": "efficiency_charged_net_km_temp",
                        "binary": {
                            "left": "sum_consumption_kwh",
                            "operator": "/",
                            "reducer": "sum",
                            "right": "sum_distance_km"
                        },
                        "mode": "binary",
                        "reduce": {
                            "reducer": "sum"
                        },
                        "replaceFields": false
                    }
                },
                {
                    "id": "calculateField",
                    "options": {
                        "alias": "efficiency_charged_net_km",
                        "binary": {
                            "left": "efficiency_charged_net_km_temp",
                            "operator": "*",
                            "reducer": "sum",
                            "right": "1000"
                        },
                        "mode": "binary",
                        "reduce": {
                            "reducer": "sum"
                        }
                    }
                },
                {
                    "id": "calculateField",
                    "options": {
                        "alias": "efficiency_charged_net_mi_temp",
                        "binary": {
                            "left": "sum_consumption_kwh",
                            "operator": "/",
                            "reducer": "sum",
                            "right": "sum_distance_mi"
                        },
                        "mode": "binary",
                        "reduce": {
                            "reducer": "sum"
                        },
                        "replaceFields": false
                    }
                },
                {
                    "id": "calculateField",
                    "options": {
                        "alias": "efficiency_charged_net_mi",
                        "binary": {
                            "left": "efficiency_charged_net_mi_temp",
                            "operator": "*",
                            "reducer": "sum",
                            "right": "1000"
                        },
                        "mode": "binary",
                        "reduce": {
                            "reducer": "sum"
                        }
                    }
                },
                {
                    "id": "organize",
                    "options": {
                        "excludeByName": {
                            "date": true,
                            "date_from": false,
                            "date_to": false,
                            "efficiency_charged_net_km_temp": true,
                            "efficiency_charged_net_mi_temp": true,
                            "timezone": true
                        },
                        "indexByName": {
                            "avg_consumption_kwh": 8,
                            "avg_outside_temp_c": 3,
                            "avg_outside_temp_f": 3,
                            "cnt_charges": 7,
                            "cost_charges": 5,
                            "date": 1,
                            "date_from": 11,
                            "date_to": 12,
                            "display": 0,
                            "efficiency": 4,
                            "efficiency_charged_net_km": 10,
                            "efficiency_charged_net_km_temp": 13,
                            "efficiency_net_km": 9,
                            "sum_consumption_kwh": 6,
                            "sum_distance_km": 2,
                            "sum_distance_mi": 2
                        },
                        "renameByName": {
                            "avg_consumption_kwh": "Avg charged",
                            "avg_outside_temp_c": "",
                            "cnt": "# drives",
                            "cnt_charges": "# charges",
                            "cost_charges": "Costs",
                            "date": "Starting at",
                            "date_from": "",
                            "date_to": "",
                            "display": "Period",
                            "efficiency": "Efficiency",
                            "efficiency_net_km": "",
                            "sum_consumption_kwh": "Energy used",
                            "sum_distance_km": "",
                            "sum_duration_h": "Time driven"
                        }
                    }
                }
            ],
            "type": "table"
        }
    ],
    "refresh": "",
    "schemaVersion": 39,
    "tags": ["TeslamateCustomDashboards"],
    "templating": {
        "list": [
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;",
                "hide": 0,
                "includeAll": false,
                "label": "Car",
                "multi": false,
                "name": "car_id",
                "options": [],
                "query": "SELECT name AS __text, id AS __value FROM cars ORDER BY display_priority ASC, name ASC;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "select base_url from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "",
                "multi": false,
                "name": "base_url",
                "options": [],
                "query": "select base_url from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "select unit_of_length from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "length_unit",
                "options": [],
                "query": "select unit_of_length from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "tagValuesQuery": "",
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT\n\tcoalesce(sum(cost), 0)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id;\n\t",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "TotalCost",
                "options": [],
                "query": "SELECT\n\tcoalesce(sum(cost), 0)\nFROM\n\tcharging_processes\nWHERE\n\t$__timeFilter(end_date)\n\tAND car_id = $car_id;\n\t",
                "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\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);",
                "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\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);",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "ACCost",
                "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\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);",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "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;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "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)",
                "error": {},
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "distance_driven",
                "options": [],
                "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)",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "select unit_of_temperature from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "temp_unit",
                "options": [],
                "query": "select unit_of_temperature from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "select preferred_range from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "preferred_range",
                "options": [],
                "query": "select preferred_range from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT name FROM geofences ORDER BY id",
                "description": "Geofence to display energy added at",
                "hide": 0,
                "includeAll": false,
                "label": "Geofence",
                "multi": false,
                "name": "geofence",
                "options": [],
                "query": "SELECT name FROM geofences ORDER BY id",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            }
        ]
    },
    "time": {
        "from": "now-10y",
        "to": "now"
    },
    "timepicker": {
        "hidden": false,
        "refresh_intervals": [],
        "time_options": [
            "5m",
            "15m",
            "1h",
            "6h",
            "12h",
            "24h",
            "2d",
            "7d",
            "30d"
        ]
    },
    "timezone": "",
    "title": "Charging Costs Stats",
    "uid": "jchmDdLe5uFVk",
    "version": 18,
    "weekStart": ""
}
