2024-10-13 13:42:52 +00:00
|
|
|
{ depot, lib, pkgs, config, ... }:
|
2022-01-17 02:38:33 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
inherit (depot.ops) secrets;
|
|
|
|
in {
|
2024-10-13 13:42:52 +00:00
|
|
|
services.zigbee2mqtt = {
|
|
|
|
enable = true;
|
2024-11-11 00:33:10 +00:00
|
|
|
package = pkgs.zigbee2mqtt;
|
2024-10-13 13:42:52 +00:00
|
|
|
settings = {
|
|
|
|
homeassistant = true;
|
|
|
|
serial.port = "/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_eca6e9ba6596ed11ac206b4ce259fb3e-if00-port0";
|
2024-10-13 13:57:02 +00:00
|
|
|
mqtt = {
|
|
|
|
server = "mqtt://localhost:1883";
|
|
|
|
user = "zigbee2mqtt";
|
|
|
|
password = "zigbee2mqtt";
|
|
|
|
};
|
2024-10-13 13:42:52 +00:00
|
|
|
frontend = {
|
|
|
|
port = 8099;
|
|
|
|
host = config.my.ip.tailscale6;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
2024-10-13 13:57:02 +00:00
|
|
|
services.mosquitto = let
|
|
|
|
localhostUsers = {
|
|
|
|
zigbee2mqtt = {
|
|
|
|
password = "zigbee2mqtt";
|
|
|
|
acl = [
|
|
|
|
"readwrite zigbee2mqtt/#"
|
|
|
|
"readwrite homeassistant/#"
|
2024-10-20 17:58:39 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
matrix2mqtt = {
|
|
|
|
password = "matrix2mqtt";
|
|
|
|
acl = [
|
|
|
|
"readwrite matrix2mqtt/#"
|
|
|
|
"readwrite homeassistant/#"
|
2024-10-13 13:57:02 +00:00
|
|
|
];
|
|
|
|
};
|
|
|
|
homeassistant = {
|
|
|
|
password = "homeassistant";
|
|
|
|
acl = [
|
2024-10-20 22:20:48 +00:00
|
|
|
"readwrite matrix2mqtt/#"
|
2024-10-13 13:57:02 +00:00
|
|
|
"readwrite zigbee2mqtt/#"
|
|
|
|
"readwrite homeassistant/#"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
in {
|
2024-10-13 13:42:52 +00:00
|
|
|
enable = true;
|
|
|
|
listeners = [{
|
|
|
|
address = "127.0.0.1";
|
|
|
|
port = 1883;
|
2024-10-13 13:57:02 +00:00
|
|
|
users = localhostUsers;
|
2024-10-13 13:42:52 +00:00
|
|
|
} {
|
|
|
|
address = "::1";
|
|
|
|
port = 1883;
|
2024-10-13 13:57:02 +00:00
|
|
|
users = localhostUsers;
|
2024-10-13 13:42:52 +00:00
|
|
|
}];
|
|
|
|
};
|
|
|
|
|
2022-01-17 02:38:33 +00:00
|
|
|
services.home-assistant = {
|
|
|
|
enable = true;
|
|
|
|
configWritable = true;
|
|
|
|
lovelaceConfigWritable = true;
|
|
|
|
config = {
|
|
|
|
homeassistant = {
|
|
|
|
name = "117 Malden Road";
|
|
|
|
time_zone = "Europe/London";
|
|
|
|
external_url = "https://ha.lukegb.com";
|
|
|
|
internal_url = "https://ha.lukegb.com";
|
|
|
|
};
|
|
|
|
notify = [{
|
|
|
|
name = "pushover-luke";
|
|
|
|
platform = "pushover";
|
|
|
|
}];
|
|
|
|
http = {
|
|
|
|
use_x_forwarded_for = true;
|
|
|
|
trusted_proxies = [ "::1" "127.0.0.1" ];
|
|
|
|
};
|
|
|
|
lifx.light = {};
|
|
|
|
light = [{
|
|
|
|
platform = "group";
|
|
|
|
name = "Bedroom Lights";
|
2024-07-03 21:29:08 +00:00
|
|
|
entities = map (x: "light.overhead_${x.side}_${x.n}") (lib.cartesianProduct { side = [ "left" "right" ]; n = [ "1" "2" "3" "4" ]; });
|
2022-01-17 02:38:33 +00:00
|
|
|
}];
|
|
|
|
cast = {};
|
|
|
|
plex = {};
|
|
|
|
default_config = {};
|
2022-01-17 04:04:07 +00:00
|
|
|
|
2022-08-14 17:10:49 +00:00
|
|
|
broadlink = {};
|
|
|
|
homekit = {};
|
2024-10-13 13:42:52 +00:00
|
|
|
mqtt = {};
|
|
|
|
smartthings = {};
|
2022-01-17 04:04:07 +00:00
|
|
|
google_assistant = {
|
|
|
|
project_id = "malden-homeassistant";
|
|
|
|
service_account = secrets.homeAssistant.googleServiceAccount;
|
|
|
|
report_state = true;
|
|
|
|
exposed_domains = [
|
|
|
|
"light"
|
|
|
|
];
|
|
|
|
};
|
|
|
|
|
|
|
|
scene = let
|
|
|
|
bedroomOverhead = x: ({
|
|
|
|
color_mode = "color_temp";
|
|
|
|
brightness = 255;
|
|
|
|
color_temp = 316;
|
|
|
|
} // x);
|
|
|
|
entityDefs = ring: overhead: let o = bedroomOverhead { state = overhead; }; in {
|
|
|
|
"light.overhead_left_1" = o;
|
|
|
|
"light.overhead_left_2" = o;
|
|
|
|
"light.overhead_left_3" = o;
|
|
|
|
"light.overhead_left_4" = o;
|
|
|
|
"light.overhead_right_1" = o;
|
|
|
|
"light.overhead_right_2" = o;
|
|
|
|
"light.overhead_right_3" = o;
|
|
|
|
"light.overhead_right_4" = o;
|
|
|
|
};
|
|
|
|
in [{
|
|
|
|
name = "Bedroom Reset";
|
|
|
|
entities = entityDefs "off" "on";
|
|
|
|
} {
|
|
|
|
name = "Bedroom Off";
|
|
|
|
entities = entityDefs "off" "off";
|
|
|
|
}];
|
|
|
|
|
|
|
|
automation = let
|
|
|
|
base = extra: alias: webhook_id: ({
|
|
|
|
inherit alias;
|
|
|
|
trigger = [{
|
|
|
|
inherit webhook_id;
|
|
|
|
platform = "webhook";
|
|
|
|
}];
|
|
|
|
} // extra);
|
|
|
|
toggleEntity = entity_id: base {
|
|
|
|
action = [{
|
|
|
|
service = "homeassistant.toggle";
|
|
|
|
target.entity_id = entity_id;
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
playPauseEntity = entity_id: base {
|
|
|
|
action = [{
|
|
|
|
service = "media_player.media_play_pause";
|
|
|
|
target.entity_id = entity_id;
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
scene = scene_entity_id: base {
|
|
|
|
action = [{
|
|
|
|
service = "scene.turn_on";
|
|
|
|
target.entity_id = scene_entity_id;
|
|
|
|
data.transition = 1.0;
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
in [
|
|
|
|
(toggleEntity "light.bedroom_lights" "Desk LHS Switch press - toggle room" "flic_desk_lhs")
|
|
|
|
(scene "scene.bedroom_reset" "Desk LHS Switch hold - reset room" "flic_desk_lhs_hold")
|
|
|
|
|
|
|
|
(toggleEntity "light.bedside_lamp" "Desk RHS Switch press - toggle bedside" "flic_desk_rhs")
|
|
|
|
|
|
|
|
(toggleEntity "light.bedroom_lights" "Bed LHS Switch press - toggle room" "flic_bed_lhs")
|
|
|
|
(scene "scene.bedroom_reset" "Bed LHS Switch dblpress - reset room" "flic_bed_lhs_dbl")
|
|
|
|
(scene "scene.bedroom_off" "Bed LHS Switch dblpress - reset room" "flic_bed_lhs_hold")
|
|
|
|
|
|
|
|
(playPauseEntity "media_player.nebula" "Bed RHS Switch press - play/pause nebula" "flic_bed_rhs")
|
|
|
|
|
|
|
|
(toggleEntity "light.bedroom_lights" "Bedroom Door Switch press - toggle room" "flic_bedroom_door")
|
|
|
|
(scene "scene.bedroom_off" "Bedroom Door Switch dblpress - room off" "flic_bedroom_door_dbl")
|
|
|
|
(scene "scene.bedroom_off" "Bedroom Door Switch hold - room off" "flic_bedroom_door_hold")
|
|
|
|
];
|
2022-01-17 02:38:33 +00:00
|
|
|
};
|
|
|
|
lovelaceConfig = {
|
|
|
|
title = "117 Malden Road";
|
|
|
|
views = [{
|
2024-10-20 17:58:49 +00:00
|
|
|
title = "Luke's Bedroom";
|
|
|
|
badges = let
|
|
|
|
scene = scene: cfg: lib.mkMerge [{
|
|
|
|
type = "entity";
|
|
|
|
show_name = true;
|
|
|
|
show_state = false;
|
|
|
|
show_icon = true;
|
|
|
|
entity = "scene.${scene}";
|
|
|
|
tap_action.action = "toggle";
|
|
|
|
} cfg];
|
|
|
|
in [(scene "bedroom_off" {
|
|
|
|
icon = "mdi:ceiling-light-outline";
|
|
|
|
}) (scene "bedroom_reset" {
|
|
|
|
icon = "mdi:ceiling-light-multiple";
|
|
|
|
})];
|
2022-01-17 02:38:33 +00:00
|
|
|
cards = [{
|
2024-10-20 17:58:49 +00:00
|
|
|
type = "grid";
|
|
|
|
square = false;
|
|
|
|
columns = 1;
|
|
|
|
cards = [{
|
|
|
|
type = "light";
|
|
|
|
entity = "light.bedroom_lights";
|
|
|
|
} {
|
|
|
|
type = "entities";
|
2024-10-20 22:34:24 +00:00
|
|
|
entities = [{
|
|
|
|
name = "Mosquito Repellent";
|
|
|
|
entity = "switch.lukes_bedroom_mosquitto_repellent";
|
|
|
|
}];
|
2024-10-20 17:58:49 +00:00
|
|
|
}];
|
2022-01-17 02:38:33 +00:00
|
|
|
} {
|
2024-10-20 17:58:49 +00:00
|
|
|
type = "grid";
|
|
|
|
square = false;
|
|
|
|
columns = 1;
|
|
|
|
cards = [{
|
|
|
|
type = "media-control";
|
|
|
|
entity = "media_player.nebula_3";
|
|
|
|
} {
|
|
|
|
type = "media-control";
|
|
|
|
entity = "media_player.shield_2";
|
|
|
|
}];
|
2024-10-20 22:34:24 +00:00
|
|
|
} {
|
|
|
|
type = "grid";
|
|
|
|
square = false;
|
|
|
|
columns = 1;
|
|
|
|
cards = [{
|
|
|
|
title = "Projector";
|
|
|
|
type = "entities";
|
|
|
|
entities = [{
|
|
|
|
name = "source";
|
|
|
|
entity = "select.hdmi_matrix_hdmi_1_projector";
|
|
|
|
} {
|
|
|
|
name = "Power (CEC)";
|
2024-11-10 19:02:42 +00:00
|
|
|
entity = "switch.hdmi_matrix_hdmi_1_projector_cec_power";
|
2024-10-20 22:34:24 +00:00
|
|
|
icon = "mdi:power";
|
|
|
|
}];
|
|
|
|
} {
|
|
|
|
title = "Sound Bar";
|
|
|
|
type = "entities";
|
|
|
|
entities = [{
|
|
|
|
name = "Source";
|
|
|
|
entity = "select.hdmi_matrix_hdmi_2_sound_bar";
|
|
|
|
} {
|
|
|
|
name = "Power (Samsung SmartThings)";
|
|
|
|
entity = "switch.samsung_soundbar_q930b";
|
|
|
|
icon = "mdi:power";
|
|
|
|
} {
|
|
|
|
name = "Power (CEC)";
|
2024-11-10 19:02:42 +00:00
|
|
|
entity = "switch.hdmi_matrix_hdmi_2_sound_bar_cec_power";
|
2024-10-20 22:34:24 +00:00
|
|
|
icon = "mdi:power";
|
|
|
|
}];
|
|
|
|
} {
|
|
|
|
title = "Side Monitor";
|
|
|
|
type = "entities";
|
|
|
|
entities = [{
|
|
|
|
name = "Source";
|
|
|
|
entity = "select.hdmi_matrix_hdmi_3_desk_monitor";
|
|
|
|
} {
|
|
|
|
name = "Power";
|
2024-11-10 19:02:42 +00:00
|
|
|
entity = "switch.hdmi_matrix_hdmi_3_desk_monitor_cec_power";
|
2024-10-20 22:34:24 +00:00
|
|
|
icon = "mdi:power";
|
|
|
|
}];
|
|
|
|
}];
|
2022-01-17 02:38:33 +00:00
|
|
|
}];
|
|
|
|
}];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
services.nginx.virtualHosts."ha.lukegb.com" = {
|
|
|
|
forceSSL = true;
|
|
|
|
locations."/" = {
|
|
|
|
proxyPass = "http://localhost:8123/";
|
|
|
|
proxyWebsockets = true;
|
|
|
|
};
|
|
|
|
};
|
2022-03-07 00:52:03 +00:00
|
|
|
my.vault.acmeCertificates."ha.lukegb.com" = {
|
2022-03-17 23:31:55 +00:00
|
|
|
hostnames = [ "ha.lukegb.com" ];
|
2022-03-07 00:52:03 +00:00
|
|
|
nginxVirtualHosts = [ "ha.lukegb.com" ];
|
|
|
|
};
|
2022-08-14 17:10:49 +00:00
|
|
|
|
|
|
|
services.node-red = {
|
|
|
|
enable = true;
|
|
|
|
withNpmAndGcc = true;
|
|
|
|
port = 1880;
|
|
|
|
};
|
2024-10-20 22:25:51 +00:00
|
|
|
|
|
|
|
systemd.services.matrix2mqtt = {
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
unitConfig = {
|
|
|
|
StartLimitIntervalSec = "0";
|
|
|
|
};
|
|
|
|
serviceConfig = {
|
|
|
|
ExecStart = "${depot.rust.matrix2mqtt}/bin/matrix2mqtt";
|
|
|
|
User = "matrix2mqtt";
|
|
|
|
PrivateTmp = true;
|
|
|
|
PrivateDevices = true;
|
|
|
|
RestrictNamespaces = true;
|
|
|
|
RestrictRealtime = true;
|
|
|
|
ProtectKernelLogs = true;
|
|
|
|
ProtectControlGroups = true;
|
|
|
|
ProtectHostname = true;
|
|
|
|
ProtectHome = true;
|
|
|
|
ProtectProc = "invisible";
|
|
|
|
ProcSubset = "pid";
|
|
|
|
ProtectKernelTunables = true;
|
|
|
|
ProtectKernelModules = true;
|
|
|
|
ProtectClock = true;
|
|
|
|
CapabilityBoundingSet = "";
|
|
|
|
LockPersonality = true;
|
|
|
|
PrivateUsers = true;
|
|
|
|
RestrictAddressFamilies = "AF_UNIX AF_INET AF_INET6 AF_NETLINK";
|
|
|
|
|
|
|
|
DynamicUser = true;
|
|
|
|
Restart = "always";
|
|
|
|
RestartSec = "100ms";
|
|
|
|
RestartSteps = 10;
|
|
|
|
RestartMaxDelaySec = "1min";
|
|
|
|
};
|
|
|
|
};
|
2022-01-17 02:38:33 +00:00
|
|
|
}
|