This commit is contained in:
mjallen18
2025-02-26 19:12:28 -06:00
parent 390383e59a
commit 1f8a4c6353

View File

@@ -1,5 +1,7 @@
{ config, pkgs, ... }:
let
mosquittoPort = 1883;
zigbee2mqttPort = 8080;
# "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
ha-bambulab = pkgs.stdenv.mkDerivation {
pname = "ha-bambulab";
@@ -149,6 +151,15 @@ in
debug = false;
};
# Add MQTT integration
mqtt = {
discovery = true;
discovery_prefix = "homeassistant";
broker = "localhost"; # Using local Mosquitto broker
port = mosquittoPort;
# If you set up MQTT with authentication, add username and password here
};
# https://www.home-assistant.io/integrations/ota_updater/
zha.zigpy_config.ota.z2m_remote_index = "https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/index.json";
};
@@ -186,15 +197,73 @@ in
ensureDBOwnership = true;
}];
};
# Enable and configure Mosquitto MQTT broker
services.mosquitto = {
enable = true;
listeners = [
{
port = mosquittoPort;
users = {
# Optional: Set up authentication
# "mqttuser" = {
# password = "your-password";
# acl = [ "pattern readwrite #" ];
# };
};
# For testing, allow anonymous connections
settings.allow_anonymous = true;
}
];
};
zigbee2mqtt = {
enable = true;
settings = {
homeassistant = config.services.home-assistant.enable;
permit_join = true;
# Web interface
frontend = {
port = zigbee2mqttPort; # Choose an available port
};
# MQTT configuration
mqtt = {
base_topic = "zigbee2mqtt";
server = "mqtt://localhost:${mosquittoPort}";
# If using authentication:
# user = "mqttuser";
# password = "your-password";
};
serial = {
port = "/dev/ttyUSB0";
};
};
};
# Enable required hardware support for the Zigbee adapter
hardware.bluetooth.enable = true; # Some adapters use Bluetooth
# Ensure proper permissions for Zigbee USB devices
# services.udev.extraRules = ''
# # For CC2531, CC2530, CC1352P-2, CC2538 and similar adapters
# SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="zigbee", MODE="0666"
# SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="zigbee", MODE="0666"
# # For ConBee/RaspBee by Dresden Elektronik
# SUBSYSTEM=="tty", ATTRS{idVendor}=="1cf1", ATTRS{idProduct}=="0030", SYMLINK+="zigbee", MODE="0666"
# # For Electrolama zig-a-zig-ah (zzh!)
# SUBSYSTEM=="tty", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", SYMLINK+="zigbee", MODE="0666"
# '';
environment.systemPackages = with pkgs; [
mosquitto # MQTT command-line tools
usbutils # For lsusb to help identify your adapter
];
networking.firewall.allowedTCPPorts = [
mosquittoPort
zigbee2mqttPort
];
};
}