Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Metrics & Hacompanion — Metrics Collection & Home Assistant Integration

Purpose

Comprehensive metrics collection and integration with Home Assistant via hacompanion.

Entry Point

Options

services.metrics.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Metrics collection service.


services.metrics.hacompanion.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable Home Assistant Companion service.


services.metrics.hacompanion.script

Typeattribute set of (submodule)

This option has no description.


services.metrics.hacompanion.script.<name>.device_class

Typenull or one of "absolute_humidity", "apparent_power", "aqi", "area", "atmospheric_pressure", "battery", "blood_glucose_concentration", "carbon_dioxide", "carbon_monoxide", "current", "data_rate", "data_size", "date", "distance", "duration", "energy", "energy_distance", "energy_storage", "enum", "frequency", "gas", "humidity", "illuminance", "irradiance", "moisture", "monetary", "nitrogen_dioxide", "nitrogen_monoxide", "nitrous_oxide", "ozone", "ph", "pm1", "pm10", "pm25", "power", "power_factor", "precipitation", "precipitation_intensity", "pressure", "reactive_energy", "reactive_power", "signal_strength", "sound_pressure", "speed", "sulphur_dioxide", "temperature", "timestamp", "volatile_organic_compounds", "volatile_organic_compounds_parts", "voltage", "volume", "volume_flow_rate", "volume_storage", "water", "weight", "wind_direction", "wind_speed"
Defaultnull

The device class for the script in Home Assistant.


services.metrics.hacompanion.script.<name>.icon

Typestring
Default"mdi:script-text-outline"

The icon to use for the script in Home Assistant.


services.metrics.hacompanion.script.<name>.name

Typestring

The name of the script as it will appear in Home Assistant.


services.metrics.hacompanion.script.<name>.path

Typeabsolute path

The path to the script to execute.


services.metrics.hacompanion.script.<name>.type

Typeone of "sensor", "switch"
Default"sensor"

The type of the script in Home Assistant.


services.metrics.hacompanion.script.<name>.unit_of_measurement

Typenull or string
Defaultnull

The unit of measurement for the script in Home Assistant.


services.metrics.hacompanion.sensor.audio_volume.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the audio_volume sensor.


services.metrics.hacompanion.sensor.companion_running.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the companion_running sensor.


services.metrics.hacompanion.sensor.cpu_temp.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the cpu_temp sensor.


services.metrics.hacompanion.sensor.cpu_usage.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the cpu_usage sensor.


services.metrics.hacompanion.sensor.load_avg.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the load_avg sensor.


services.metrics.hacompanion.sensor.memory.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the memory sensor.


services.metrics.hacompanion.sensor.online_check.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the online_check sensor.


services.metrics.hacompanion.sensor.power.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the power sensor.


services.metrics.hacompanion.sensor.uptime.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the uptime sensor.


services.metrics.hacompanion.sensor.webcam.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable the webcam sensor.


services.metrics.hacompanion.storage

Typeattribute set of (submodule)
Default{ }

Storage devices and ZFS pools to monitor


services.metrics.hacompanion.storage.<name>.name

Typenull or string
Defaultnull

The pretty display name for this storage device in Home Assistant.


services.metrics.hacompanion.storage.<name>.sensors.avail

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable available space sensor.


services.metrics.hacompanion.storage.<name>.sensors.read

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable read speed sensor.


services.metrics.hacompanion.storage.<name>.sensors.temperature

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable temperature sensor.


services.metrics.hacompanion.storage.<name>.sensors.used

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable used space sensor.


services.metrics.hacompanion.storage.<name>.sensors.write

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable write speed sensor.


services.metrics.hacompanion.test

Typeanything
DefaulthacompanionConfig

This option has no description.


services.metrics.upgradeStatus.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable Upgrade Status service.


services.metrics.upgradeStatus.uptimeKuma.enable

Typeboolean
Defaultfalse
Exampletrue

Whether to enable Enable Uptime Kuma tracking for Upgrade Status.


Architecture / Services / Scope

  • hacompanion — Home Assistant companion daemon that publishes system sensors (CPU, memory, storage, uptime, and more) to Home Assistant. It uses a generated TOML configuration file and loads the Home Assistant API token from sops.secrets.HACOMPANION_ENV.
  • upgradeStatus — reports NixOS upgrade state (idle / running / failed / dirty). When upgradeStatus.uptimeKuma.enable is set, it also sends heartbeat notifications to Uptime Kuma on successful upgrades.

Secrets

  • HACOMPANION_ENV — Home Assistant API token, declared in hosts/secrets.yaml and consumed via EnvironmentFile.
  • UPGRADE_STATUS_ID — Uptime Kuma push monitor ID (host-level secrets.yaml), required when upgradeStatus.uptimeKuma.enable is set.

Operational Notes / Assumptions

  • Hacompanion runs as a DynamicUser with its state in /var/lib/hacompanion.
  • The upgradeStatus feature can integrate with Uptime Kuma to provide heartbeat notifications for successful system upgrades.

Usage Example

{ ... }: {
  services.metrics.hacompanion = {
    enable = true;
    sensor.cpu_temp.enable = true;
    sensor.memory.enable = true;
    storage.main = {
      name = "Main OS Drive";
      sensors.used = true;
    };
  };
}

References