nixos-config/configs/pepe/home-assistant.nix

294 lines
7.4 KiB
Nix
Raw Normal View History

2020-04-08 16:43:09 +02:00
{ pkgs, config, lib, ... }:
let unstablePkgs = import <nixpkgs-unstable> { };
in {
imports = [
#./home-assistant/mpd.nix
#./home-assistant/timer.nix
2020-06-01 04:12:15 +02:00
./home-assistant/light-control.nix
2021-03-20 13:28:40 +01:00
./home-assistant/iot-control.nix
2020-04-17 20:59:12 +02:00
./home-assistant/chaospott.nix
2020-04-10 11:36:58 +02:00
./home-assistant/kodi.nix
2020-04-12 13:36:15 +02:00
./home-assistant/mqtt.nix
./home-assistant/sonoff.nix
2020-04-17 20:59:12 +02:00
./home-assistant/stocks.nix
2020-04-12 13:36:15 +02:00
./home-assistant/weather.nix
./home-assistant/workday.nix
2020-04-10 13:50:20 +02:00
./home-assistant/zigbee2mqtt.nix
2020-04-08 16:43:09 +02:00
];
2021-03-23 07:37:21 +01:00
networking.firewall.allowedTCPPorts = [ 8123 ];
networking.firewall.allowedUDPPorts = [ 8123 ];
2020-04-08 16:43:09 +02:00
services.homeAssistantConfig = {
# turn on to edit GUI
lovelace = { };
2020-04-08 16:43:09 +02:00
homeassistant = {
name = "Home";
2020-04-08 16:43:09 +02:00
latitude = 51.444847;
longitude = 6.967006;
elevation = 116;
unit_system = "metric";
2020-04-08 16:43:09 +02:00
time_zone = config.time.timeZone;
2020-04-08 16:43:09 +02:00
auth_providers = [{
type = "trusted_networks";
trusted_networks = [
config.module.cluster.services.tinc."private".networkSubnet
# lan network
"10.1.0.0/24"
2021-03-23 07:37:21 +01:00
"192.168.178.0/24"
];
2020-04-08 16:43:09 +02:00
}];
2020-04-08 16:43:09 +02:00
};
# needed, don't know why
default_config = { };
config = { };
# to grab metrics via prometheus
2020-04-08 16:43:09 +02:00
prometheus.namespace = "hass";
2020-04-16 02:58:44 +02:00
# manual state
# ------------
# all scenes
input_select.scene = {
2020-04-16 01:26:02 +02:00
icon = "mdi:brightness-auto";
2021-03-17 09:09:44 +01:00
options = [ "up-bright" "up-dark" "half" "down" "night" "outside" ];
2020-04-16 01:26:02 +02:00
};
# scenes controlled by buttons
input_select.scene_button = {
icon = "mdi:brightness-auto";
2021-03-17 09:09:44 +01:00
options = [ "up-dark" "night" ];
};
2020-04-16 01:26:02 +02:00
input_boolean.situation_toggle.icon = "mdi:toggle-switch";
input_boolean.printer_toggle.icon = "mdi:toggle-switch";
2020-04-14 17:29:00 +02:00
input_boolean.windows_up.icon = "mdi:toggle-switch";
2020-06-01 04:12:15 +02:00
automation = [
2020-04-17 20:59:12 +02:00
{
alias = "Hold Button -> Toggle Printer";
trigger = {
platform = "state";
entity_id = "input_boolean.printer_toggle";
};
action = {
service = "switch.toggle";
data.entity_id = "switch.pal02";
};
}
2020-04-16 01:26:02 +02:00
{
2020-06-11 12:28:29 +02:00
alias = "set light-control scene";
2020-04-16 01:26:02 +02:00
trigger = {
platform = "state";
entity_id = "input_select.scene";
2020-04-16 01:26:02 +02:00
};
action = {
2020-06-01 04:12:15 +02:00
service = "mqtt.publish";
data_template = {
2020-06-01 04:12:15 +02:00
topic = "control/lights/set";
payload_template =
''{"scene":"{{ states('input_select.scene')}}"}'';
2020-04-16 01:26:02 +02:00
};
};
}
# control situation with buttons
2020-04-16 01:26:02 +02:00
{
2020-06-11 12:28:29 +02:00
alias = "Button -> Change Scene";
2020-04-16 01:26:02 +02:00
trigger = {
platform = "state";
entity_id = "input_boolean.situation_toggle";
};
action = {
service = "input_select.select_next";
data.entity_id = "input_select.scene_button";
};
}
{
alias = "Button Scene -> Scene";
trigger = {
platform = "state";
entity_id = "input_select.scene_button";
};
action = {
service = "input_select.select_option";
data_template = {
entity_id = "input_select.scene";
option = "{{ states('input_select.scene_button') }}";
2020-04-16 01:26:02 +02:00
};
};
2020-04-16 00:22:29 +02:00
}
2020-11-14 00:46:45 +01:00
# outside and home
{
alias = "when opening door I'm outside";
trigger = [
{
platform = "state";
2020-06-01 04:12:15 +02:00
# todo : groups are not working right now
2020-10-21 22:57:48 +02:00
entity_id = "binary_sensor.door_sensor_4";
from = "off";
to = "on";
}
{
platform = "state";
2020-06-01 04:12:15 +02:00
# todo : groups are not working right now
2020-10-21 22:57:48 +02:00
entity_id = "binary_sensor.door_sensor_4";
from = "on";
to = "off";
}
];
2021-01-17 16:57:35 +01:00
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.scene";
option = "outside";
};
2021-03-17 09:09:44 +01:00
}];
}
2020-11-14 00:46:45 +01:00
{
alias = "reset everything when back home";
2020-11-14 00:46:45 +01:00
trigger = map (entity_id: {
platform = "state";
entity_id = entity_id;
from = "off";
to = "on";
}) [
"binary_sensor.motion_sensor_1"
"binary_sensor.motion_sensor_2"
"binary_sensor.motion_sensor_3"
"binary_sensor.motion_sensor_4"
"binary_sensor.motion_sensor_5"
"binary_sensor.motion_sensor_6"
"binary_sensor.motion_sensor_7"
"binary_sensor.motion_sensor_8"
];
condition = {
condition = "template";
value_template =
''{{ states.input_select.scene.state == "outside" }}'';
};
2021-01-17 16:57:35 +01:00
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.scene";
2021-03-17 09:09:44 +01:00
option = "up-dark";
2021-01-17 16:57:35 +01:00
};
}];
2020-10-28 23:56:10 +01:00
}
];
2020-04-08 16:43:09 +02:00
2020-04-14 11:38:40 +02:00
group = let
create_room = { name, description }: {
2020-04-14 11:38:40 +02:00
"${name}" = {
2020-04-16 00:22:29 +02:00
name = "${description}";
2020-04-15 18:08:27 +02:00
entities = [ ];
2020-04-14 11:38:40 +02:00
};
};
create_rooms = rooms:
lib.foldr (a: b: a // b) { } (map create_room rooms);
2020-04-12 21:05:55 +02:00
# rooms
# -----
2020-04-14 11:38:40 +02:00
in (create_rooms [
{
name = "floor_room";
description = "Flur";
}
{
name = "bed_room";
description = "Schlafzimmer";
}
{
name = "living_room";
description = "Wohnzimmer";
}
{
name = "kitchen_room";
description = "Küche";
}
2020-04-15 18:08:27 +02:00
{
name = "bath_room";
description = "Klo";
}
2020-04-14 11:38:40 +02:00
]) // {
2020-04-12 21:05:55 +02:00
# overview
# --------
all_sensors = { name = "Alle Sensoren"; };
2020-04-12 21:05:55 +02:00
today = {
name = "Today";
entities = [ "input_select.scene" ];
2020-04-12 19:57:49 +02:00
};
2020-04-12 21:05:55 +02:00
# other stuff
# -----------
tv = { name = "TV"; };
all_lights = { name = "Alle Lampen"; };
2020-04-12 21:05:55 +02:00
unknown = {
name = "Not Used";
entities = [ ];
2020-04-08 16:43:09 +02:00
};
};
};
services.home-assistant = {
enable = true;
#package = unstablePkgs.home-assistant.override {
# python3 = unstablePkgs.python37;
# extraPackages = python: [
# # todo : check which is still needed
# python.netdisco
# python.xmltodict
# python.mpd2
# # for mqtt
# python.hbmqtt
# python.paho-mqtt
# # needed for platform workday
# #(python.buildPythonPackage rec {
# # pname = "holidays";
# # version = "0.9.10";
# # src = python.fetchPypi {
# # inherit pname version;
# # sha256 =
# # "9f06d143eb708e8732230260636938f2f57114e94defd8fa2082408e0d422d6f";
# # };
# # doCheck = false;
# # buildInputs = [ pkgs.dateutils ];
# # propagatedBuildInputs = [ python."python-dateutil" python."six" ];
# # meta = with pkgs.stdenv.lib; {
# # homepage = "https://github.com/dr-prodigy/python-holidays";
# # license = licenses.mit;
# # description = "Generate and work with holidays in Python";
# # maintainers = with maintainers; [ mrVanDalo ];
# # };
# #})
# ];
#};
2020-04-08 16:43:09 +02:00
};
2020-04-09 01:19:00 +02:00
# host nginx setup
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts = {
"iot.pepe.private" = {
2020-04-09 16:51:39 +02:00
serverAliases = [ "hass.pepe.private" "home.pepe.private" ];
locations."/" = { proxyPass = "http://pepe.private:8123"; };
2020-04-09 01:19:00 +02:00
};
};
};
2020-04-08 16:43:09 +02:00
}