Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonacox committed Apr 2, 2023
2 parents d24ae50 + 95868e7 commit e623d4c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 29 deletions.
19 changes: 5 additions & 14 deletions tools/influxdb2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ This includes optionals files and instructions to help setup InfluxDB 2.x (inste
* Host Path: /var/lib/grafana TO wherever you want to store your Grafana config and plugins (So its not stored in the container)
* Variable: GF_SERVER_ROOT_URL | http://xxx.xxx.xxx.xxx (Your localhost IP)
* Variable: GF_SECURITY_ADMIN_PASSWORD | Sup3rSecr3t (admin account password)
* Variable: GF_PATHS_CONFIG | /etc/grafana/grafana.ini (location of config file within container)
* Host Path: /etc/grafana/grafana.ini TO wherever you want to store your Grafana config (So its not stored in the container)
* Variable: GF_PANELS_DISABLE_SANITIZE_HTML | true (allow html code for tesla graphic)
* Variable: GF_INSTALL_PLUGINS | yesoreyeram-boomtable-panel, fetzerch-sunandmoon-datasource (auto install required plugins)

## Configure containers
* InfluxDB 2.x
Expand All @@ -54,7 +54,7 @@ This includes optionals files and instructions to help setup InfluxDB 2.x (inste
* At this time not all data is aggregated, everything used for current reporting is aggregated to tesla_energy, set a retention policy respective of how much data you want to keep (its stored at 5s intervals from pyPowerwall)
* tesla_energy (For aggregate date from raw_tesla_energy, also primary source for tesla data on the dashboard)
* Aggregate data (@1m intervals) from raw_tesla_energy, do not set a retention policy if you want to keep historical data.
* Generate the following API tokens. Each a sperate tokens unless specified together. API tokens are only displayed at creatiion and need to be recreated if lost.
* Generate the following API tokens in the Web UI. Each a sperate tokens unless specified together. API tokens are only displayed at creatiion and need to be recreated if lost.
* Write
* raw_weather (for weather 411)
* raw_tesla_energy (for Telegraf capturing pyPowerwall)
Expand All @@ -71,20 +71,11 @@ This includes optionals files and instructions to help setup InfluxDB 2.x (inste
* Telegraf
* Edit telegraf.conf file with your server information and Write API token for raw_tesla_energy from above. Ensure it is saved where you specfied above.
* Grafana (http://IP:3000/)
* grafana.ini
* Get the sample file from: https://github.com/grafana/grafana/blob/main/conf/sample.ini
* Save this file as grafana.ini in the location you specified
* Allow html
* In the grafana.ini file, find and edit:
* ;disable_sanitize_html = false TO disable_sanitize_html = true
* Add data sources in configuration
* Add data sources in configuration (Grafana web UI)
* Enter the URL of your influxdb: http://IP:8086
* Enter the Organization you created
* Default Bucket: tesla_energy
* Add plugins in configuration
* Search for and install: Sun and Moon (By fetzerch)
* Search for and install: Boom Table (By yesoreyeram)
* Dashboard
* Dashboard (Grafana web UI)
* Import grafana dashboard json file

## Discussion Link
Expand Down
26 changes: 26 additions & 0 deletions tools/influxdb2/flux/tesla_energy.strings.flux
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import "date"
import "regexp"

option task = {name: "tesla_energy.strings", every: 1m}

data =
from(bucket: "raw_tesla_energy")
//for historical generation change start here, otherwise use -2m for previous minute final total
|> range(start: date.truncate(t: -2m, unit: 1m), stop: date.truncate(t: now(), unit: 1m))
|> filter(fn: (r) => r["_measurement"] == "http")

withoutnum =
data
|> filter(fn: (r) => r["_field"] =~ /\A[A-D]_.*/)
|> map(fn: (r) => ({r with _field: regexp.replaceAllString(v: r._field, r: /_/, t: "0_")}))

withnum =
data
|> filter(fn: (r) => r["_field"] =~ /\A[A-D][1-99]_.*/)

union(tables: [withoutnum, withnum])
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)
|> drop(columns: ["host", "month", "url", "year"])
|> map(fn: (r) => ({r with _measurement: "strings"}))
|> drop(columns: ["_start", "_stop"])
|> to(bucket: "tesla_energy")
34 changes: 34 additions & 0 deletions tools/influxdb2/flux/tesla_energy.vitals.flux
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import "date"
import "regexp"
option task = {
name: "tesla_energy.vitals",
every: 1m,
}

data = from(bucket: "raw_tesla_energy")
//for historical generation change start here, otherwise use -2m for previous minute final total
|> range(start: date.truncate(t: -2m, unit: 1m), stop: date.truncate(t: now(), unit: 1m))
|> filter(fn: (r) => r["_measurement"] == "http")
|> drop(columns: ["host", "month", "url", "year"])

pinv = data
|> filter(fn: (r) => r["_field"] =~ /PW[0-99]_PINV/)
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)

island = data
|> filter(fn: (r) => r["_field"] =~ /ISLAND_/)
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)

meter = data
|> filter(fn: (r) => r["_field"] =~ /METER_/)
|> filter(fn: (r) => r["_field"] !~ /.*Life/)
|> aggregateWindow(every: 1m, fn: mean, createEmpty: false)

life = data
|> filter(fn: (r) => r["_field"] =~ /_Life/)
|> aggregateWindow(every: 1m, fn: last, createEmpty: false)

union(tables: [pinv, island, meter, life])
|> drop(columns: ["_start", "_stop"])
|> map(fn: (r) => ({r with _measurement: "vitals"}))
|> to(bucket: "tesla_energy")
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@
},
"gridPos": {
"h": 13,
"w": 17,
"w": 16,
"x": 0,
"y": 1
},
Expand Down Expand Up @@ -610,18 +610,18 @@
},
"gridPos": {
"h": 10,
"w": 7,
"x": 17,
"w": 8,
"x": 16,
"y": 1
},
"id": 4,
"id": 62,
"options": {
"code": {
"language": "plaintext",
"showLineNumbers": false,
"showMiniMap": false
},
"content": "<style>\n.powerDiv {\n width: 100%;\n height: 100%;\n position: absolute;\n left: 50%;\n top: 50%;\n }\n.firmwareDiv {\n width: 100%;\n position: absolute;\n text-align: center;\n left: 0%;\n bottom: 0%;\n }\n.powerFrame {\n width: 500px;\n height: 300px;\n transform: scale(0);\n transform-origin: 0 0;\n position: absolute;\n left: 0;\n top: 0;\n border-style: none;\n }\n</style>\n<div class=\"powerDiv\">\n <iframe id=\"frame8675\" class=\"powerFrame\" src=\"/public/img/grafana_icon.svg\" onload=\"scale(this)\">IFRAME not supported by browser.</iframe>\n <script>\n document.getElementById('frame8675').parentElement.parentElement.parentElement.style.overflow = 'hidden';\n </script>\n</div>\n<div class=\"firmwareDiv\">\n <p class=\"version\" style=\"color:gray; text-align: bottom\">Firmware</p>\n</div>\n<script>\n// Scale Animation when Window is Resized\nfunction scale() {\n document.querySelectorAll('.powerFrame').forEach(scaled => {\n parent = scaled.parentNode;\n ratio = 1.2 * Math.min((parent.offsetWidth / scaled.offsetWidth), (parent.offsetHeight / scaled.offsetHeight));\n if (ratio > 1.0) ratio = 1.0;\n scaled.style.transform = 'scale(' + ratio + ') translate(-50%, -50%)';\n scaled.style.transformOrigin = 'top left';\n })\n}\nwindow.addEventListener('resize', function(e){ scale(); }, false);\n\n// Display Firmware Version\nfunction showversion() {\n var pwver = window.location.protocol + \"//\" + window.location.hostname + \":8675/version\";\n $.getJSON(pwver, function(data) {\n var text = `Firmware: ${data.version.split(\" \")[0]}`;\n $(\".version\").html(text);\n });\n setTimeout(showversion, 60000);\n}\nshowversion();\n\n// Load Animation from pyPowerwall\nvar pwurl = window.location.protocol + \"//\" + window.location.hostname + \":8675/\";\ndocument.getElementById('frame8675').src = pwurl;\n\n</script>",
"content": "<style>\ndiv.powerDiv {\n width: 100%;\n height: 100%;\n overflow: hidden;\n }\ndiv.firmwareDiv {\n width: 100%;\n position: absolute;\n text-align: center;\n left: 0;\n bottom: 0;\n overflow: hidden;\n }\niframe.powerFrame {\n width: 500px;\n height: 300px;\n transform: scale(0);\n transform-origin: center;\n position: absolute;\n left: 50%;\n top: 50%;\n border-style: none;\n }\n</style>\n<div class=\"powerDiv\">\n <iframe id=\"frame8675\" class=\"powerFrame\" src=\"/public/img/grafana_icon.svg\" onload=\"scale(this)\">IFRAME not supported by browser.</iframe>\n <script>\n document.getElementById('frame8675').parentElement.parentElement.parentElement.style.overflow = 'hidden';\n </script>\n</div>\n<div class=\"firmwareDiv\">\n <p class=\"version\" style=\"color:gray; text-align: bottom\">Firmware</p>\n</div>\n<script>\n// Scale Animation when Window is Resized\nfunction scale() {\n document.querySelectorAll('.powerFrame').forEach(scaled => {\n parent = scaled.parentNode;\n ratio = Math.min(1, 1.2 * (parent.offsetWidth / scaled.offsetWidth), (parent.offsetHeight / scaled.offsetHeight));\n scaled.style.transform = 'translate(-50%, -50%) scale(' + ratio + ')';\n })\n}\nwindow.addEventListener('resize', function(e){ scale(); }, false);\n\n// Display Firmware Version\nfunction showversion() {\n var pwver = window.location.protocol + \"//\" + window.location.hostname + \":8675/version\";\n $.getJSON(pwver, function(data) {\n var text = `Firmware: ${data.version.split(\" \")[0]}`;\n $(\".version\").html(text);\n });\n setTimeout(showversion, 60000);\n}\nshowversion();\n\n// Load Animation from pyPowerwall\nvar pwurl = window.location.protocol + \"//\" + window.location.hostname + \":8675/\";\ndocument.getElementById('frame8675').src = pwurl;\n</script>",
"mode": "html"
},
"pluginVersion": "9.4.7",
Expand Down Expand Up @@ -717,8 +717,8 @@
},
"gridPos": {
"h": 3,
"w": 5,
"x": 18,
"w": 6,
"x": 17,
"y": 11
},
"id": 6,
Expand Down Expand Up @@ -1690,7 +1690,7 @@
"type": "piechart"
},
{
"activePatternIndex": 2,
"activePatternIndex": 0,
"datasource": {
"type": "influxdb",
"uid": "${DS_INFLUXDB}"
Expand Down Expand Up @@ -1769,11 +1769,11 @@
"value_below": ""
},
"format": "kwatt",
"name": "Home",
"name": "Grid",
"null_color": "darkred",
"null_textcolor": "black",
"null_value": "No data",
"pattern": "Home",
"pattern": "Grid",
"row_col_wrapper": "_",
"row_name": "_1_",
"textColors": "white | white | white",
Expand Down Expand Up @@ -1973,7 +1973,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down Expand Up @@ -2065,7 +2066,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down Expand Up @@ -2157,7 +2159,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down Expand Up @@ -2249,7 +2252,8 @@
"mode": "absolute",
"steps": [
{
"color": "green"
"color": "green",
"value": null
},
{
"color": "red",
Expand Down Expand Up @@ -4621,6 +4625,6 @@
"timezone": "",
"title": "Tesla Energy",
"uid": "yDBrTi-4k",
"version": 61,
"version": 65,
"weekStart": "monday"
}

0 comments on commit e623d4c

Please sign in to comment.