Compare commits

..

No commits in common. "master" and "dev" have entirely different histories.
master ... dev

4 changed files with 27 additions and 387 deletions

View file

@ -129,4 +129,3 @@ Grafana can be used to create dashboard and visualise prometheus metrics. To ins
Grafana is accessible on port `:80`. Premade dashboards can be found in the `grafana/dashboards` folder. Grafana is accessible on port `:80`. Premade dashboards can be found in the `grafana/dashboards` folder.
![](./docs/grafana_dashboard.png) ![](./docs/grafana_dashboard.png)

View file

@ -73,17 +73,12 @@ class Bme680Sensor(Accessory):
if self.sensor.data.heat_stable: if self.sensor.data.heat_stable:
self._gas_resistance_metric.set(self.sensor.data.gas_resistance) self._gas_resistance_metric.set(self.sensor.data.gas_resistance)
logging.info(
f"T: {self.sensor.data.temperature}; H: {self.sensor.data.humidity}: P: {self.sensor.data.pressure}")
logging.info(f"G: {self.sensor.data.gas_resistance}")
@Accessory.run_at_interval(120) @Accessory.run_at_interval(120)
def run(self): def run(self):
""" """
This function runs the accessory. It polls for data and publishes it at the given interval. This function runs the accessory. It polls for data and publishes it at the given interval.
""" """
try: try:
logging.info("Reading data from BME680 sensor.")
self._run() self._run()
except IOError as e: except IOError as e:
# This happens from time to time, best we stop and let systemd restart us. # This happens from time to time, best we stop and let systemd restart us.

View file

@ -27,10 +27,10 @@ class Pms5003Sensor(Accessory):
"pms5003_pm_ug_per_m3_1", "The PM1.0 ug/m3 (ultrafine particles)." "pms5003_pm_ug_per_m3_1", "The PM1.0 ug/m3 (ultrafine particles)."
) )
self._pms5003_pm_ug_per_m3_2 = Gauge( self._pms5003_pm_ug_per_m3_2 = Gauge(
"pms5003_pm_ug_per_m3_2", "PM2.5 ug/m3 (combustion particles, organic compounds, metals)." "pms5003_pm_ug_per_m3_1", "PM2.5 ug/m3 (combustion particles, organic compounds, metals)."
) )
self._pms5003_pm_ug_per_m3_10 = Gauge( self._pms5003_pm_ug_per_m3_10 = Gauge(
"pms5003_pm_ug_per_m3_10", "PM10 ug/m3 (dust, pollen, mould spores)" "pms5003_pm_ug_per_m3_1", "PM10 ug/m3 (dust, pollen, mould spores)"
) )
@Accessory.run_at_interval(120) @Accessory.run_at_interval(120)
@ -39,14 +39,11 @@ class Pms5003Sensor(Accessory):
This function runs the accessory. It polls for data and updates prometheus metrics. This function runs the accessory. It polls for data and updates prometheus metrics.
""" """
try: try:
logging.info("Reading data from PMS5003 sensor.")
data = self.sensor.read() data = self.sensor.read()
self._pms5003_pm_ug_per_m3_1.set(data.pm_ug_per_m3(1.0)) self._pms5003_pm_ug_per_m3_1.set(data.pm_ug_per_m3(1.0))
self._pms5003_pm_ug_per_m3_2.set(data.pm_ug_per_m3(2.5)) self._pms5003_pm_ug_per_m3_2.set(data.pm_ug_per_m3(2.5))
self._pms5003_pm_ug_per_m3_10.set(data.pm_ug_per_m3(10)) self._pms5003_pm_ug_per_m3_10.set(data.pm_ug_per_m3(10))
logging.info(f"PM1.0 {data.pm_ug_per_m3(1.0)} PM2.5 {data.pm_ug_per_m3(2.5)} PM10 {data.pm_ug_per_m3(10)}")
except IOError as e: except IOError as e:
# This happens from time to time, best we stop and let systemd restart us. # This happens from time to time, best we stop and let systemd restart us.
logging.critical("Failed to read data from serial.") logging.critical("Failed to read data from serial.")

View file

