{ pkgs, config, lib, ... }: let unstablePkgs = import { }; 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 = { 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 # lan network "10.1.0.0/24" ]; }]; }; # 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 = [ "default" "night" "outside" "cooking" ]; }; # scenes controlled by buttons input_select.scene_button = { icon = "mdi:brightness-auto"; options = [ "default" "night" ]; }; input_boolean.situation_toggle.icon = "mdi:toggle-switch"; input_boolean.printer_toggle.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"; }; condition = { condition = "template"; value_template = ''{{ states.input_select.scene.state != "outside" }}''; }; action = { service = "input_select.select_next"; data.entity_id = "input_select.scene_button"; }; } { alias = "Button -> Default Scene"; trigger = { platform = "state"; entity_id = "input_boolean.situation_toggle"; }; condition = { condition = "template"; value_template = ''{{ states.input_select.scene.state == "outside" }}''; }; 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"; }; } ]; } { 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') }}"; }; }; } { alias = "Set Scene To Outside when opening door"; 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"; }; }; } # window roles { alias = "windows down in the evening"; trigger = [{ platform = "sun"; event = "sunset"; offset = "+00:10:00"; # 10 min after sunset }]; action = [ { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/fyrtur1/set"; payload_template = ''{"position":"15"}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/fyrtur2/set"; payload_template = ''{"position":"15"}''; }; } ]; } { alias = "windows up in the morning"; trigger = [{ platform = "sun"; event = "sunrise"; offset = "-00:3:00"; # 3 min before sunrise }]; action = [{ service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/fyrtur1/set"; payload_template = ''{"position":"90"}''; }; }]; } { alias = "windows up in the morning"; trigger = [{ platform = "sun"; event = "sunrise"; offset = "+02:30:00"; # 2 1/2 hours after sunrise }]; action = [{ service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/fyrtur2/set"; payload_template = ''{"position":"90"}''; }; }]; } { alias = "heater on in the morning"; trigger = [{ platform = "time"; at = "09:30:00"; }]; action = [ { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater1/set"; # office payload_template = ''{"system_mode":"auto","current_heating_setpoint":21.5}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater2/set"; # office payload_template = ''{"system_mode":"auto","current_heating_setpoint":21.5}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater3/set"; # bed room payload_template = ''{"system_mode":"auto","current_heating_setpoint":20.0}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater4/set"; # storage room payload_template = ''{"system_mode":"auto","current_heating_setpoint":18.0}''; }; } ]; } { alias = "heater off in the evening"; trigger = [{ platform = "time"; at = "23:00:00"; }]; action = [ { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater1/set"; # office payload_template = ''{"system_mode":"off"}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater2/set"; # office payload_template = ''{"system_mode":"off"}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater3/set"; # bed room payload_template = ''{"system_mode":"off"}''; }; } { service = "mqtt.publish"; data_template = { topic = "zigbee2mqtt/heater4/set"; # storage room payload_template = ''{"system_mode":"off"}''; }; } ]; } ]; 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 = 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"; }; }; }; }; }