depot/ops/nixos/totoro/home-assistant.nix

179 lines
5.2 KiB
Nix
Raw Normal View History

{ depot, lib, pkgs, config, ... }:
let
inherit (depot.ops) secrets;
in {
services.zigbee2mqtt = {
enable = true;
settings = {
homeassistant = true;
serial.port = "/dev/serial/by-id/usb-ITead_Sonoff_Zigbee_3.0_USB_Dongle_Plus_eca6e9ba6596ed11ac206b4ce259fb3e-if00-port0";
mqtt.server = "mqtt://localhost:1883";
frontend = {
port = 8099;
host = config.my.ip.tailscale6;
};
};
};
services.mosquitto = {
enable = true;
listeners = [{
address = "127.0.0.1";
port = 1883;
} {
address = "::1";
port = 1883;
}];
};
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" ]; });
}];
cast = {};
plex = {};
default_config = {};
2022-01-17 04:04:07 +00:00
2022-08-14 17:10:49 +00:00
broadlink = {};
homekit = {};
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);
bedroomRing = x: ({
color_mode = "color_temp";
brightness = 69;
color_temp = 142;
} // x);
entityDefs = ring: overhead: let o = bedroomOverhead { state = overhead; }; in {
"light.bedside_lamp" = bedroomRing { state = ring; };
"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")
];
};
lovelaceConfig = {
title = "117 Malden Road";
views = [{
title = "Bedroom Lights";
cards = [{
type = "light";
entity = "light.bedroom_lights";
} {
type = "light";
entity = "light.bedside_lamp";
icon = "mdi:webcam";
}];
}];
};
};
services.nginx.virtualHosts."ha.lukegb.com" = {
forceSSL = true;
locations."/" = {
proxyPass = "http://localhost:8123/";
proxyWebsockets = true;
};
};
my.vault.acmeCertificates."ha.lukegb.com" = {
hostnames = [ "ha.lukegb.com" ];
nginxVirtualHosts = [ "ha.lukegb.com" ];
};
2022-08-14 17:10:49 +00:00
services.node-red = {
enable = true;
withNpmAndGcc = true;
port = 1880;
};
}