@ -2,20 +2,20 @@
"__inputs": [ "__inputs": [
{ {
"name": "DS_PROMETHEUS", "name": "DS_PROMETHEUS",
"label": "prometheus", "label": "Prometheus",
"description": "", "description": "",
"type": "datasource", "type": "datasource",
"pluginId": "prometheus", "pluginId": "prometheus",
"pluginName": "Prometheus" "pluginName": "Prometheus"
} }
], ],
"__elements": {}, "__elements": [],
"__requires": [ "__requires": [
{ {
"type": "grafana", "type": "grafana",
"id": "grafana", "id": "grafana",
"name": "Grafana", "name": "Grafana",
"version": "10.3.1" "version": "8.5.5"
}, },
{ {
"type": "datasource", "type": "datasource",
@ -65,324 +65,6 @@
"links": [], "links": [],
"liveNow": true, "liveNow": true,
"panels": [ "panels": [
{
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 0
},
"id": 14,
"title": "Air Quality",
"type": "row"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"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": "linear",
"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
}
]
},
"unit": "ug/m3",
"unitScale": false
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 7,
"x": 0,
"y": 1
},
"id": 11,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "pms5003_pm_ug_per_m3_1{instance=\"localhost:8000\"}",
"instant": false,
"legendFormat": "Measurement",
"range": true,
"refId": "A"
}
],
"title": "PM1.0 ug/m3 (ultrafine particles)",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"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": "linear",
"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
}
]
},
"unit": "ug/m3",
"unitScale": false
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 8,
"x": 7,
"y": 1
},
"id": 12,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "pms5003_pm_ug_per_m3_2{instance=\"localhost:8000\"}",
"instant": false,
"legendFormat": "Measurement",
"range": true,
"refId": "A"
}
],
"title": "PM2.5 ug/m3 (combustion particles, organic compounds, metals).",
"type": "timeseries"
},
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"description": "",
"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": "linear",
"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
}
]
},
"unit": "ug/m3",
"unitScale": false
},
"overrides": []
},
"gridPos": {
"h": 8,
"w": 9,
"x": 15,
"y": 1
},
"id": 13,
"options": {
"legend": {
"calcs": [],
"displayMode": "list",
"placement": "bottom",
"showLegend": true
},
"tooltip": {
"mode": "single",
"sort": "none"
}
},
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "${DS_PROMETHEUS}"
},
"editorMode": "code",
"expr": "pms5003_pm_ug_per_m3_10{instance=\"localhost:8000\"}",
"instant": false,
"legendFormat": "Measurement",
"range": true,
"refId": "A"
}
],
"title": "PM10 ug/m3 (dust, pollen, mould spores)",
"type": "timeseries"
},
{
"collapsed": false,
"gridPos": {
"h": 1,
"w": 24,
"x": 0,
"y": 9
},
"id": 10,
"panels": [],
"title": "Climate Sensor",
"type": "row"
},
{ {
"datasource": { "datasource": {
"type": "prometheus", "type": "prometheus",
@ -403,8 +85,7 @@
} }
] ]
}, },
"unit": "celsius", "unit": "celsius"
"unitScale": true
}, },
"overrides": [] "overrides": []
}, },
@ -412,7 +93,7 @@
"h": 4, "h": 4,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 10 "y": 0
}, },
"id": 8, "id": 8,
"options": { "options": {
@ -427,11 +108,9 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"showPercentChange": false, "textMode": "auto"
"textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "10.3.1", "pluginVersion": "8.5.5",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -465,8 +144,7 @@
} }
] ]
}, },
"unit": "humidity", "unit": "humidity"
"unitScale": true
}, },
"overrides": [] "overrides": []
}, },
@ -474,7 +152,7 @@
"h": 4, "h": 4,
"w": 12, "w": 12,
"x": 12, "x": 12,
"y": 10 "y": 0
}, },
"id": 9, "id": 9,
"options": { "options": {
@ -489,11 +167,9 @@
"fields": "", "fields": "",
"values": false "values": false
}, },
"showPercentChange": false, "textMode": "auto"
"textMode": "auto",
"wideLayout": true
}, },
"pluginVersion": "10.3.1", "pluginVersion": "8.5.5",
"targets": [ "targets": [
{ {
"datasource": { "datasource": {
@ -518,9 +194,6 @@
"mode": "palette-classic" "mode": "palette-classic"
}, },
"custom": { "custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
@ -532,7 +205,6 @@
"tooltip": false, "tooltip": false,
"viz": false "viz": false
}, },
"insertNulls": false,
"lineInterpolation": "linear", "lineInterpolation": "linear",
"lineWidth": 1, "lineWidth": 1,
"pointSize": 5, "pointSize": 5,
@ -563,8 +235,7 @@
} }
] ]
}, },
"unit": "celsius", "unit": "celsius"
"unitScale": true
}, },
"overrides": [] "overrides": []
}, },
@ -572,15 +243,14 @@
"h": 10, "h": 10,
"w": 12, "w": 12,
"x": 0, "x": 0,
"y": 14 "y": 4
}, },
"id": 2, "id": 2,
"options": { "options": {
"legend": { "legend": {
"calcs": [], "calcs": [],
"displayMode": "list", "displayMode": "list",
"placement": "bottom", "placement": "bottom"
"showLegend": true
}, },
"tooltip": { "tooltip": {
"mode": "single", "mode": "single",
@ -593,10 +263,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${DS_PROMETHEUS}" "uid": "${DS_PROMETHEUS}"
}, },
"editorMode": "code",
"expr": "bme680_temperature_celsius{}", "expr": "bme680_temperature_celsius{}",
"legendFormat": "Temperature",
"range": true,
"refId": "A" "refId": "A"
} }
], ],
@ -614,9 +281,6 @@
"mode": "palette-classic" "mode": "palette-classic"
}, },
"custom": { "custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
@ -628,7 +292,6 @@
"tooltip": false, "tooltip": false,
"viz": false "viz": false
}, },
"insertNulls": false,
"lineInterpolation": "linear", "lineInterpolation": "linear",
"lineWidth": 1, "lineWidth": 1,
"pointSize": 5, "pointSize": 5,
@ -659,8 +322,7 @@
} }
] ]
}, },
"unit": "humidity", "unit": "humidity"
"unitScale": true
}, },
"overrides": [] "overrides": []
}, },
@ -668,15 +330,14 @@
"h": 10, "h": 10,
"w": 12, "w": 12,
"x": 12, "x": 12,
"y": 14 "y": 4
}, },
"id": 4, "id": 4,
"options": { "options": {
"legend": { "legend": {
"calcs": [], "calcs": [],
"displayMode": "list", "displayMode": "list",
"placement": "bottom", "placement": "bottom"
"showLegend": true
}, },
"tooltip": { "tooltip": {
"mode": "single", "mode": "single",
@ -689,10 +350,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${DS_PROMETHEUS}" "uid": "${DS_PROMETHEUS}"
}, },
"editorMode": "code",
"expr": "bme680_humidity_rh{}", "expr": "bme680_humidity_rh{}",
"legendFormat": "Relative Humidity",
"range": true,
"refId": "A" "refId": "A"
} }
], ],
@ -710,9 +368,6 @@
"mode": "palette-classic" "mode": "palette-classic"
}, },
"custom": { "custom": {
"axisBorderShow": false,
"axisCenteredZero": false,
"axisColorMode": "text",
"axisLabel": "", "axisLabel": "",
"axisPlacement": "auto", "axisPlacement": "auto",
"barAlignment": 0, "barAlignment": 0,
@ -724,7 +379,6 @@
"tooltip": false, "tooltip": false,
"viz": false "viz": false
}, },
"insertNulls": false,
"lineInterpolation": "linear", "lineInterpolation": "linear",
"lineWidth": 1, "lineWidth": 1,
"pointSize": 5, "pointSize": 5,
@ -755,24 +409,22 @@
} }
] ]
}, },
"unit": "pressurehpa", "unit": "pressurehpa"
"unitScale": true
}, },
"overrides": [] "overrides": []
}, },
"gridPos": { "gridPos": {
"h": 10, "h": 11,
"w": 24, "w": 24,
"x": 0, "x": 0,
"y": 24 "y": 14
}, },
"id": 6, "id": 6,
"options": { "options": {
"legend": { "legend": {
"calcs": [], "calcs": [],
"displayMode": "list", "displayMode": "list",
"placement": "bottom", "placement": "bottom"
"showLegend": true
}, },
"tooltip": { "tooltip": {
"mode": "single", "mode": "single",
@ -785,10 +437,7 @@
"type": "prometheus", "type": "prometheus",
"uid": "${DS_PROMETHEUS}" "uid": "${DS_PROMETHEUS}"
}, },
"editorMode": "code",
"expr": "bme680_pressure_hpa{}", "expr": "bme680_pressure_hpa{}",
"legendFormat": "Pressure",
"range": true,
"refId": "A" "refId": "A"
} }
], ],
@ -796,20 +445,20 @@
"type": "timeseries" "type": "timeseries"
} }
], ],
"refresh": false, "schemaVersion": 36,
"schemaVersion": 39, "style": "dark",
"tags": [], "tags": [],
"templating": { "templating": {
"list": [] "list": []
}, },
"time": { "time": {
"from": "now-5m", "from": "now-30m",
"to": "now" "to": "now"
}, },
"timepicker": {}, "timepicker": {},
"timezone": "", "timezone": "",
"title": "Home", "title": "Home",
"uid": "snBE4Jj7z", "uid": "snBE4Jj7z",
"version": 4, "version": 5,
"weekStart": "" "weekStart": ""
} }