2020-02-24 15:59:11 +00:00
|
|
|
{config, pkgs, lib, ...}:
|
|
|
|
|
2020-11-18 21:20:24 +00:00
|
|
|
let
|
|
|
|
dataDir = "/var/lib/zigbee2mqtt";
|
2021-03-09 21:16:13 +00:00
|
|
|
sec = import <secrets/zigbee2mqtt.nix>;
|
2021-04-08 19:39:39 +00:00
|
|
|
internal-ip = "192.168.111.11";
|
2021-03-12 19:28:20 +00:00
|
|
|
webport = 8521;
|
2020-11-18 21:20:24 +00:00
|
|
|
in
|
|
|
|
{
|
2020-03-03 20:17:43 +00:00
|
|
|
# symlink the zigbee controller
|
2021-03-09 21:16:13 +00:00
|
|
|
#services.udev.extraRules = ''
|
|
|
|
# SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout"
|
|
|
|
#'';
|
2021-03-12 19:28:20 +00:00
|
|
|
|
|
|
|
# /dev/serial/by-id/usb-Silicon_Labs_slae.sh_cc2652rb_stick_-_slaesh_s_iot_stuff_00_12_4B_00_21_CC_45_BD-if00-port0
|
2020-02-24 15:59:11 +00:00
|
|
|
services.udev.extraRules = ''
|
2021-03-09 21:16:13 +00:00
|
|
|
SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="cc2531", MODE="0660", GROUP="dialout"
|
2020-02-24 15:59:11 +00:00
|
|
|
'';
|
2020-03-03 20:17:43 +00:00
|
|
|
|
2020-11-18 21:20:24 +00:00
|
|
|
services.zigbee2mqtt = {
|
|
|
|
enable = true;
|
|
|
|
inherit dataDir;
|
2021-06-05 13:52:06 +00:00
|
|
|
settings = {
|
2021-03-09 21:16:13 +00:00
|
|
|
permit_join = true;
|
|
|
|
serial.port = "/dev/cc2531";
|
|
|
|
homeassistant = true;
|
|
|
|
mqtt = {
|
|
|
|
server = "mqtt://omo.lan:1883";
|
|
|
|
base_topic = "/ham/zigbee";
|
|
|
|
user = sec.mqtt.username;
|
|
|
|
password = sec.mqtt.password;
|
|
|
|
include_device_information = true;
|
|
|
|
client_id = "zigbee2mqtt";
|
|
|
|
};
|
2023-06-03 13:27:46 +00:00
|
|
|
availability = {
|
|
|
|
active.timeout = 10;
|
|
|
|
passive.timeout = 1500;
|
|
|
|
};
|
2021-03-12 19:28:20 +00:00
|
|
|
frontend = {
|
|
|
|
port = webport;
|
|
|
|
};
|
2021-03-09 21:16:13 +00:00
|
|
|
advanced = {
|
|
|
|
log_level = "debug";
|
|
|
|
log_output = [ "console" ];
|
|
|
|
last_seen = "ISO_8601";
|
|
|
|
elapsed = true;
|
|
|
|
pan_id = 6755;
|
|
|
|
inherit (sec.zigbee) network_key;
|
|
|
|
};
|
|
|
|
map_options.graphviz.colors = {
|
|
|
|
fill = {
|
|
|
|
enddevice = "#fff8ce" ;
|
|
|
|
coordinator = "#e04e5d";
|
|
|
|
router = "#4ea3e0";
|
|
|
|
};
|
|
|
|
font = {
|
|
|
|
coordinator= "#ffffff";
|
|
|
|
router = "#ffffff";
|
|
|
|
enddevice = "#000000";
|
|
|
|
};
|
|
|
|
line = {
|
|
|
|
active = "#009900";
|
|
|
|
inactive = "#994444";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2020-11-18 21:20:24 +00:00
|
|
|
};
|
|
|
|
|
2021-03-12 19:28:20 +00:00
|
|
|
services.nginx.recommendedProxySettings = true;
|
|
|
|
services.nginx.virtualHosts."zigbee" = {
|
|
|
|
serverAliases = [ "zigbee.lan" ];
|
|
|
|
locations."/".proxyPass = "http://localhost:${toString webport}";
|
|
|
|
locations."/api".proxyPass = "http://localhost:${toString webport}";
|
|
|
|
locations."/api".proxyWebsockets = true;
|
|
|
|
extraConfig = ''
|
|
|
|
if ( $server_addr != "${internal-ip}" ) {
|
|
|
|
return 403;
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2021-03-09 21:16:13 +00:00
|
|
|
state = [ "${dataDir}/devices.yaml" "${dataDir}/state.json" ];
|
2020-03-03 20:17:43 +00:00
|
|
|
|
2020-11-18 21:20:24 +00:00
|
|
|
systemd.services.zigbee2mqtt = {
|
2020-11-18 21:26:41 +00:00
|
|
|
# override automatic configuration.yaml deployment
|
2021-03-09 21:16:13 +00:00
|
|
|
environment.ZIGBEE2MQTT_DATA = dataDir;
|
|
|
|
#serviceConfig.ExecStartPre = lib.mkForce "${pkgs.coreutils}/bin/true";
|
2020-11-18 21:20:24 +00:00
|
|
|
after = [
|
|
|
|
"home-assistant.service"
|
|
|
|
"mosquitto.service"
|
|
|
|
"network-online.target"
|
|
|
|
];
|
2020-03-03 20:17:43 +00:00
|
|
|
};
|
2020-02-24 15:59:11 +00:00
|
|
|
}
|