Created
May 22, 2024 17:49
-
-
Save AlanJohnWilliams/9e6cce34412d3f4eb6b21df197c229c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"__inputs": [ | |
{ | |
"name": "DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH", | |
"label": "InfluxDB - Homeassistant - FLUX - BH", | |
"description": "", | |
"type": "datasource", | |
"pluginId": "influxdb", | |
"pluginName": "InfluxDB" | |
} | |
], | |
"__elements": {}, | |
"__requires": [ | |
{ | |
"type": "panel", | |
"id": "dashlist", | |
"name": "Dashboard list", | |
"version": "" | |
}, | |
{ | |
"type": "panel", | |
"id": "gauge", | |
"name": "Gauge", | |
"version": "" | |
}, | |
{ | |
"type": "grafana", | |
"id": "grafana", | |
"name": "Grafana", | |
"version": "10.4.2" | |
}, | |
{ | |
"type": "datasource", | |
"id": "influxdb", | |
"name": "InfluxDB", | |
"version": "1.0.0" | |
}, | |
{ | |
"type": "panel", | |
"id": "timeseries", | |
"name": "Time series", | |
"version": "" | |
} | |
], | |
"annotations": { | |
"list": [ | |
{ | |
"builtIn": 1, | |
"datasource": { | |
"type": "datasource", | |
"uid": "grafana" | |
}, | |
"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": 0, | |
"id": null, | |
"links": [], | |
"liveNow": false, | |
"panels": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 0, | |
"y": 0 | |
}, | |
"id": 25, | |
"options": { | |
"folderUID": "", | |
"includeVars": true, | |
"keepTime": true, | |
"maxItems": 10, | |
"query": "${vehicleName}", | |
"showHeadings": true, | |
"showRecentlyViewed": false, | |
"showSearch": true, | |
"showStarred": false, | |
"tags": [] | |
}, | |
"pluginVersion": "10.4.2", | |
"type": "dashlist" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"max": 100000, | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 2, | |
"y": 0 | |
}, | |
"id": 26, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nfrom(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> last()\n\n\n", | |
"refId": "A" | |
} | |
], | |
"title": "Odometer (mi)", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 4, | |
"y": 0 | |
}, | |
"id": 20, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nfrom(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> spread()\n\n\n", | |
"refId": "A" | |
} | |
], | |
"title": "Distance (mi)", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"max": 6, | |
"min": 0, | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "red", | |
"value": null | |
}, | |
{ | |
"color": "yellow", | |
"value": 1.4 | |
}, | |
{ | |
"color": "green", | |
"value": 1.8 | |
}, | |
{ | |
"color": "blue", | |
"value": 2.2 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 6, | |
"y": 0 | |
}, | |
"id": 30, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\nimport \"array\"\n\nsoc_delta = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/ and r._field == \"value\")\n |> elapsed()\n |> map(fn: (r) => ({r with _value: 100.0 - r._value}))\n |> difference(nonNegative: true)\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"soc_delta\"})\n\ndistance = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> difference(nonNegative: true)\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"distance\"})\n\nstate = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"entity_id\"] == \"${vehicleName}_power_state\")\n |> filter(fn: (r) => r[\"_field\"] == \"state\")\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"state\"})\n\nbattery_capacity = {_value: 130.0}\n//battery_capacity = from(bucket: \"homeassistant\")\n// |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n// |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_capacity$/ and r._field == \"value\")\n// |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n// |> max()\n// |> toFloat()\n// |> findRecord(fn: (key) => true, idx: 0)\n\nunion(tables: [soc_delta, state, distance])\n |> sort(columns:[\"_time\"])\n |> reduce(\n identity: {last_state: \"None\", moving_loss: 0.0, phantom_loss: 0.0, moving_time: 0, phantom_time: 0, distance: 0.0},\n fn: (r, accumulator) => ({\n last_state: if exists r.state then r.state else accumulator.last_state,\n moving_loss: if accumulator.last_state == \"Go\" then \n if exists r.soc_delta then accumulator.moving_loss + r.soc_delta else accumulator.moving_loss\n else accumulator.moving_loss,\n phantom_loss: if accumulator.last_state != \"Go\" then \n if exists r.soc_delta then accumulator.phantom_loss + r.soc_delta else accumulator.phantom_loss\n else accumulator.phantom_loss,\n moving_time: if accumulator.last_state == \"Go\" then \n if exists r.elapsed then accumulator.moving_time + r.elapsed else accumulator.moving_time\n else accumulator.moving_time,\n phantom_time: if accumulator.last_state != \"Go\" then \n if exists r.elapsed then accumulator.phantom_time + r.elapsed else accumulator.phantom_time\n else accumulator.phantom_time,\n distance: if accumulator.last_state == \"Go\" then \n if exists r.distance then accumulator.distance + r.distance else accumulator.distance\n else accumulator.distance,\n })\n )\n |> reduce(\n identity: {moving: 0.0, phantom: 0.0, moving_hr: 0.0, phantom_mo: 0.0, moving_time: 0.0, phantom_time: 0.0, distance: 0.0, moving_efficency: 0.0},\n fn: (r, accumulator) => ({\n moving: r.moving_loss * float(v: battery_capacity._value) / 100.0,\n phantom: r.phantom_loss * float(v: battery_capacity._value) / 100.0,\n moving_time: float(v: r.moving_time) / 60.0 / 60.0,\n phantom_time: (float(v: r.phantom_time) / 60.0 / 60.0 / 24.0 / (365.0 / 12.0)),\n moving_hr: (r.moving_loss * float(v: battery_capacity._value) / 100.0) / (float(v: r.moving_time) / 60.0 / 60.0),\n phantom_mo: (r.phantom_loss * float(v: battery_capacity._value) / 100.0) /((float(v: r.phantom_time) / 60.0 / 60.0 / 24.0 / (365.0 / 12.0))),\n moving_efficency: r.distance / (r.moving_loss * float(v: battery_capacity._value) / 100.0),\n distance: r.distance,\n })\n )\n// |> keep(columns: [\"moving\",\"moving_hr\",\"phantom\",\"phantom_mo\",\"moving_time\",\"phantom_time\",\"distance\",\"moving_efficency\"])\n// |> rename(columns: {moving: \"Moving (kWh)\", moving_hr: \"Moving (kWh/hr)\", phantom: \"Phantom (kWh)\", phantom_mo: \"Phantom (kWh/mo)\", \n// moving_time: \"Moving (hr)\", phantom_time: \"Phantom (mo)\", distance: \"Distance (mi)\", moving_efficency: \"Efficiency (mi/kWh)\"})\n |> keep(columns: [\"moving_efficency\"])\n |> rename(columns: {moving_efficency: \"Efficiency (mi/kWh)\"})\n", | |
"refId": "A" | |
} | |
], | |
"title": "Moving Efficiency", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": true, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 10, | |
"w": 8, | |
"x": 8, | |
"y": 0 | |
}, | |
"id": 8, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": true | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/) or\n (r.entity_id =~ /^${vehicleName}_soc_limit$/) \n ) \n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n |> pivot(rowKey:[\"_time\"],columnKey:[\"entity_id\"],valueColumn: \"_value\")\n |> keep(columns: [\"_time\",\"${vehicleName}_battery_state_of_charge\",\"${vehicleName}_soc_limit\"])\n |> rename(fn: (column) => {\n return if column == \"${vehicleName}_soc_limit\" then \"Charge Limit\" else column\n })\n|> rename(fn: (column) => {\n return if column == \"${vehicleName}_battery_state_of_charge\" then \"SoC\" else column\n })\n\n", | |
"refId": "A" | |
} | |
], | |
"title": "State of Charge (SOC) (%)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": false, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 10, | |
"w": 8, | |
"x": 16, | |
"y": 0 | |
}, | |
"id": 15, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "right", | |
"showLegend": false | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_battery_capacity$/)\n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n", | |
"refId": "A" | |
} | |
], | |
"title": "Battery Capacity (kWh)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 0, | |
"y": 4 | |
}, | |
"id": 21, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nfrom(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_charger_connection$/ and r._field == \"value\")\n |> difference()\n |> filter(fn: (r) => r._value > 0)\n |> count()\n", | |
"refId": "A" | |
} | |
], | |
"title": "Charges", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 2, | |
"y": 4 | |
}, | |
"id": 22, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nfrom(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_charging_energy_delivered$/ and r._field == \"value\")\n |> difference(nonNegative: true)\n |> sum()\n\n", | |
"refId": "A" | |
} | |
], | |
"title": "Energy Added (kWh)", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 4, | |
"y": 4 | |
}, | |
"id": 23, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\nimport \"array\"\n\nkw_added = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_charging_energy_delivered$/ and r._field == \"value\")\n |> difference(nonNegative: true)\n |> sum()\n |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n |> toFloat()\n |> findRecord(fn: (key) => true, idx: 0)\n\n\nperc_battery_used = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/ and r._field == \"value\")\n |> map(fn: (r) => ({r with _value: 100.0 - r._value}))\n |> difference(nonNegative: true)\n |> sum()\n |> toFloat()\n |> findRecord(fn: (key) => true, idx: 0)\n \nbattery_capacity = {_value: 130.0}\n//battery_capacity = from(bucket: \"homeassistant\")\n// |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n// |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_capacity/ and r._field == \"value\")\n// |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n// |> max()\n// |> toFloat()\n// |> findRecord(fn: (key) => true, idx: 0)\n\nresult = (if exists kw_added._value then kw_added._value else 0.0) + (battery_capacity._value * (if perc_battery_used._value < 0.0 then 0.0 else perc_battery_used._value) / 100.0)\n\narray.from(rows: [{result}])", | |
"refId": "A" | |
} | |
], | |
"title": "Consumption (kWh)", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"max": 6, | |
"min": 0, | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "red", | |
"value": null | |
}, | |
{ | |
"color": "yellow", | |
"value": 1.4 | |
}, | |
{ | |
"color": "green", | |
"value": 1.8 | |
}, | |
{ | |
"color": "blue", | |
"value": 2.2 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 4, | |
"w": 2, | |
"x": 6, | |
"y": 4 | |
}, | |
"id": 29, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\nimport \"array\"\n\ndistance = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> spread()\n |> toFloat()\n |> findRecord(fn: (key) => true, idx: 0)\n\n\nkw_added = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /${vehicleName}_charging_energy_delivered$/ and r._field == \"value\")\n |> difference(nonNegative: true)\n |> sum()\n |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n |> toFloat()\n |> findRecord(fn: (key) => true, idx: 0)\n\n\nperc_battery_used = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/ and r._field == \"value\")\n |> map(fn: (r) => ({r with _value: 100.0 - r._value}))\n |> difference(nonNegative: true)\n |> sum()\n |> toFloat()\n |> findRecord(fn: (key) => true, idx: 0)\n\nbattery_capacity = {_value: 130.0}\n//battery_capacity = from(bucket: \"homeassistant\")\n// |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n// |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_capacity$/ and r._field == \"value\")\n// |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n// |> max()\n// |> toFloat()\n// |> findRecord(fn: (key) => true, idx: 0)\n\nresult = distance._value / ( (if exists kw_added._value then kw_added._value else 0.0) + (battery_capacity._value * (perc_battery_used._value / 100.0))) \n\narray.from(rows: [{result}])\n", | |
"refId": "A" | |
} | |
], | |
"title": "Total Efficiency (mi/kWh)", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "thresholds" | |
}, | |
"mappings": [], | |
"max": 6, | |
"min": 0, | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "purple", | |
"value": null | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 7, | |
"w": 8, | |
"x": 0, | |
"y": 8 | |
}, | |
"id": 28, | |
"options": { | |
"minVizHeight": 75, | |
"minVizWidth": 75, | |
"orientation": "auto", | |
"reduceOptions": { | |
"calcs": [ | |
"lastNotNull" | |
], | |
"fields": "", | |
"values": false | |
}, | |
"showThresholdLabels": false, | |
"showThresholdMarkers": true, | |
"sizing": "auto" | |
}, | |
"pluginVersion": "10.4.2", | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\nimport \"array\"\n\nsoc_delta = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/ and r._field == \"value\")\n |> elapsed()\n |> map(fn: (r) => ({r with _value: 100.0 - r._value}))\n |> difference(nonNegative: true)\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"soc_delta\"})\n\ndistance = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> difference(nonNegative: true)\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"distance\"})\n\nstate = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"entity_id\"] == \"${vehicleName}_power_state\")\n |> filter(fn: (r) => r[\"_field\"] == \"state\")\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"state\"})\n\nbattery_capacity = {_value: 130.0}\n//battery_capacity = from(bucket: \"homeassistant\")\n// |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n// |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_capacity$/ and r._field == \"value\")\n// |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n// |> max()\n// |> toFloat()\n// |> findRecord(fn: (key) => true, idx: 0)\n\nunion(tables: [soc_delta, state, distance])\n |> sort(columns:[\"_time\"])\n |> reduce(\n identity: {last_state: \"None\", moving_loss: 0.0, phantom_loss: 0.0, moving_time: 0, phantom_time: 0, distance: 0.0},\n fn: (r, accumulator) => ({\n last_state: if exists r.state then r.state else accumulator.last_state,\n moving_loss: if accumulator.last_state == \"Go\" then \n if exists r.soc_delta then accumulator.moving_loss + r.soc_delta else accumulator.moving_loss\n else accumulator.moving_loss,\n phantom_loss: if accumulator.last_state != \"Go\" then \n if exists r.soc_delta then accumulator.phantom_loss + r.soc_delta else accumulator.phantom_loss\n else accumulator.phantom_loss,\n moving_time: if accumulator.last_state == \"Go\" then \n if exists r.elapsed then accumulator.moving_time + r.elapsed else accumulator.moving_time\n else accumulator.moving_time,\n phantom_time: if accumulator.last_state != \"Go\" then \n if exists r.elapsed then accumulator.phantom_time + r.elapsed else accumulator.phantom_time\n else accumulator.phantom_time,\n distance: if accumulator.last_state == \"Go\" then \n if exists r.distance then accumulator.distance + r.distance else accumulator.distance\n else accumulator.distance,\n })\n )\n |> reduce(\n identity: {moving: 0.0, phantom: 0.0, moving_hr: 0.0, phantom_mo: 0.0, moving_time: 0.0, phantom_time: 0.0, distance: 0.0, moving_efficency: 0.0},\n fn: (r, accumulator) => ({\n moving: r.moving_loss * float(v: battery_capacity._value) / 100.0,\n phantom: r.phantom_loss * float(v: battery_capacity._value) / 100.0,\n moving_time: float(v: r.moving_time) / 60.0 / 60.0,\n phantom_time: (float(v: r.phantom_time) / 60.0 / 60.0 / 24.0 / (365.0 / 12.0)),\n moving_hr: (r.moving_loss * float(v: battery_capacity._value) / 100.0) / (float(v: r.moving_time) / 60.0 / 60.0),\n phantom_mo: (r.phantom_loss * float(v: battery_capacity._value) / 100.0) /((float(v: r.phantom_time) / 60.0 / 60.0 / 24.0 / (365.0 / 12.0))),\n moving_efficency: r.distance / (r.moving_loss * float(v: battery_capacity._value) / 100.0),\n distance: r.distance,\n })\n )\n// |> keep(columns: [\"moving\",\"moving_hr\",\"phantom\",\"phantom_mo\",\"moving_time\",\"phantom_time\",\"distance\",\"moving_efficency\"])\n// |> rename(columns: {moving: \"Moving (kWh)\", moving_hr: \"Moving (kWh/hr)\", phantom: \"Phantom (kWh)\", phantom_mo: \"Phantom (kWh/mo)\", \n// moving_time: \"Moving (hr)\", phantom_time: \"Phantom (mo)\", distance: \"Distance (mi)\", moving_efficency: \"Efficiency (mi/kWh)\"})\n |> keep(columns: [\"moving\",\"moving_hr\",\"phantom\",\"phantom_mo\",\"moving_time\",\"phantom_time\"])\n |> rename(columns: {moving: \"Moving (kWh)\", moving_hr: \"Moving (kWh/hr)\", phantom: \"Phantom (kWh)\", phantom_mo: \"Phantom (kWh/mo)\", \n moving_time: \"Moving (hr)\", phantom_time: \"Phantom (mo)\"})\n", | |
"refId": "A" | |
} | |
], | |
"title": "Energy Utilization", | |
"type": "gauge" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "stepAfter", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": true, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 11, | |
"w": 8, | |
"x": 8, | |
"y": 10 | |
}, | |
"id": 11, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": true | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_battery_capacity$/) or\n (r.entity_id =~ /^${vehicleName}_charging_speed$/) or\n (r.entity_id =~ /^${vehicleName}_charging_energy_delivered$/) \n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n |> pivot(rowKey:[\"_time\"],columnKey:[\"entity_id\"],valueColumn: \"_value\")\n |> keep(columns: [\"_time\",\"${vehicleName}_charging_speed\",\"${vehicleName}_battery_capacity\",\"${vehicleName}_charging_energy_delivered\"])\n |> rename(columns: {${vehicleName}_charging_speed: \"Charging Speed (kW)\", ${vehicleName}_charging_energy_delivered: \"Charge Delivered (kWh)\"})\n |> rename(fn: (column) => {\n return if column == \"${vehicleName}_battery_capacity\" then \"Capacity (kWh)\" else column\n })", | |
"refId": "A" | |
} | |
], | |
"title": "Charging (kW / kWh)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": false, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 11, | |
"w": 8, | |
"x": 16, | |
"y": 10 | |
}, | |
"id": 31, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "right", | |
"showLegend": false | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_odometer$/)\n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n", | |
"refId": "A" | |
} | |
], | |
"title": "Odometer (mi)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": false, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 8, | |
"w": 8, | |
"x": 0, | |
"y": 15 | |
}, | |
"id": 17, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": true | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_tire_pressure/) \n ) and (\n (r.entity_id !~ /^${vehicleName}_tire_pressure.*validity/) \n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n |> pivot(rowKey:[\"_time\"],columnKey:[\"entity_id\"],valueColumn: \"_value\")\n |> keep(fn: (column) => column =~ /^(_time)|(${vehicleName}_tire_pressure)/)\n |> rename(fn: (column) => {\n return if column =~ /front_right/ then \"Front Right\" else \n if column =~ /front_left/ then \"Front Left\" else \n if column =~ /rear_right/ then \"Rear Right\" else\n if column =~ /rear_left/ then \"Rear Left\" else column\n },)", | |
"refId": "A" | |
} | |
], | |
"title": "Tire Pressure (psi)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": false, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 11, | |
"w": 8, | |
"x": 8, | |
"y": 21 | |
}, | |
"id": 27, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": false | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\nimport \"array\"\n\nsoc_delta = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_state_of_charge$/ and r._field == \"value\")\n |> elapsed()\n |> map(fn: (r) => ({r with _value: 100.0 - r._value}))\n |> difference(nonNegative: true)\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"soc_delta\"})\n\nstate = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r[\"entity_id\"] == \"${vehicleName}_power_state\")\n |> filter(fn: (r) => r[\"_field\"] == \"state\")\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"state\"})\n\ndistance = from(bucket: \"homeassistant\")\n |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_odometer$/ and r._field == \"value\")\n |> difference()\n |> drop(columns: [\"_field\",\"_measurement\",\"domain\",\"entity_id\"])\n |> rename(columns: {_value: \"distance\"})\n\nbattery_capacity = {_value: 130.0}\n//battery_capacity = from(bucket: \"homeassistant\")\n// |> range(start: v.timeRangeStart, stop: v.timeRangeStop)\n// |> filter(fn: (r) => r.entity_id =~ /^${vehicleName}_battery_capacity$/ and r._field == \"value\")\n// |> drop(columns: [\"_time\",\"_start\",\"_stop\"])\n// |> max()\n// |> toFloat()\n// |> findRecord(fn: (key) => true, idx: 0)\n\nunion(tables: [soc_delta, state, distance])\n |> sort(columns:[\"_time\"])\n |> aggregateWindow(\n// every: v.windowPeriod, \n every: 60m,\n fn: (column, tables=<-) => tables\n |> reduce(\n identity: {last_state: \"None\", distance: 0.0, moving_loss: 0.0, phantom_loss: 0.0, moving_time: 0, phantom_time: 0},\n fn: (r, accumulator) => ({\n last_state: if exists r.state then r.state else accumulator.last_state,\n distance: if accumulator.last_state == \"Go\" then \n if exists r.distance then accumulator.distance + float(v: r.distance) else accumulator.distance\n else accumulator.distance,\n moving_loss: if accumulator.last_state == \"Go\" then \n if exists r.soc_delta then accumulator.moving_loss + r.soc_delta else accumulator.moving_loss\n else accumulator.moving_loss,\n phantom_loss: if accumulator.last_state != \"Go\" then \n if exists r.soc_delta then accumulator.phantom_loss + r.soc_delta else accumulator.phantom_loss\n else accumulator.phantom_loss,\n moving_time: if accumulator.last_state == \"Go\" then \n if exists r.elapsed then accumulator.moving_time + r.elapsed else accumulator.moving_time\n else accumulator.moving_time,\n phantom_time: if accumulator.last_state != \"Go\" then \n if exists r.elapsed then accumulator.phantom_time + r.elapsed else accumulator.phantom_time\n else accumulator.phantom_time,\n })\n )\n )\n |> filter(fn: (r) => r.distance > 0.10 and r.moving_loss > 0.1)\n |> map(fn: (r) => ({\n r with efficiency: r.distance / (r.moving_loss * float(v: battery_capacity._value) / 100.0),\n }))\n// |> keep(columns: [\"_time\",\"efficiency\",\"distance\",\"moving_loss\"])\n |> keep(columns: [\"_time\",\"efficiency\"])\n |> rename(columns: {efficiency: \"Efficiency (mi/kWh)\"})\n\n// result = distance._value / (kw_added._value + (battery_capacity._value * (perc_battery_used._value / 100.0))) \n", | |
"refId": "A" | |
} | |
], | |
"title": "Efficiency", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "stepBefore", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": false, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 11, | |
"w": 8, | |
"x": 16, | |
"y": 21 | |
}, | |
"id": 12, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": true | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_charging_range_added$/) or\n (r.entity_id =~ /^${vehicleName}_estimated_vehicle_range$/) \n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /sulley/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n |> pivot(rowKey:[\"_time\"],columnKey:[\"entity_id\"],valueColumn: \"_value\")\n |> keep(columns: [\"_time\",\"${vehicleName}_charging_range_added\",\"${vehicleName}_estimated_vehicle_range\"])\n |> rename(columns: {${vehicleName}_estimated_vehicle_range: \"Range\"})\n |> rename(fn: (column) => {\n return if column == \"${vehicleName}_charging_range_added\" then \"Range Added\" else column\n })", | |
"refId": "A" | |
} | |
], | |
"title": "Mileage (mi)", | |
"type": "timeseries" | |
}, | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"fieldConfig": { | |
"defaults": { | |
"color": { | |
"mode": "palette-classic" | |
}, | |
"custom": { | |
"axisBorderShow": false, | |
"axisCenteredZero": false, | |
"axisColorMode": "text", | |
"axisLabel": "", | |
"axisPlacement": "auto", | |
"barAlignment": 0, | |
"drawStyle": "line", | |
"fillOpacity": 0, | |
"gradientMode": "none", | |
"hideFrom": { | |
"legend": false, | |
"tooltip": false, | |
"viz": false | |
}, | |
"insertNulls": false, | |
"lineInterpolation": "smooth", | |
"lineWidth": 1, | |
"pointSize": 5, | |
"scaleDistribution": { | |
"type": "linear" | |
}, | |
"showPoints": "auto", | |
"spanNulls": true, | |
"stacking": { | |
"group": "A", | |
"mode": "none" | |
}, | |
"thresholdsStyle": { | |
"mode": "off" | |
} | |
}, | |
"mappings": [], | |
"thresholds": { | |
"mode": "absolute", | |
"steps": [ | |
{ | |
"color": "green", | |
"value": null | |
}, | |
{ | |
"color": "red", | |
"value": 80 | |
} | |
] | |
} | |
}, | |
"overrides": [] | |
}, | |
"gridPos": { | |
"h": 9, | |
"w": 8, | |
"x": 0, | |
"y": 23 | |
}, | |
"id": 16, | |
"options": { | |
"legend": { | |
"calcs": [], | |
"displayMode": "list", | |
"placement": "bottom", | |
"showLegend": true | |
}, | |
"tooltip": { | |
"mode": "single", | |
"sort": "none" | |
} | |
}, | |
"targets": [ | |
{ | |
"datasource": { | |
"type": "influxdb", | |
"uid": "${DS_INFLUXDB_- HOMEASSISTANT - FLUX - BH}" | |
}, | |
"query": "import \"regexp\"\nimport \"date\"\n\nextend_duration = 1 // hours\nextend_duration_ns = extend_duration * 60 * 60 * 1000 * 1000 * 1000\n\n// Function definition\nfilterEntities = (r) => \n (\n (r.entity_id =~ /^${vehicleName}_cabin_temp/) or\n (r.entity_id =~ /^boulder_temp/) or\n (r.entity_id =~ /^${vehicleName}_driver_temp/)\n )\n\nfrom(bucket: \"homeassistant\")\n |> range(start: date.sub(d: duration(v: extend_duration_ns), from: v.timeRangeStart), stop: v.timeRangeStop)\n |> filter(fn: (r) => r.entity_id =~ /^(${vehicleName}_)|(boulder_temp)/ and r._field == \"value\")\n |> filter(fn: filterEntities)\n |> aggregateWindow(every: v.windowPeriod, fn: max)\n |> filter(fn: (r) => exists r._value)\n |> pivot(rowKey:[\"_time\"],columnKey:[\"entity_id\"],valueColumn: \"_value\")\n |> keep(columns: [\"_time\",\"${vehicleName}_cabin_temperature\",\"${vehicleName}_driver_temperature\",\"boulder_temp\"])\n |> rename(columns: {${vehicleName}_cabin_temperature: \"Cabin Temp\", ${vehicleName}_driver_temperature: \"Temp Set Point\", boulder_temp: \"Boulder Temp\"})\n", | |
"refId": "A" | |
} | |
], | |
"title": "Temps (F)", | |
"type": "timeseries" | |
} | |
], | |
"schemaVersion": 39, | |
"tags": [], | |
"templating": { | |
"list": [ | |
{ | |
"current": { | |
"selected": false, | |
"text": "sulley", | |
"value": "sulley" | |
}, | |
"hide": 0, | |
"includeAll": false, | |
"label": "Name of Vehicle", | |
"multi": false, | |
"name": "vehicleName", | |
"options": [ | |
{ | |
"selected": true, | |
"text": "sulley", | |
"value": "sulley" | |
} | |
], | |
"query": "sulley", | |
"queryValue": "", | |
"skipUrlSync": false, | |
"type": "custom" | |
} | |
] | |
}, | |
"time": { | |
"from": "now-7d", | |
"to": "now" | |
}, | |
"timepicker": {}, | |
"timezone": "", | |
"title": "Sulley - Stats", | |
"uid": "3442245", | |
"version": 146, | |
"weekStart": "" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment