mqtt
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
{ config, pkgs, ... }:
|
{ config, pkgs, ... }:
|
||||||
let
|
let
|
||||||
|
mosquittoPort = 1883;
|
||||||
|
zigbee2mqttPort = 8080;
|
||||||
# "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
# "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
|
||||||
ha-bambulab = pkgs.stdenv.mkDerivation {
|
ha-bambulab = pkgs.stdenv.mkDerivation {
|
||||||
pname = "ha-bambulab";
|
pname = "ha-bambulab";
|
||||||
@@ -149,6 +151,15 @@ in
|
|||||||
debug = false;
|
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/
|
# 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";
|
zha.zigpy_config.ota.z2m_remote_index = "https://raw.githubusercontent.com/Koenkk/zigbee-OTA/master/index.json";
|
||||||
};
|
};
|
||||||
@@ -186,15 +197,73 @@ in
|
|||||||
ensureDBOwnership = true;
|
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 = {
|
zigbee2mqtt = {
|
||||||
enable = true;
|
enable = true;
|
||||||
settings = {
|
settings = {
|
||||||
homeassistant = config.services.home-assistant.enable;
|
homeassistant = config.services.home-assistant.enable;
|
||||||
permit_join = true;
|
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 = {
|
serial = {
|
||||||
port = "/dev/ttyUSB0";
|
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
|
||||||
|
];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user