diff --git a/nixos/tako/services/homeassistant.json b/nixos/tako/services/homeassistant.json new file mode 100644 --- /dev/null +++ b/nixos/tako/services/homeassistant.json @@ -0,0 +1,153 @@ +{ + "annotations": {"list": []}, + "editable": true, + "fiscalYearStartMonth": 0, + "graphTooltip": 0, + "id": null, + "links": [], + "liveNow": false, + "panels": [ + { + "type": "timeseries", + "title": "Plug power", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 0}, + "id": 1, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "watt", "custom": {"drawStyle": "line", "lineInterpolation": "smooth", "fillOpacity": 10, "showPoints": "never"}}, "overrides": []}, + "options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull", "max"]}, "tooltip": {"mode": "multi"}}, + "targets": [ + {"expr": "hass_sensor_power_w{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "refId": "A"} + ] + }, + { + "type": "timeseries", + "title": "Plug current", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 0}, + "id": 2, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "amp", "custom": {"drawStyle": "line", "lineInterpolation": "smooth", "fillOpacity": 10, "showPoints": "never"}}, "overrides": []}, + "options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull", "max"]}, "tooltip": {"mode": "multi"}}, + "targets": [ + {"expr": "hass_sensor_current_a{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "refId": "A"} + ] + }, + { + "type": "timeseries", + "title": "Temperatures", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 16}, + "id": 3, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "celsius", "custom": {"drawStyle": "line", "lineInterpolation": "smooth", "fillOpacity": 10, "showPoints": "never"}}, "overrides": []}, + "options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull", "max"]}, "tooltip": {"mode": "multi"}}, + "targets": [ + {"expr": "hass_sensor_temperature_celsius{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Battery levels", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 16}, + "id": 4, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100, "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "red"}, {"color": "yellow", "value": 25}, {"color": "green", "value": 50}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_sensor_battery_percent{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Energy today", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 8}, + "id": 5, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "kwatth", "min": 0, "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "green"}, {"color": "yellow", "value": 2}, {"color": "red", "value": 10}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_sensor_energy_kwh{job=\"tsuba-homeassistant\", friendly_name=~\".*Today.*\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Energy this month", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 8}, + "id": 6, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "kwatth", "min": 0, "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "green"}, {"color": "yellow", "value": 50}, {"color": "red", "value": 300}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_sensor_energy_kwh{job=\"tsuba-homeassistant\", friendly_name=~\".*month.*\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + }, + { + "type": "timeseries", + "title": "Plug voltage", + "gridPos": {"h": 8, "w": 12, "x": 0, "y": 24}, + "id": 7, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "volt", "custom": {"drawStyle": "line", "lineInterpolation": "smooth", "fillOpacity": 10, "showPoints": "never"}}, "overrides": []}, + "options": {"legend": {"displayMode": "table", "placement": "right", "calcs": ["lastNotNull", "min", "max"]}, "tooltip": {"mode": "multi"}}, + "targets": [ + {"expr": "hass_sensor_voltage_v{job=\"tsuba-homeassistant\", entity=~\"sensor\\\\.(bedside_port|tapo_p110|ac|bambu_lab)_voltage\"}", "legendFormat": "{{friendly_name}}", "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Light brightness", + "gridPos": {"h": 8, "w": 12, "x": 12, "y": 24}, + "id": 8, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "percent", "min": 0, "max": 100, "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "green"}, {"color": "yellow", "value": 70}, {"color": "blue", "value": 100}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_light_brightness_percent{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Humidity", + "gridPos": {"h": 5, "w": 12, "x": 0, "y": 32}, + "id": 9, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "percent", "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "yellow"}, {"color": "green", "value": 30}, {"color": "yellow", "value": 65}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_sensor_humidity_percent{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + }, + { + "type": "stat", + "title": "Wi-Fi signal", + "gridPos": {"h": 5, "w": 12, "x": 12, "y": 32}, + "id": 10, + "datasource": {"type": "prometheus", "uid": "${datasource}"}, + "fieldConfig": {"defaults": {"unit": "dBm", "color": {"mode": "thresholds"}, "thresholds": {"mode": "absolute", "steps": [{"color": "red"}, {"color": "yellow", "value": -75}, {"color": "green", "value": -60}]}}, "overrides": []}, + "options": {"colorMode": "value", "graphMode": "area", "justifyMode": "center", "orientation": "horizontal", "reduceOptions": {"calcs": ["lastNotNull"], "fields": "", "values": false}, "textMode": "auto"}, + "targets": [ + {"expr": "hass_sensor_signal_strength_dbm{job=\"tsuba-homeassistant\"}", "legendFormat": "{{friendly_name}}", "instant": true, "refId": "A"} + ] + } + ], + "refresh": "30s", + "schemaVersion": 39, + "tags": ["homeassistant", "tsuba"], + "templating": { + "list": [ + { + "name": "datasource", + "type": "datasource", + "query": "prometheus", + "current": {"text": "Prometheus", "value": "Prometheus"}, + "hide": 0, + "label": "Datasource" + } + ] + }, + "time": {"from": "now-6h", "to": "now"}, + "timepicker": {}, + "timezone": "", + "title": "Home Assistant", + "uid": "homeassistant", + "version": 1, + "weekStart": "" +} diff --git a/nixos/tako/services/monitoring.nix b/nixos/tako/services/monitoring.nix --- a/nixos/tako/services/monitoring.nix +++ b/nixos/tako/services/monitoring.nix @@ -43,6 +43,7 @@ "grafana/oidc/client_secret" = { key = "authelia/oidc/grafana/client_secret_plain"; owner = "grafana"; }; + "homeassistant/cli-token".owner = "prometheus"; }; # Grafana configuration with Authelia OIDC @@ -193,6 +194,7 @@ # Central Prometheus server services.prometheus = { enable = true; port = ports.prometheus; + checkConfig = "syntax-only"; # Retention settings (90 days) retentionTime = "90d"; @@ -382,7 +384,6 @@ static_configs = [ { targets = [ "tsuba:8096" # jellyfin (built-in /metrics endpoint) - # "tsuba:8123" # homeassistant (configure prometheus integration) "tsuba:9617" # pihole-exporter ]; labels = { @@ -399,12 +400,25 @@ regex = "tsuba:8096"; target_label = "__metrics_path__"; replacement = "/metrics"; } - # { - # source_labels = ["__address__"]; - # regex = "tsuba:8123"; - # target_label = "__metrics_path__"; - # replacement = "/api/prometheus"; - # } + ]; + } + + # Home Assistant - tsuba + { + job_name = "tsuba-homeassistant"; + scrape_interval = "60s"; + metrics_path = "/api/prometheus"; + authorization.credentials_file = config.sops.secrets."homeassistant/cli-token".path; + scheme = "http"; + static_configs = [ + { + targets = ["tsuba:8123"]; + labels = { + instance = "tsuba"; + machine = "tsuba"; + service = "homeassistant"; + }; + } ]; } @@ -548,6 +562,7 @@ sha256 = "0ibqj1zlznxp9vpj1jf6vkq8hj6rg63v7kih7s9bilq5zgqj4l3v"; }; caddyDashboard = ./caddy.json; giteaDashboard = ./gitea.json; + homeassistantDashboard = ./homeassistant.json; homeDashboard = ./home.json; in [ "d /var/lib/grafana/dashboards 0755 grafana grafana -" @@ -560,6 +575,7 @@ "L+ /var/lib/grafana/dashboards/pihole.json - - - - ${piholeDashboard}" "L+ /var/lib/grafana/dashboards/harmonia.json - - - - ${harmoniaDashboard}" "L+ /var/lib/grafana/dashboards/caddy.json - - - - ${caddyDashboard}" "L+ /var/lib/grafana/dashboards/gitea.json - - - - ${giteaDashboard}" + "L+ /var/lib/grafana/dashboards/homeassistant.json - - - - ${homeassistantDashboard}" "L+ /var/lib/grafana/dashboards/home.json - - - - ${homeDashboard}" ];