{ pkgs, config, lib, ... }: { imports = [ #./home-assistant/mpd.nix #./home-assistant/timer.nix ./home-assistant/light-control.nix ./home-assistant/iot-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 ]; networking.firewall.allowedTCPPorts = [ 8123 ]; networking.firewall.allowedUDPPorts = [ 8123 ]; services.homeAssistantConfig = { # turn on to edit GUI lovelace = { }; homeassistant = { name = "Home"; latitude = 51.444847; longitude = 6.967006; elevation = 116; unit_system = "metric"; time_zone = config.time.timeZone; auth_providers = [{ type = "trusted_networks"; trusted_networks = [ config.module.cluster.services.tinc."private".networkSubnet "192.168.178.0/24" "127.0.0.1" ]; }]; }; # needed, don't know why default_config = { }; config = { }; # to grab metrics via prometheus prometheus.namespace = "hass"; # manual state # ------------ # all scenes input_select.scene = { icon = "mdi:brightness-auto"; options = [ "up-bright" "up-dark" "half" "down" "night" "outside" ]; }; # scenes controlled by buttons input_select.scene_button = { icon = "mdi:brightness-auto"; options = [ "up-dark" "night" ]; }; input_boolean.situation_toggle.icon = "mdi:toggle-switch"; input_boolean.printer_toggle.icon = "mdi:toggle-switch"; input_boolean.windows_up.icon = "mdi:toggle-switch"; automation = [ { alias = "Hold Button -> Toggle Printer"; trigger = { platform = "state"; entity_id = "input_boolean.printer_toggle"; }; action = { service = "switch.toggle"; data.entity_id = "switch.pal02"; }; } { alias = "set light-control scene"; trigger = { platform = "state"; entity_id = "input_select.scene"; }; action = { service = "mqtt.publish"; data_template = { topic = "control/lights/set"; payload_template = ''{"scene":"{{ states('input_select.scene')}}"}''; }; }; } # control situation with buttons { alias = "Button -> Change Scene"; 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') }}"; }; }; } # outside and home { alias = "when opening door I'm outside"; trigger = [ { platform = "state"; # todo : groups are not working right now entity_id = "binary_sensor.door_sensor_4"; from = "off"; to = "on"; } { platform = "state"; # todo : groups are not working right now entity_id = "binary_sensor.door_sensor_4"; from = "on"; to = "off"; } ]; action = [{ service = "input_select.select_option"; data = { entity_id = "input_select.scene"; option = "outside"; }; }]; } { alias = "reset everything when back home"; 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" }}''; }; action = [{ service = "input_select.select_option"; data = { entity_id = "input_select.scene"; option = "up-dark"; }; }]; } ]; group = let create_room = { name, description }: { "${name}" = { name = "${description}"; entities = [ ]; }; }; 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"; } ]) // { # overview # -------- all_sensors = { name = "Alle Sensoren"; }; today = { name = "Today"; entities = [ "input_select.scene" ]; }; # other stuff # ----------- tv = { name = "TV"; }; all_lights = { name = "Alle Lampen"; }; unknown = { name = "Not Used"; entities = [ ]; }; }; }; services.home-assistant = { enable = true; package = pkgs.unstable.home-assistant; #package = pkgs.unstable.home-assistant.override { # python3 = pkgs.unstable.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" ]; extraConfig = '' proxy_buffering off; ''; locations."/" = { proxyPass = "http://127.0.0.1:8123"; proxyWebsockets = true; extraConfig = '' proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; ''; }; }; }; }; }