The homeassistant override key should match the entity type in the MQTT discovery topic path. For battery sensors, the topic is homeassistant/sensor/<device>/battery/config, so the key should be "battery" not "sensor_battery". Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
113 lines
3.4 KiB
Nix
113 lines
3.4 KiB
Nix
{ pkgs, config, ... }:
|
|
{
|
|
homelab.monitoring.scrapeTargets = [{
|
|
job_name = "home-assistant";
|
|
port = 8123;
|
|
metrics_path = "/api/prometheus";
|
|
scrape_interval = "60s";
|
|
}];
|
|
# Enable the Home Assistant service
|
|
services.home-assistant = {
|
|
enable = true;
|
|
package = pkgs.unstable.home-assistant;
|
|
configWritable = true;
|
|
config = null;
|
|
extraPackages =
|
|
python3Packages: with pkgs.unstable.python313Packages; [
|
|
aiopyarr
|
|
aioshelly
|
|
bellows
|
|
gtts
|
|
ha-silabs-firmware-client
|
|
isal
|
|
paho-mqtt
|
|
prometheus-client
|
|
pykodi
|
|
python-roborock
|
|
radios
|
|
uiprotect
|
|
unifi-discovery
|
|
universal-silabs-flasher
|
|
vacuum-map-parser-base
|
|
vacuum-map-parser-roborock
|
|
zha
|
|
zha-quirks
|
|
zigpy-cc
|
|
zigpy-deconz
|
|
zigpy-xbee
|
|
zigpy-zigate
|
|
zigpy-znp
|
|
zlib-ng
|
|
];
|
|
customComponents = with pkgs.home-assistant-custom-components; [
|
|
];
|
|
};
|
|
|
|
# Enable the mosquitto MQTT broker
|
|
services.mosquitto = {
|
|
enable = true;
|
|
persistence = true;
|
|
listeners = [
|
|
{
|
|
acl = [ "pattern readwrite #" ];
|
|
omitPasswordAuth = true;
|
|
settings.allow_anonymous = true;
|
|
}
|
|
];
|
|
};
|
|
|
|
# Enable the zigbee2mqtt service
|
|
services.zigbee2mqtt = {
|
|
enable = true;
|
|
package = pkgs.unstable.zigbee2mqtt;
|
|
settings = {
|
|
homeassistant = {
|
|
legacy_entity_attributes = false;
|
|
legacy_triggers = false;
|
|
};
|
|
availability = true;
|
|
frontend = true;
|
|
permit_join = false;
|
|
serial.port = "/dev/ttyUSB0";
|
|
|
|
# Inline device configuration (replaces devices.yaml)
|
|
# This allows declarative management and homeassistant overrides
|
|
devices = {
|
|
# Temperature sensors with battery fix
|
|
# WSDCGQ12LM sensors report battery: 0 due to firmware quirk
|
|
# Override battery calculation using voltage (mV): (voltage - 2100) / 9
|
|
"0x54ef441000a547bd" = {
|
|
friendly_name = "0x54ef441000a547bd";
|
|
homeassistant.battery.value_template = "{{ (((value_json.voltage | float) - 2100) / 9) | round(0) | int | min(100) | max(0) }}";
|
|
};
|
|
"0x54ef441000a54d3c" = {
|
|
friendly_name = "0x54ef441000a54d3c";
|
|
homeassistant.battery.value_template = "{{ (((value_json.voltage | float) - 2100) / 9) | round(0) | int | min(100) | max(0) }}";
|
|
};
|
|
"0x54ef441000a564b6" = {
|
|
friendly_name = "temp_server";
|
|
homeassistant.battery.value_template = "{{ (((value_json.voltage | float) - 2100) / 9) | round(0) | int | min(100) | max(0) }}";
|
|
};
|
|
|
|
# Other sensors
|
|
"0x00124b0025495463".friendly_name = "0x00124b0025495463"; # SONOFF temp sensor (battery works)
|
|
"0x54ef4410009ac117".friendly_name = "0x54ef4410009ac117"; # Water leak sensor
|
|
|
|
# Buttons
|
|
"0x54ef441000a1f907".friendly_name = "btn_livingroom";
|
|
"0x54ef441000a1ee71".friendly_name = "btn_bedroom";
|
|
|
|
# Philips Hue lights
|
|
"0x001788010d1b599a" = {
|
|
friendly_name = "0x001788010d1b599a";
|
|
transition = 5;
|
|
};
|
|
"0x001788010d253b99".friendly_name = "0x001788010d253b99";
|
|
"0x001788010e371aa4".friendly_name = "0x001788010e371aa4";
|
|
"0x001788010dc5f003".friendly_name = "0x001788010dc5f003";
|
|
"0x001788010dc35d06".friendly_name = "0x001788010dc35d06";
|
|
};
|
|
};
|
|
};
|
|
}
|