{
    "__elements": {},
    "__requires": [
        {
            "type": "panel",
            "id": "bargauge",
            "name": "Bar gauge",
            "version": ""
        },
        {
            "type": "panel",
            "id": "geomap",
            "name": "Geomap",
            "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": "stat",
            "name": "Stat",
            "version": ""
        },
        {
            "type": "panel",
            "id": "timeseries",
            "name": "Time series",
            "version": ""
        }
    ],
    "annotations": {
        "list": [
            {
                "$$hashKey": "object:286",
                "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"
            }
        ]
    },
    "description": "A high level overview of your car",
    "editable": true,
    "fiscalYearStartMonth": 0,
    "graphTooltip": 1,
    "links": [
        {
            "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": ""
        },
        {
            "asDropdown": false,
            "icon": "info",
            "includeVars": false,
            "keepTime": false,
            "tags": [],
            "targetBlank": false,
            "title": "Current Drive",
            "tooltip": "Adjust to current drive",
            "type": "link",
            "url": "d/jchmkOuP_Fggz/current-drive-view?kiosk&var-car_id=${car_id}&from=${current_drive_start_time}&to=${current_drive_end_time}&var-current_drive=${current_drive}&var-BatteryCapacity=${BatteryCapacity}&var-efficiency=${efficiency}&var-preferred_range=${preferred_range}&var-length_unit=${length_unit}&var-temp_unit=${temp_unit}&var-alternative_length_unit=${alternative_length_unit}"
        }
    ],
    "liveNow": false,
    "panels": [
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "description": "This is a special dashboard to load while driving. When you open this dashboard it will show the last 15 minutes, but you should click the \"Current Drive\" button at the top right corner, to enter in Kiosk mode:\n\n - If you are driving, you will see the information from the start time of the current drive until now and it will refesh automatically every 30 seconds.\n\n - If you are just browsing (not driving) you will see the information of the last drive.",
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "fixed"
                    },
                    "custom": {
                        "axisBorderShow": false,
                        "axisCenteredZero": true,
                        "axisColorMode": "text",
                        "axisLabel": "",
                        "axisPlacement": "auto",
                        "barAlignment": 0,
                        "drawStyle": "line",
                        "fillOpacity": 5,
                        "gradientMode": "hue",
                        "hideFrom": {
                            "legend": false,
                            "tooltip": false,
                            "viz": false
                        },
                        "insertNulls": false,
                        "lineInterpolation": "smooth",
                        "lineStyle": {
                            "fill": "solid"
                        },
                        "lineWidth": 1,
                        "pointSize": 5,
                        "scaleDistribution": {
                            "type": "linear"
                        },
                        "showPoints": "never",
                        "spanNulls": true,
                        "stacking": {
                            "group": "A",
                            "mode": "normal"
                        },
                        "thresholdsStyle": {
                            "mode": "line"
                        }
                    },
                    "links": [],
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "transparent",
                                "value": null
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "Battery heater"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "bool_on_off"
                            },
                            {
                                "id": "custom.axisPlacement",
                                "value": "hidden"
                            },
                            {
                                "id": "color",
                                "value": {
                                    "fixedColor": "semi-dark-red",
                                    "mode": "fixed"
                                }
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "power"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Power"
                            },
                            {
                                "id": "color",
                                "value": {
                                    "fixedColor": "dark-orange",
                                    "mode": "fixed",
                                    "seriesBy": "last"
                                }
                            },
                            {
                                "id": "unit",
                                "value": "kwatt"
                            },
                            {
                                "id": "thresholds",
                                "value": {
                                    "mode": "absolute",
                                    "steps": [
                                        {
                                            "color": "transparent",
                                            "value": null
                                        },
                                        {
                                            "color": "dark-green",
                                            "value": 0
                                        }
                                    ]
                                }
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "elevation_m"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Elevation"
                            },
                            {
                                "id": "unit",
                                "value": "lengthm"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "speed_kmh"
                        },
                        "properties": [
                            {
                                "id": "color",
                                "value": {
                                    "fixedColor": "light-blue",
                                    "mode": "fixed"
                                }
                            },
                            {
                                "id": "unit",
                                "value": "velocitykmh"
                            },
                            {
                                "id": "displayName",
                                "value": "Speed"
                            },
                            {
                                "id": "custom.axisPlacement",
                                "value": "hidden"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "speed_mih"
                        },
                        "properties": [
                            {
                                "id": "color",
                                "value": {
                                    "fixedColor": "light-blue",
                                    "mode": "fixed"
                                }
                            },
                            {
                                "id": "unit",
                                "value": "velocitymih"
                            },
                            {
                                "id": "displayName",
                                "value": "Speed"
                            },
                            {
                                "id": "custom.axisPlacement",
                                "value": "hidden"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "elevation_ft"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "lengthft"
                            },
                            {
                                "id": "displayName",
                                "value": "Elevation"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 11,
                "w": 16,
                "x": 0,
                "y": 0
            },
            "id": 26,
            "options": {
                "legend": {
                    "calcs": [],
                    "displayMode": "list",
                    "placement": "bottom",
                    "showLegend": true
                },
                "tooltip": {
                    "mode": "multi",
                    "sort": "none"
                }
            },
            "pluginVersion": "8.5.4",
            "targets": [
                {
                    "alias": "",
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT\n\t$__time(date),\n\tavg(power) AS Power,\n\tavg(battery_heater::integer) AS \"Battery heater\",\n\tavg(convert_km(speed::numeric, '$length_unit')) AS speed_[[length_unit]]h\nFROM\n\tpositions\nWHERE\n car_id = $car_id AND\n $__timeFilter(date)\nGROUP BY 1  \nORDER BY\n\tdate ASC",
                    "refId": "Power",
                    "select": [
                        [
                            {
                                "params": ["id"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "table": "charging",
                    "timeColumn": "Datum",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                },
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "format": "time_series",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT\n\t$__time(date),\n\tAVG(ROUND(convert_m(elevation, '$alternative_length_unit'))) AS elevation_[[alternative_length_unit]]\nFROM\n\tpositions\nWHERE\n car_id = $car_id AND\n $__timeFilter(date)\nGROUP BY 1 \nORDER BY\n\tdate ASC",
                    "refId": "Elevation",
                    "select": [
                        [
                            {
                                "params": ["start_km"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "drives",
                    "timeColumn": "start_date",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Drive",
            "type": "timeseries"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "fixedColor": "red",
                        "mode": "thresholds"
                    },
                    "custom": {
                        "hideFrom": {
                            "legend": false,
                            "tooltip": false,
                            "viz": false
                        }
                    },
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            }
                        ]
                    }
                },
                "overrides": []
            },
            "gridPos": {
                "h": 21,
                "w": 8,
                "x": 16,
                "y": 0
            },
            "id": 33,
            "maxDataPoints": 50000,
            "options": {
                "basemap": {
                    "config": {},
                    "name": "Layer 0",
                    "type": "osm-standard"
                },
                "controls": {
                    "mouseWheelZoom": true,
                    "showAttribution": true,
                    "showDebug": false,
                    "showMeasure": false,
                    "showScale": false,
                    "showZoom": true
                },
                "layers": [
                    {
                        "config": {
                            "arrow": 0,
                            "style": {
                                "color": {
                                    "fixed": "dark-blue"
                                },
                                "lineWidth": 2,
                                "opacity": 1,
                                "rotation": {
                                    "fixed": 0,
                                    "max": 360,
                                    "min": -360,
                                    "mode": "mod"
                                },
                                "size": {
                                    "fixed": 3,
                                    "max": 15,
                                    "min": 2
                                },
                                "symbol": {
                                    "field": "",
                                    "fixed": "",
                                    "mode": "fixed"
                                },
                                "symbolAlign": {
                                    "horizontal": "center",
                                    "vertical": "center"
                                },
                                "textConfig": {
                                    "fontSize": 12,
                                    "offsetX": 0,
                                    "offsetY": 0,
                                    "textAlign": "center",
                                    "textBaseline": "middle"
                                }
                            }
                        },
                        "location": {
                            "mode": "auto"
                        },
                        "name": "route",
                        "opacity": 1,
                        "tooltip": true,
                        "type": "route"
                    }
                ],
                "tooltip": {
                    "mode": "details"
                },
                "view": {
                    "allLayers": true,
                    "id": "fit",
                    "lat": 0,
                    "lon": 0,
                    "zoom": 15
                }
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "alias": "",
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [
                        {
                            "params": ["$__interval", "none"],
                            "type": "time"
                        }
                    ],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT\n  $__time(date),\n  latitude,\n  longitude\nFROM positions\nWHERE \n  car_id = $car_id AND \n  $__timeFilter(date)\nORDER BY \n  date ASC",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["lat"],
                                "type": "column"
                            },
                            {
                                "params": ["avg"],
                                "type": "aggregate"
                            },
                            {
                                "params": ["lat"],
                                "type": "alias"
                            }
                        ],
                        [
                            {
                                "params": ["lng"],
                                "type": "column"
                            },
                            {
                                "params": ["avg"],
                                "type": "aggregate"
                            },
                            {
                                "params": ["lat"],
                                "type": "alias"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ]
                    },
                    "table": "pos",
                    "timeColumn": "Datum",
                    "timeColumnType": "datetime",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "type": "geomap"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "efficiency_km"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "Wh/km"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "efficiency_mi"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "Wh/mi"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 0,
                "y": 11
            },
            "id": 32,
            "options": {
                "colorMode": "value",
                "graphMode": "none",
                "justifyMode": "auto",
                "orientation": "auto",
                "reduceOptions": {
                    "calcs": ["lastNotNull"],
                    "fields": "",
                    "values": false
                },
                "showPercentChange": false,
                "textMode": "auto",
                "wideLayout": true
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "table",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT\n\t(CASE WHEN '$length_unit' = 'km' THEN $efficiency\n\t     WHEN '$length_unit' = 'mi' THEN $efficiency * 1.60934\n\tEND) * 10 as \"efficiency_$length_unit\"",
                    "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": "Derivated Efficiency",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "yellow",
                                "value": null
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": ".*_km"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "Wh/km"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": ".*_mi"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "Wh/mi"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 4,
                "y": 11
            },
            "id": 24,
            "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": "WITH d 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 charging_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 AND\n\t  $__timeFilter(start_date)\n\tORDER BY start_date\n),\n\nrange_loss_between_charges AS (\n  SELECT sum(range_loss) AS range_loss\n  FROM d\n  WHERE distance >= 0 AND range_loss >= 0\n  GROUP BY car_id\n),\n\ncharge_dates AS (\n\tSELECT\n\t\tmin(start_date) as first_charge,\n\t\tmax(end_date) as last_charge\n\tFROM\n\t\tcharging_processes\n\tWHERE\n\t\tend_date IS NOT NULL\n\t\tAND car_id = $car_id\n\t\tAND $__timeFilter(start_date)\n),\n\nrange_loss_before_first_charge AS (\n\tSELECT\n\t\tmax([[preferred_range]]_battery_range_km) - min([[preferred_range]]_battery_range_km) AS range_loss\n\tFROM positions, charge_dates\n\tWHERE\n\t\tcar_id = $car_id\n\t\tAND $__timeFilter(date)\n\t\tAND ((select first_charge from charge_dates) is null OR date < (select first_charge from charge_dates))\n),\n\nrange_loss_after_last_charge AS (\n\tSELECT\n\t\tmax([[preferred_range]]_battery_range_km) - min([[preferred_range]]_battery_range_km) AS range_loss\n\tFROM positions, charge_dates\n\tWHERE\n\t\tcar_id = $car_id\n\t\tAND $__timeFilter(date)\n\t\tAND date > (select last_charge from charge_dates)\t\n),\n\ntotal_range_loss AS (\n  SELECT sum(range_loss) as range_loss\n  FROM (\n    SELECT range_loss FROM range_loss_between_charges\n    UNION ALL\n    SELECT range_loss FROM range_loss_before_first_charge\n    UNION ALL\n    SELECT range_loss FROM range_loss_after_last_charge\n  ) r\n),\n\ndistance AS (\n  SELECT max(odometer) - min(odometer) as distance\n  FROM positions\n  WHERE car_id = $car_id AND $__timeFilter(date)\n)\n\nSELECT \n  NULLIF(range_loss, 0) * (c.efficiency * 1000) / convert_km(NULLIF(distance::numeric, 0), '$length_unit') as \"consumption_$length_unit\"\nFROM total_range_loss, distance\nLEFT JOIN cars c ON c.id = $car_id",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["start_km"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "drives",
                    "timeColumn": "start_date",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Current Consumption",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "continuous-GrYlRd"
                    },
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "green",
                                "value": null
                            },
                            {
                                "color": "red",
                                "value": 80
                            }
                        ]
                    }
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/.*_f/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "fahrenheit"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/.*_c/"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "celsius"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/outdoor*/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Outdoor"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/inside*/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Inside"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byRegexp",
                            "options": "/driver*/"
                        },
                        "properties": [
                            {
                                "id": "displayName",
                                "value": "Driver"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 8,
                "y": 11
            },
            "id": 34,
            "options": {
                "colorMode": "value",
                "graphMode": "area",
                "justifyMode": "center",
                "orientation": "auto",
                "reduceOptions": {
                    "calcs": ["mean"],
                    "fields": "",
                    "values": false
                },
                "showPercentChange": false,
                "text": {},
                "textMode": "auto",
                "wideLayout": true
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT $__timeGroupAlias(date,$__interval), avg(convert_celsius(outside_temp, '$temp_unit')) as outdoor_$temp_unit \r\nFROM positions \r\nWHERE car_id = $car_id AND outside_temp IS NOT NULL AND $__timeFilter(date)\r\nGROUP BY date\r\nORDER BY date",
                    "refId": "Outdoor",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                },
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT $__timeGroupAlias(date,$__interval), avg(convert_celsius(inside_temp, '$temp_unit')) as inside_$temp_unit \r\nFROM positions \r\nWHERE car_id = $car_id AND outside_temp IS NOT NULL AND $__timeFilter(date)\r\nGROUP BY date\r\nORDER BY date",
                    "refId": "Inside",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                },
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT $__timeGroupAlias(date,$__interval), avg(convert_celsius(driver_temp_setting, '$temp_unit')) as driver_$temp_unit \r\nFROM positions \r\nWHERE car_id = $car_id AND outside_temp IS NOT NULL AND $__timeFilter(date)\r\nGROUP BY date\r\nORDER BY date",
                    "refId": "Driver",
                    "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"
                        }
                    ]
                }
            ],
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "decimals": 1,
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "super-light-blue",
                                "value": null
                            }
                        ]
                    },
                    "unit": "clocks"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 12,
                "y": 11
            },
            "id": 36,
            "options": {
                "colorMode": "value",
                "graphMode": "none",
                "justifyMode": "auto",
                "orientation": "auto",
                "reduceOptions": {
                    "calcs": ["sum"],
                    "fields": "",
                    "values": false
                },
                "showPercentChange": false,
                "text": {},
                "textMode": "value",
                "wideLayout": true
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "alias": "Elapsed Time",
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "table",
                    "group": [],
                    "groupBy": [
                        {
                            "params": ["$__interval"],
                            "type": "time"
                        },
                        {
                            "params": ["null"],
                            "type": "fill"
                        }
                    ],
                    "metricColumn": "none",
                    "orderByTime": "ASC",
                    "policy": "default",
                    "rawQuery": true,
                    "rawSql": "SELECT ${__to:date:seconds} - ${__from:date:seconds}",
                    "refId": "A",
                    "resultFormat": "time_series",
                    "select": [
                        [
                            {
                                "params": ["utc"],
                                "type": "field"
                            },
                            {
                                "params": [],
                                "type": "mean"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "tags": [],
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Elapsed",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "decimals": 1,
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "#c7d0d9",
                                "value": null
                            }
                        ]
                    },
                    "unit": "lengthkm"
                },
                "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": 4,
                "w": 4,
                "x": 0,
                "y": 15
            },
            "id": 27,
            "links": [
                {
                    "targetBlank": true,
                    "title": "Mileage",
                    "url": "/d/NjtMTFggz/mileage?"
                }
            ],
            "maxDataPoints": 100,
            "options": {
                "colorMode": "value",
                "fieldOptions": {
                    "calcs": ["first"]
                },
                "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"
                    },
                    "editorMode": "code",
                    "format": "table",
                    "group": [],
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT convert_km((max(odometer) - min(odometer))::numeric, '$length_unit') as \"distance_$length_unit\"\n  FROM positions\n  WHERE  $__timeFilter(date) AND drive_id=$current_drive ",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Distance",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "decimals": 0,
                    "mappings": [
                        {
                            "options": {
                                "match": "null",
                                "result": {
                                    "text": "N/A"
                                }
                            },
                            "type": "special"
                        }
                    ],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "#c7d0d9",
                                "value": null
                            }
                        ]
                    },
                    "unit": "none"
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "range_km"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "lengthkm"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "range_mi"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "lengthmi"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 4,
                "y": 15
            },
            "id": 14,
            "maxDataPoints": 100,
            "options": {
                "colorMode": "value",
                "fieldOptions": {
                    "calcs": ["first"]
                },
                "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"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT $__timeGroupAlias(date,$__interval), avg(convert_km([[preferred_range]]_battery_range_km, '$length_unit')) as range_$length_unit \nFROM positions WHERE $__timeFilter(date) AND drive_id=$current_drive GROUP BY 1 ORDER BY 1 desc limit 1",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Current Range ($preferred_range)",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "decimals": 0,
                    "mappings": [],
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "#c7d0d9",
                                "value": null
                            }
                        ]
                    },
                    "unit": "none"
                },
                "overrides": [
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "odometer_km"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "km"
                            }
                        ]
                    },
                    {
                        "matcher": {
                            "id": "byName",
                            "options": "odometer_mi"
                        },
                        "properties": [
                            {
                                "id": "unit",
                                "value": "mi"
                            }
                        ]
                    }
                ]
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 8,
                "y": 15
            },
            "id": 6,
            "links": [
                {
                    "targetBlank": true,
                    "title": "Mileage",
                    "url": "/d/NjtMTFggz/mileage?"
                }
            ],
            "maxDataPoints": 100,
            "options": {
                "colorMode": "value",
                "fieldOptions": {
                    "calcs": ["first"]
                },
                "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"
                    },
                    "editorMode": "code",
                    "format": "time_series",
                    "group": [],
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "select $__time(date), convert_km(odometer::numeric, '$length_unit')  as \"odometer_$length_unit\"\nfrom positions \nwhere drive_id = $current_drive \norder by date desc \nlimit 1;",
                    "refId": "A",
                    "select": [
                        [
                            {
                                "params": ["value"],
                                "type": "column"
                            }
                        ]
                    ],
                    "sql": {
                        "columns": [
                            {
                                "parameters": [],
                                "type": "function"
                            }
                        ],
                        "groupBy": [
                            {
                                "property": {
                                    "type": "string"
                                },
                                "type": "groupBy"
                            }
                        ],
                        "limit": 50
                    },
                    "timeColumn": "time",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "title": "Odometer",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "description": "",
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "palette-classic"
                    },
                    "decimals": 0,
                    "mappings": [],
                    "max": 49,
                    "min": 0,
                    "noValue": "0",
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "light-orange",
                                "value": null
                            }
                        ]
                    },
                    "unit": "kwatth"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 4,
                "w": 4,
                "x": 12,
                "y": 15
            },
            "id": 35,
            "options": {
                "colorMode": "value",
                "graphMode": "area",
                "justifyMode": "center",
                "orientation": "vertical",
                "reduceOptions": {
                    "calcs": ["lastNotNull"],
                    "fields": "",
                    "values": false
                },
                "showPercentChange": false,
                "textMode": "value",
                "wideLayout": true
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "alias": "kWh Added",
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "editorMode": "code",
                    "format": "table",
                    "group": [],
                    "hide": false,
                    "metricColumn": "none",
                    "rawQuery": true,
                    "rawSql": "SELECT $BatteryCapacity AS \"Battery Capacity\"",
                    "refId": "B",
                    "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": "Battery Capacity",
            "type": "stat"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "thresholds"
                    },
                    "decimals": 1,
                    "mappings": [],
                    "max": 100,
                    "min": 0,
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "dark-red",
                                "value": null
                            },
                            {
                                "color": "semi-dark-green",
                                "value": 20
                            },
                            {
                                "color": "semi-dark-orange",
                                "value": 80
                            },
                            {
                                "color": "light-blue",
                                "value": 100
                            }
                        ]
                    },
                    "unit": "%"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 2,
                "w": 8,
                "x": 0,
                "y": 19
            },
            "id": 29,
            "options": {
                "displayMode": "lcd",
                "maxVizHeight": 300,
                "minVizHeight": 10,
                "minVizWidth": 0,
                "namePlacement": "auto",
                "orientation": "horizontal",
                "reduceOptions": {
                    "calcs": ["lastNotNull"],
                    "fields": "",
                    "values": false
                },
                "showUnfilled": true,
                "sizing": "auto",
                "text": {},
                "valueMode": "color"
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "format": "table",
                    "group": [],
                    "groupBy": [
                        {
                            "params": ["$__interval"],
                            "type": "time"
                        },
                        {
                            "params": ["null"],
                            "type": "fill"
                        }
                    ],
                    "measurement": "%",
                    "metricColumn": "none",
                    "orderByTime": "ASC",
                    "policy": "default",
                    "rawQuery": true,
                    "rawSql": "(SELECT battery_level, date\nFROM positions\nWHERE car_id = $car_id\nORDER BY date DESC\nLIMIT 1)\nUNION\nSELECT battery_level, date\nFROM charges c\nJOIN charging_processes p ON p.id = c.charging_process_id\nWHERE $__timeFilter(date) AND p.car_id = $car_id\nORDER BY date DESC\nLIMIT 1",
                    "refId": "SOC",
                    "resultFormat": "time_series",
                    "select": [
                        [
                            {
                                "params": ["start_km"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "drives",
                    "timeColumn": "start_date",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "type": "bargauge"
        },
        {
            "datasource": {
                "type": "grafana-postgresql-datasource",
                "uid": "TeslaMate"
            },
            "description": "",
            "fieldConfig": {
                "defaults": {
                    "color": {
                        "mode": "thresholds"
                    },
                    "decimals": 1,
                    "mappings": [],
                    "min": 0,
                    "thresholds": {
                        "mode": "absolute",
                        "steps": [
                            {
                                "color": "dark-red",
                                "value": null
                            },
                            {
                                "color": "dark-green",
                                "value": 7.84
                            },
                            {
                                "color": "semi-dark-orange",
                                "value": 31.36
                            },
                            {
                                "color": "light-blue",
                                "value": 35.28
                            }
                        ]
                    },
                    "unit": "kwatth"
                },
                "overrides": []
            },
            "gridPos": {
                "h": 2,
                "w": 8,
                "x": 8,
                "y": 19
            },
            "id": 31,
            "options": {
                "displayMode": "gradient",
                "maxVizHeight": 300,
                "minVizHeight": 10,
                "minVizWidth": 0,
                "namePlacement": "auto",
                "orientation": "horizontal",
                "reduceOptions": {
                    "calcs": ["lastNotNull"],
                    "fields": "/^kwh$/",
                    "values": false
                },
                "showUnfilled": true,
                "sizing": "auto",
                "text": {},
                "valueMode": "color"
            },
            "pluginVersion": "10.4.0",
            "targets": [
                {
                    "datasource": {
                        "type": "grafana-postgresql-datasource",
                        "uid": "TeslaMate"
                    },
                    "format": "table",
                    "group": [],
                    "groupBy": [
                        {
                            "params": ["$__interval"],
                            "type": "time"
                        },
                        {
                            "params": ["null"],
                            "type": "fill"
                        }
                    ],
                    "measurement": "%",
                    "metricColumn": "none",
                    "policy": "default",
                    "rawQuery": true,
                    "rawSql": "(SELECT battery_level * $BatteryCapacity / 100 as kWh, date, $BatteryCapacity as Total\nFROM positions\nWHERE car_id = $car_id\nORDER BY date DESC\nLIMIT 1)\nUNION\nSELECT battery_level * $BatteryCapacity / 100 as kWh, date, $BatteryCapacity as Total\nFROM charges c\nJOIN charging_processes p ON p.id = c.charging_process_id\nWHERE $__timeFilter(date) AND p.car_id = $car_id\nORDER BY date DESC\nLIMIT 1",
                    "refId": "A",
                    "resultFormat": "time_series",
                    "select": [
                        [
                            {
                                "params": ["start_km"],
                                "type": "column"
                            }
                        ]
                    ],
                    "table": "drives",
                    "timeColumn": "start_date",
                    "timeColumnType": "timestamp",
                    "where": [
                        {
                            "name": "$__timeFilter",
                            "params": [],
                            "type": "macro"
                        }
                    ]
                }
            ],
            "type": "bargauge"
        }
    ],
    "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 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 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,
                "tagValuesQuery": "",
                "tagsQuery": "",
                "type": "query",
                "useTags": false
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "select preferred_range from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "label": "",
                "multi": false,
                "name": "preferred_range",
                "options": [],
                "query": "select preferred_range 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 case when unit_of_length = 'km' then 'm' when unit_of_length = 'mi' then 'ft' end  from settings limit 1;",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "alternative_length_unit",
                "options": [],
                "query": "select case when unit_of_length = 'km' then 'm' when unit_of_length = 'mi' then 'ft' end  from settings limit 1;",
                "refresh": 1,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT drive_id FROM positions WHERE car_id = $car_id AND drive_id IS NOT NULL ORDER BY date DESC LIMIT 1;",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "current_drive",
                "options": [],
                "query": "SELECT drive_id FROM positions WHERE car_id = $car_id AND drive_id IS NOT NULL ORDER BY date DESC LIMIT 1;",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT \n  (round(extract(epoch FROM start_date) - 10) * 1000) AS start_date_ts\n  FROM drives \n   WHERE id = $current_drive",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "current_drive_start_time",
                "options": [],
                "query": "SELECT \n  (round(extract(epoch FROM start_date) - 10) * 1000) AS start_date_ts\n  FROM drives \n   WHERE id = $current_drive",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "SELECT \n  CASE WHEN end_date IS NULL THEN 'now&refresh=10s' \n  ELSE CAST(round(extract(epoch FROM end_date) - 10) * 1000 AS VARCHAR(100)) END\n  FROM drives\n  WHERE id = $current_drive",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "current_drive_end_time",
                "options": [],
                "query": "SELECT \n  CASE WHEN end_date IS NULL THEN 'now&refresh=10s' \n  ELSE CAST(round(extract(epoch FROM end_date) - 10) * 1000 AS VARCHAR(100)) END\n  FROM drives\n  WHERE id = $current_drive",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "--- Extracted from Battery Health Dashboard",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "BatteryCapacity",
                "options": [],
                "query": "WITH Aux AS\n(SELECT car_id,\n\t\tCOALESCE(efficiency, \n\t\t(SELECT efficiency\n\t\t\tFROM cars WHERE id = $car_id) * 100) AS efficiency\n\tFROM (\n\t\tSELECT ROUND((charge_energy_added / NULLIF(end_rated_range_km - start_rated_range_km, 0))::numeric, 3) * 100 as efficiency,\n\t\t\tCOUNT(*) as count, $car_id AS car_id \n\t\tFROM charging_processes\n\t\tWHERE car_id = $car_id\n\t\t\tAND duration_min > 10\n\t\t\tAND end_battery_level <= 95\n\t\t\tAND start_rated_range_km IS NOT NULL\n\t\t\tAND end_rated_range_km IS NOT NULL\n\t\t\tAND charge_energy_added > 0\n\t\tGROUP BY 1\n\t\tORDER BY 2 DESC\n\t\tLIMIT 1\n\t) AS DerivatedEfficiency\n),\nCurrentCapacity\t AS\n(SELECT AVG(Capacity) AS CurrentCapacity \nFROM (\nSELECT \n\tc.[[preferred_range]]_battery_range_km * aux.efficiency / c.usable_battery_level AS Capacity \n\tFROM charging_processes cp\n\t\tINNER JOIN charges c\n\t\tON c.charging_process_id = cp.id \n                INNER JOIN aux ON cp.car_id = aux.car_id\n\tWHERE cp.car_id = $car_id\n\t\tAND cp.end_date IS NOT NULL\n\t\tAND cp.charge_energy_added >= aux.efficiency\n\t\tAND c.usable_battery_level > 0\n\t ORDER BY cp.end_date DESC LIMIT 10) AS lastCharges\n)\nSELECT CurrentCapacity FROM CurrentCapacity",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            },
            {
                "current": {},
                "datasource": {
                    "type": "grafana-postgresql-datasource",
                    "uid": "TeslaMate"
                },
                "definition": "--- Extracted from Battery Health Dashboard",
                "hide": 2,
                "includeAll": false,
                "multi": false,
                "name": "efficiency",
                "options": [],
                "query": "\t\tSELECT \n\t\tCOALESCE(efficiency, \n\t\t(SELECT efficiency\n\t\t\tFROM cars WHERE id = $car_id) * 100) AS efficiency\n\tFROM (\n\t\tSELECT ROUND((charge_energy_added / NULLIF(end_rated_range_km - start_rated_range_km, 0))::numeric, 3) * 100 as efficiency,\n\t\t\tCOUNT(*) as count, $car_id AS car_id \n\t\tFROM charging_processes\n\t\tWHERE car_id = $car_id\n\t\t\tAND duration_min > 10\n\t\t\tAND end_battery_level <= 95\n\t\t\tAND start_rated_range_km IS NOT NULL\n\t\t\tAND end_rated_range_km IS NOT NULL\n\t\t\tAND charge_energy_added > 0\n\t\tGROUP BY 1\n\t\tORDER BY 2 DESC\n\t\tLIMIT 1\n\t) AS DerivatedEfficiency",
                "refresh": 2,
                "regex": "",
                "skipUrlSync": false,
                "sort": 0,
                "type": "query"
            }
        ]
    },
    "time": {
        "from": "now-15m",
        "to": "now"
    },
    "timepicker": {
        "hidden": false,
        "refresh_intervals": [
            "5s",
            "10s",
            "30s",
            "1m",
            "5m",
            "15m",
            "30m",
            "1h",
            "2h",
            "1d"
        ],
        "time_options": [
            "5m",
            "15m",
            "1h",
            "6h",
            "12h",
            "24h",
            "2d",
            "7d",
            "30d"
        ]
    },
    "timezone": "",
    "title": "Current Drive View",
    "uid": "jchmkOuP_Fggz",
    "version": 11,
    "weekStart": ""
}
