nixos-config/configs/pepe/home-assistant.nix
2020-06-01 04:12:15 +02:00

306 lines
7.3 KiB
Nix

{ pkgs, config, lib, ... }:
let unstablePkgs = import <nixpkgs-unstable> { };
in {
imports = [
#./home-assistant/mpd.nix
#./home-assistant/timer.nix
./home-assistant/light-control.nix
./home-assistant/chaospott.nix
./home-assistant/kodi.nix
./home-assistant/mqtt.nix
./home-assistant/sonoff.nix
./home-assistant/stocks.nix
./home-assistant/weather.nix
./home-assistant/workday.nix
./home-assistant/zigbee2mqtt.nix
];
services.homeAssistantConfig = {
# turn on to edit GUI
# lovelace = {};
homeassistant = {
latitude = 51.444847;
longitude = 6.967006;
elevation = 116;
auth_providers = [{
type = "trusted_networks";
trusted_networks =
[ config.module.cluster.services.tinc."private".networkSubnet ];
}];
};
prometheus.namespace = "hass";
# manual state
# ------------
input_select.situation = {
icon = "mdi:brightness-auto";
options = [ "default" "night" "outside" ];
};
input_boolean.situation_toggle.icon = "mdi:toggle-switch";
automation = [
# control situation with buttons
{
alias = "set night scene";
trigger = {
platform = "state";
entity_id = "input_boolean.situation_toggle";
from = "off";
to = "on";
};
action = {
service = "mqtt.publish";
data = {
topic = "control/lights/set";
payload = builtins.toJSON { scene = "night"; };
};
};
}
{
alias = "set default scene";
trigger = {
platform = "state";
entity_id = "input_boolean.situation_toggle";
from = "on";
to = "off";
};
action = {
service = "mqtt.publish";
data = {
topic = "control/lights/set";
payload = builtins.toJSON { scene = "default"; };
};
};
}
{
alias = "set outside scene";
trigger = [
{
platform = "state";
# todo : groups are not working right now
entity_id = "binary_sensor.door_sensor_2";
from = "off";
to = "on";
}
{
platform = "state";
# todo : groups are not working right now
entity_id = "binary_sensor.door_sensor_2";
from = "on";
to = "off";
}
];
action = {
service = "mqtt.publish";
data = {
topic = "control/lights/set";
payload = builtins.toJSON { scene = "outside"; };
};
};
}
];
group = let
create_room = { name, description }: {
"${name}" = {
name = "${description}";
view = false;
control = "hidden";
entities = [ ];
};
"${name}_lights" = {
name = "${description} Beleuchtung";
view = false;
entities = [ ];
};
"${name}_present" = {
control = "hidden";
name = "${description} Anwesend";
view = false;
entities = [ ];
};
"${name}_essential" = {
control = "hidden";
name = "${description} Minimale Beleuchtung";
view = false;
entities = [ ];
};
"${name}_bright" = {
control = "hidden";
name = "${description} Tages Beleuchtung";
view = false;
entities = [ ];
};
"view_${name}" = {
name = description;
view = true;
entities = [
"group.${name}"
"group.${name}_bright"
"group.${name}_essential"
"group.${name}_lights"
"group.${name}_present"
];
};
};
create_rooms = rooms:
lib.foldr (a: b: a // b) { } (map create_room rooms);
# rooms
# -----
in (create_rooms [
{
name = "floor_room";
description = "Flur";
}
{
name = "bed_room";
description = "Schlafzimmer";
}
{
name = "living_room";
description = "Wohnzimmer";
}
{
name = "kitchen_room";
description = "Küche";
}
{
name = "bath_room";
description = "Klo";
}
]) // {
view_rooms = {
name = "Räume";
view = true;
entities = [
"group.today"
"group.floor_room"
"group.bed_room"
"group.living_room"
"group.kitchen_room"
"group.bath_room"
];
};
all_room_presents = {
name = "Alle Anwesenheits Raum Sensoren";
entities = [
"group.floor_room_present"
"group.bed_room_present"
"group.living_room_present"
"group.kitchen_room_present"
"group.bath_room_present"
];
};
outside = {
name = "Draußen";
entities = [ ];
};
# overview
# --------
all_sensors = {
name = "Alle Sensoren";
control = "hidden";
};
today = {
control = "hidden";
name = "Today";
view = false;
entities = [
"input_select.situation"
"input_select.room_present"
"input_boolean.presents_tracking"
];
};
view_overview = {
name = "Übersicht";
view = true;
entities = [ "group.today" ];
};
# other stuff
# -----------
tv = {
name = "TV";
view = false;
};
all_lights = {
name = "Alle Lampen";
view = false;
};
unknown = {
control = "hidden";
name = "Not Used";
view = false;
entities = [ ];
};
};
script.turn_all_off.sequence = [ ];
script.turn_all_lights_off.sequence = [ ];
};
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 ];
# };
#})
];
};
};
# host nginx setup
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts = {
"iot.pepe.private" = {
serverAliases = [ "hass.pepe.private" "home.pepe.private" ];
locations."/" = { proxyPass = "http://pepe.private:8123"; };
};
};
};
}