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
|
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
|
|
|
];
|
|
|
|
|
|
|
|
services.homeAssistantConfig = {
|
|
|
|
|
|
|
|
# turn on to edit GUI
|
2020-06-01 23:20:15 +02:00
|
|
|
lovelace = { };
|
2020-04-08 16:43:09 +02:00
|
|
|
|
|
|
|
homeassistant = {
|
2020-06-01 23:20:15 +02:00
|
|
|
|
|
|
|
name = "Home";
|
2020-04-08 16:43:09 +02:00
|
|
|
latitude = 51.444847;
|
|
|
|
longitude = 6.967006;
|
|
|
|
elevation = 116;
|
2020-06-01 23:20:15 +02:00
|
|
|
unit_system = "metric";
|
2020-04-08 16:43:09 +02:00
|
|
|
|
2020-06-01 23:20:15 +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 ];
|
|
|
|
}];
|
2020-06-01 23:20:15 +02:00
|
|
|
|
2020-04-08 16:43:09 +02:00
|
|
|
};
|
|
|
|
|
2020-06-01 23:20:15 +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
|
|
|
|
# ------------
|
2020-06-01 23:20:15 +02:00
|
|
|
# all scenes
|
|
|
|
input_select.scene = {
|
2020-04-16 01:26:02 +02:00
|
|
|
icon = "mdi:brightness-auto";
|
2020-06-11 12:28:29 +02:00
|
|
|
options = [ "default" "night" "outside" "cooking" ];
|
2020-04-16 01:26:02 +02:00
|
|
|
};
|
2020-06-01 23:20:15 +02:00
|
|
|
# scenes controlled by buttons
|
|
|
|
input_select.scene_button = {
|
|
|
|
icon = "mdi:brightness-auto";
|
|
|
|
options = [ "default" "night" ];
|
|
|
|
};
|
2020-04-16 01:26:02 +02:00
|
|
|
input_boolean.situation_toggle.icon = "mdi:toggle-switch";
|
2020-04-14 17:29:00 +02:00
|
|
|
|
2020-06-01 04:12:15 +02:00
|
|
|
automation = [
|
2020-04-17 20:59:12 +02:00
|
|
|
|
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";
|
2020-06-01 23:20:15 +02:00
|
|
|
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";
|
2020-06-01 23:20:15 +02:00
|
|
|
data_template = {
|
2020-06-01 04:12:15 +02:00
|
|
|
topic = "control/lights/set";
|
2020-06-01 23:20:15 +02:00
|
|
|
payload_template =
|
|
|
|
''{"scene":"{{ states('input_select.scene')}}"}'';
|
2020-04-16 01:26:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
2020-06-01 23:20:15 +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";
|
|
|
|
};
|
2020-06-11 12:28:29 +02:00
|
|
|
condition = {
|
2020-06-11 16:53:29 +02:00
|
|
|
condition = "template";
|
|
|
|
value_template =
|
|
|
|
''{{ states.input_select.scene.state != "outside" }}'';
|
2020-06-11 12:28:29 +02:00
|
|
|
};
|
2020-04-16 01:26:02 +02:00
|
|
|
action = {
|
2020-06-01 23:20:15 +02:00
|
|
|
service = "input_select.select_next";
|
|
|
|
data.entity_id = "input_select.scene_button";
|
|
|
|
};
|
|
|
|
}
|
2020-06-11 12:28:29 +02:00
|
|
|
{
|
|
|
|
alias = "Button -> Default Scene";
|
|
|
|
trigger = {
|
|
|
|
platform = "state";
|
|
|
|
entity_id = "input_boolean.situation_toggle";
|
|
|
|
};
|
|
|
|
condition = {
|
2020-06-11 16:53:29 +02:00
|
|
|
condition = "template";
|
|
|
|
value_template =
|
|
|
|
''{{ states.input_select.scene.state == "outside" }}'';
|
2020-06-11 12:28:29 +02:00
|
|
|
};
|
2020-06-11 16:53:29 +02:00
|
|
|
action = [
|
|
|
|
{
|
|
|
|
service = "input_select.select_option";
|
|
|
|
data = {
|
|
|
|
entity_id = "input_select.scene_button";
|
|
|
|
option = "default";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
service = "input_select.select_option";
|
|
|
|
data = {
|
|
|
|
entity_id = "input_select.scene";
|
|
|
|
option = "default";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2020-06-11 12:28:29 +02:00
|
|
|
}
|
2020-06-01 23:20:15 +02:00
|
|
|
{
|
|
|
|
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-06-11 12:28:29 +02:00
|
|
|
|
2020-05-12 22:52:51 +02:00
|
|
|
{
|
2020-06-01 23:20:15 +02:00
|
|
|
alias = "Set Scene To Outside when opening door";
|
2020-05-12 22:52:51 +02:00
|
|
|
trigger = [
|
|
|
|
{
|
|
|
|
platform = "state";
|
2020-06-01 04:12:15 +02:00
|
|
|
# todo : groups are not working right now
|
|
|
|
entity_id = "binary_sensor.door_sensor_2";
|
2020-05-12 22:52:51 +02:00
|
|
|
from = "off";
|
|
|
|
to = "on";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
platform = "state";
|
2020-06-01 04:12:15 +02:00
|
|
|
# todo : groups are not working right now
|
|
|
|
entity_id = "binary_sensor.door_sensor_2";
|
2020-05-12 22:52:51 +02:00
|
|
|
from = "on";
|
|
|
|
to = "off";
|
|
|
|
}
|
|
|
|
];
|
|
|
|
action = {
|
2020-06-01 23:20:15 +02:00
|
|
|
service = "input_select.select_option";
|
2020-06-01 04:12:15 +02:00
|
|
|
data = {
|
2020-06-01 23:20:15 +02:00
|
|
|
entity_id = "input_select.scene";
|
|
|
|
option = "outside";
|
2020-06-01 04:12:15 +02:00
|
|
|
};
|
2020-05-12 22:52:51 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2020-05-03 18:22:28 +02:00
|
|
|
];
|
2020-04-08 16:43:09 +02:00
|
|
|
|
2020-04-14 11:38:40 +02:00
|
|
|
group = let
|
2020-04-14 17:49:09 +02:00
|
|
|
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-05-06 22:35:31 +02:00
|
|
|
|
2020-04-12 21:05:55 +02:00
|
|
|
# overview
|
|
|
|
# --------
|
2020-06-01 23:20:15 +02:00
|
|
|
all_sensors = { name = "Alle Sensoren"; };
|
2020-04-12 21:05:55 +02:00
|
|
|
today = {
|
|
|
|
name = "Today";
|
2020-06-01 23:20:15 +02:00
|
|
|
entities = [ "input_select.scene" ];
|
2020-04-12 19:57:49 +02:00
|
|
|
};
|
2020-04-12 21:05:55 +02:00
|
|
|
# other stuff
|
|
|
|
# -----------
|
2020-06-01 23:20:15 +02:00
|
|
|
tv = { name = "TV"; };
|
|
|
|
all_lights = { name = "Alle Lampen"; };
|
2020-04-12 21:05:55 +02:00
|
|
|
unknown = {
|
|
|
|
name = "Not Used";
|
2020-04-12 21:42:11 +02:00
|
|
|
entities = [ ];
|
2020-04-08 16:43:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
services.home-assistant = {
|
|
|
|
enable = true;
|
2020-06-01 23:20:15 +02:00
|
|
|
#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
|
|
|
}
|