Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable use of multiple shelly plugs #346

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ So that's what this is.

Other features:

- **Shelly Plug Monitoring**: Installs a [`shelly-plug-prometheus` exporter](https://github.com/geerlingguy/shelly-plug-prometheus) and a Grafana dashboard, which tracks and displays power usage on a Shelly Plug running on the local network. (Disabled by default. Enable and configure using the `shelly_plug_*` vars in `config.yml`.)
- **Shelly Plug Monitoring**: Installs a [`shelly-plug-prometheus` exporter](https://github.com/geerlingguy/shelly-plug-prometheus) and a Grafana dashboard, which tracks and displays power usage on one or more Shelly Plugs running on the local network. (Disabled by default. Enable and configure using the `shelly_plugs_*` vars in `config.yml`.)
- **AirGradient Monitoring**: Configures [`airgradient-prometheus`](https://github.com/geerlingguy/airgradient-prometheus) and a Grafana dashboard, which tracks and displays air quality over time via one or more AirGradient DIY monitors. (Disabled by default. Enable and configure using the `airgradient_enable` var in `config.yml`. See example configuration for ability to monitor multiple AirGradient DIY stations.)
- **Starlink Monitoring**: Installs a [`starlink` prometheus exporter](https://github.com/danopstech/starlink_exporter) and a Grafana dashboard, which tracks and displays Starlink statistics. (Disabled by default. Enable and configure using the `starlink_enable` var in `config.yml`.)

Expand Down
11 changes: 7 additions & 4 deletions example.config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,13 @@ monitoring_ping_hosts: # [URL];[HUMAN_READABLE_NAME]
- https://www.apple.com/;apple.com

# Shelly Plug configuration. (Also requires `monitoring_enable`)
shelly_plug_enable: false
shelly_plug_hostname: my-shelly-plug-host-or-ip
shelly_plug_http_username: username
shelly_plug_http_password: "password"
shelly_plugs_enable: false
shelly_plugs: # list of Shelly Plugs to connect to
- name: my-shelly-plug # will show up in dashboard to identify this plug
hostname: "my-shelly-plug-host-or-ip"
port: 9924
shelly_plugs_http_username: username
shelly_plugs_http_password: "password"

# AirGradient configuration. (Also requires `monitoring_enable`)
airgradient_enable: false
Expand Down
200 changes: 112 additions & 88 deletions files/power-consumption.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,33 @@
"hide": true,
"iconColor": "rgba(0, 211, 255, 1)",
"name": "Annotations & Alerts",
"target": {
"limit": 100,
"matchAny": false,
"tags": [],
"type": "dashboard"
},
"type": "dashboard"
}
]
},
"editable": true,
"gnetId": null,
"fiscalYearStartMonth": 0,
"graphTooltip": 0,
"id": 2,
"links": [],
"liveNow": false,
"panels": [
{
"datasource": "prometheus",
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"description": "",
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {},
"mappings": [],
"max": 500,
"min": 0,
Expand Down Expand Up @@ -59,6 +67,7 @@
},
"id": 6,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"lastNotNull"
Expand All @@ -70,12 +79,17 @@
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "7.4.5",
"pluginVersion": "8.4.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"exemplar": false,
"expr": "power",
"interval": "",
"legendFormat": "Watts",
"legendFormat": "{{job}}",
"queryType": "randomWalk",
"refId": "A"
}
Expand All @@ -84,13 +98,15 @@
"type": "gauge"
},
{
"datasource": "prometheus",
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"fieldConfig": {
"defaults": {
"color": {
"mode": "thresholds"
},
"custom": {},
"mappings": [],
"max": 500,
"min": 0,
Expand Down Expand Up @@ -123,6 +139,7 @@
},
"id": 4,
"options": {
"orientation": "auto",
"reduceOptions": {
"calcs": [
"mean"
Expand All @@ -134,12 +151,17 @@
"showThresholdMarkers": true,
"text": {}
},
"pluginVersion": "7.4.5",
"pluginVersion": "8.4.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"exemplar": false,
"expr": "power",
"interval": "",
"legendFormat": "Watts",
"legendFormat": "{{job}}",
"queryType": "randomWalk",
"refId": "A"
}
Expand All @@ -148,110 +170,111 @@
"type": "gauge"
},
{
"aliasColors": {},
"bars": false,
"dashLength": 10,
"dashes": false,
"datasource": "prometheus",
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"description": "",
"fieldConfig": {
"defaults": {
"custom": {},
"color": {
"mode": "palette-classic"
},
"custom": {
"axisLabel": "",
"axisPlacement": "auto",
"barAlignment": 0,
"drawStyle": "line",
"fillOpacity": 10,
"gradientMode": "none",
"hideFrom": {
"legend": false,
"tooltip": false,
"viz": false
},
"lineInterpolation": "linear",
"lineWidth": 1,
"pointSize": 3,
"scaleDistribution": {
"type": "linear"
},
"showPoints": "always",
"spanNulls": true,
"stacking": {
"group": "A",
"mode": "none"
},
"thresholdsStyle": {
"mode": "line"
}
},
"mappings": [],
"min": 0,
"thresholds": {
"mode": "absolute",
"steps": [
{
"color": "green",
"value": null
},
{
"color": "dark-yellow",
"value": 2000
},
{
"color": "dark-red",
"value": 2500
}
]
},
"unit": "watt"
},
"overrides": []
},
"fill": 1,
"fillGradient": 0,
"gridPos": {
"h": 8,
"h": 10,
"w": 24,
"x": 0,
"y": 8
},
"hiddenSeries": false,
"id": 2,
"legend": {
"avg": false,
"current": false,
"max": false,
"min": false,
"show": false,
"total": false,
"values": false
},
"lines": true,
"linewidth": 1,
"nullPointMode": "null",
"options": {
"alertThreshold": true
"legend": {
"calcs": [
"min",
"mean",
"max",
"lastNotNull"
],
"displayMode": "table",
"placement": "bottom"
},
"tooltip": {
"mode": "multi",
"sort": "none"
}
},
"percentage": false,
"pluginVersion": "7.4.5",
"pointradius": 1,
"points": true,
"renderer": "flot",
"seriesOverrides": [],
"spaceLength": 10,
"stack": false,
"steppedLine": false,
"pluginVersion": "8.4.2",
"targets": [
{
"datasource": {
"type": "prometheus",
"uid": "P1809F7CD0C75ACF3"
},
"exemplar": true,
"expr": "power",
"interval": "",
"legendFormat": "Watts",
"legendFormat": "{{job}}",
"queryType": "randomWalk",
"refId": "A"
}
],
"thresholds": [],
"timeFrom": null,
"timeRegions": [],
"timeShift": null,
"title": "Power Consumption",
"tooltip": {
"shared": true,
"sort": 0,
"value_type": "individual"
},
"type": "graph",
"xaxis": {
"buckets": null,
"mode": "time",
"name": null,
"show": true,
"values": []
},
"yaxes": [
{
"$$hashKey": "object:169",
"decimals": null,
"format": "watt",
"label": null,
"logBase": 1,
"max": null,
"min": "0",
"show": true
},
{
"$$hashKey": "object:170",
"decimals": null,
"format": "short",
"label": null,
"logBase": 1,
"max": null,
"min": null,
"show": true
}
],
"yaxis": {
"align": false,
"alignLevel": null
}
"type": "timeseries"
}
],
"refresh": "5m",
"schemaVersion": 27,
"schemaVersion": 35,
"style": "dark",
"tags": [
"power"
Expand All @@ -267,5 +290,6 @@
"timezone": "",
"title": "Power consumption",
"uid": "i_aeo-uMz",
"version": 3
"version": 1,
"weekStart": ""
}
2 changes: 1 addition & 1 deletion main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

- name: Set up Shelly Plug Monitoring.
ansible.builtin.import_tasks: tasks/shelly-plug.yml
when: shelly_plug_enable
when: shelly_plugs_enable

- name: Set up Air Gradient Monitoring.
ansible.builtin.import_tasks: tasks/airgradient.yml
Expand Down
8 changes: 5 additions & 3 deletions templates/prometheus.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ scrape_configs:
static_configs:
- targets: ['speedtest:9798']

{% if shelly_plug_enable %}
- job_name: 'shelly-plug'
{% if shelly_plugs_enable %}
{% for plug in shelly_plugs %}
- job_name: '{{ plug.name }}'
metrics_path: /metrics
scrape_interval: 1m
static_configs:
- targets: ['172.17.0.1:9924']
- targets: ['172.17.0.1:{{ plug.port }}']
{% endfor %}
{% endif %}

{% if airgradient_enable %}
Expand Down
14 changes: 8 additions & 6 deletions templates/shelly-plug-docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
version: "3"

services:
shelly-plug:
container_name: shelly-plug
{% for plug in shelly_plugs %}
shelly-plug-{{ plug.name }}:
container_name: shelly-plug-{{ plug.name }}
image: php:8-apache
ports:
- "9924:80"
- "{{ plug.port }}:80"
environment:
SHELLY_HOSTNAME: '{{ shelly_plug_hostname }}'
SHELLY_HTTP_USERNAME: '{{ shelly_plug_http_username }}'
SHELLY_HTTP_PASSWORD: '{{ shelly_plug_http_password }}'
SHELLY_HOSTNAME: '{{ plug.hostname }}'
SHELLY_HTTP_USERNAME: '{{ shelly_plugs_http_username }}'
SHELLY_HTTP_PASSWORD: '{{ shelly_plugs_http_password }}'
volumes:
- './:/var/www/html'
restart: unless-stopped
{% endfor %}