From 8a887226e7af6b80d0c1b534c3325e09e0a15b47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kier=C3=A1n=20Meinhardt?= Date: Wed, 21 Oct 2020 00:36:10 +0200 Subject: [PATCH] feat(hass): init --- systems/toum/configuration.nix | 1 + systems/toum/hass/default.nix | 64 ++++++++++++++ systems/toum/hass/frontend.nix | 46 ++++++++++ systems/toum/hass/lib.nix | 16 ++++ systems/toum/hass/themes/clear-dark.nix | 72 +++++++++++++++ systems/toum/hass/themes/clear.nix | 52 +++++++++++ systems/toum/hass/zigbee.nix | 112 ++++++++++++++++++++++++ 7 files changed, 363 insertions(+) create mode 100644 systems/toum/hass/default.nix create mode 100644 systems/toum/hass/frontend.nix create mode 100644 systems/toum/hass/lib.nix create mode 100644 systems/toum/hass/themes/clear-dark.nix create mode 100644 systems/toum/hass/themes/clear.nix create mode 100644 systems/toum/hass/zigbee.nix diff --git a/systems/toum/configuration.nix b/systems/toum/configuration.nix index eac12b6..d37d0e8 100644 --- a/systems/toum/configuration.nix +++ b/systems/toum/configuration.nix @@ -7,6 +7,7 @@ let in { imports = [ ./hardware-configuration.nix + ./hass ./telegram-bots diff --git a/systems/toum/hass/default.nix b/systems/toum/hass/default.nix new file mode 100644 index 0000000..d483efd --- /dev/null +++ b/systems/toum/hass/default.nix @@ -0,0 +1,64 @@ +{ config, pkgs, lib, ... }: +let + inherit (import ./lib.nix) triggers; +in +{ + disabledModules = [ + "services/misc/home-assistant.nix" + ]; + + imports = [ + ./zigbee.nix + ./frontend.nix + + ]; + + services.home-assistant = { + enable = true; + configWritable = true; + lovelaceConfigWritable = true; + openFirewall = true; + config = { + homeassistant = { + name = "Toum"; + latitude = 52.461; + longitude = 13.378; + elevation = 90; # TODO find out how high I live + unit_system = "metric"; + time_zone = config.time.timeZone; + }; + config = {}; + discovery = {}; + system_health = {}; + history = {}; + tradfri.host = "192.168.178.28"; + sun = {}; + shopping_list = {}; + sensor = [ + { + platform = "dwd_weather_warnings"; + region_name = "Berlin"; + } + ]; + mqtt = { + broker = "localhost"; + port = 1883; + client_id = "home-assistant"; + username = "albrecht"; + password = lib.strings.fileContents ; + keepalive = 60; + protocol = "3.1"; + + discovery = true; + birth_message = { + topic = "/hass/status"; + payload = "online"; + }; + will_message = { + topic = "/hass/status"; + payload = "offline"; + }; + }; + }; + }; +} diff --git a/systems/toum/hass/frontend.nix b/systems/toum/hass/frontend.nix new file mode 100644 index 0000000..76160e0 --- /dev/null +++ b/systems/toum/hass/frontend.nix @@ -0,0 +1,46 @@ +let + inherit (import ./lib.nix) triggers; +in +{ + disabledModules = [ + "services/misc/home-assistant.nix" + ]; + + imports = [ + + ]; + + + services.home-assistant.config = { + frontend = { + themes = { + day_theme = import ./themes/clear.nix; + night_theme = import ./themes/clear-dark.nix; + }; + }; + automation = [ + { + alias = "Night Theme"; + hide_entity = true; + trigger = triggers.night; + action = [ + { + service = "frontend.set_theme"; + data.name = "night_theme"; + } + ]; + } + { + alias = "Day Theme"; + hide_entity = true; + trigger = triggers.day; + action = [ + { + service = "frontend.set_theme"; + data.name = "day_theme"; + } + ]; + } + ]; + }; +} diff --git a/systems/toum/hass/lib.nix b/systems/toum/hass/lib.nix new file mode 100644 index 0000000..0af04fc --- /dev/null +++ b/systems/toum/hass/lib.nix @@ -0,0 +1,16 @@ +{ + triggers = { + night = { + platform = "numeric_state"; + entity_id = "sun.sun"; + value_template = "{{ state.attributes.elevation }}"; + below = -4.0; + }; + day = { + platform = "numeric_state"; + entity_id = "sun.sun"; + value_template = "{{ state.attributes.elevation }}"; + above = 0; + }; + }; +} diff --git a/systems/toum/hass/themes/clear-dark.nix b/systems/toum/hass/themes/clear-dark.nix new file mode 100644 index 0000000..11a4b73 --- /dev/null +++ b/systems/toum/hass/themes/clear-dark.nix @@ -0,0 +1,72 @@ +rec { +# Colors + text-color = "#DADADB"; # Grey text + text-medium-light-color = "#A0A2A8"; # Medium-light grey text + text-medium-color = "#80828A"; # Medium grey text + text-dark-color = "#6A6B74"; # Dark grey text + accent-color = "#008bef"; # Blue + accent-medium-color = "#2484C9"; # Decent blue + background-color = "#3b4049"; # Dark grey background + background-color-2 = "#484E59"; # Light grey background + background-card-color = "#434952"; # Grey background + border-color = "#383C46"; # Grey border + + # Header + app-header-background-color = "#363941"; # Background color + + # Text + primary-color = text-color; + text-primary-color = text-color; + + # Left Menu + paper-listbox-background-color = background-color; # Background + sidebar-icon-color = text-medium-color; # icons + sidebar-selected-icon-color = text-medium-light-color; # Selected row icon and background (15%) + sidebar-selected-text-color = text-color; # Selected row label + + # UI + paper-card-header-color = text-color; # Title in settings + primary-background-color = background-color; # Background (also title background in left menu) + mdc-theme-primary = accent-medium-color; # Action Buttons (save, restart etc.) + card-background-color = background-card-color; # Entity Registry Background + + # Card + paper-card-background-color = background-card-color; # Background + dark-primary-color = text-color; + primary-text-color = text-color; + paper-listbox-color = text-color; + light-primary-color = text-dark-color; + secondary-text-color = text-medium-color; + disabled-text-color = text-dark-color; + paper-dialog-button-color = text-color; + secondary-background-color = background-color-2; # Background more info title + + # Icons + paper-item-icon-color = text-dark-color; # Off + paper-item-icon-active-color = accent-color; # On + + # Switches + switch-checked-button-color = text-medium-light-color; # Knob On + switch-unchecked-button-color = text-medium-light-color; # Knob Off + switch-checked-track-color = "#009FFF"; # Background On + switch-unchecked-track-color = "#767682"; # Background Off + + # Slider + paper-slider-active-color = accent-color; # Line On + paper-slider-knob-color = text-medium-light-color; # Knob On + paper-slider-container-color = text-dark-color; # Line Off + paper-slider-knob-start-color = text-medium-light-color; # Knob Off + + # Badges + label-badge-text-color = text-color; + label-badge-background-color = "rgba(54, 57, 65, 0.6)"; + + # Shadows + ha-card-box-shadow = "inset 0px 0px 0px 1px var(--border-color)"; + + # HACS + hacs-badge-color = accent-color; # New Badge + hacs-status-installed = text-color; # Installed Icon + hacs-status-pending-restart = text-dark-color; # Restart Icon + hacs-status-pending-update = accent-color; +} diff --git a/systems/toum/hass/themes/clear.nix b/systems/toum/hass/themes/clear.nix new file mode 100644 index 0000000..64c18ec --- /dev/null +++ b/systems/toum/hass/themes/clear.nix @@ -0,0 +1,52 @@ +rec { + text-color = "#636B75"; # Grey text + text-medium-color = "#8c96a5"; # Medium grey text + text-light-color = "#BAC0C6"; # Light grey text + accent-color = "#00a1ff"; # Blue + background-color = "#F7F8F9"; # Light grey background + background-color-2 = "#F4F5F6"; # Light grey background + background-card-color = "rgba(255,255,255,1.0)"; # White background + border-color = "#E8E8E8"; # Light grey border + + # Header + primary-color = text-color; # Background + text-primary-color = "#FFF"; # Text + + # Left Menu + paper-listbox-background-color = background-color; # Background + # TODO = Text and Icons + + # UI + paper-card-header-color = text-color; # Title in settings + primary-background-color = background-color; # Background color (also title background in left menu) + + # Card + paper-card-background-color = background-card-color; # Background + dark-primary-color = text-color; + primary-text-color = text-color; + paper-listbox-color = text-color; + light-primary-color = text-light-color; + secondary-text-color = text-medium-color; + disabled-text-color = text-light-color; + paper-dialog-button-color = text-color; + secondary-background-color = background-color-2; # Background more info title + + # Icons + paper-item-icon-color = text-light-color; # Off + paper-item-icon-active-color = accent-color; # On + + # Switches + switch-checked-button-color = "#FFF"; # Knob On + switch-unchecked-button-color = "#FFF"; # Knob Off + switch-checked-track-color = "#0077FF"; # Background On + switch-unchecked-track-color = disabled-text-color; # Background Off + + # Slider + paper-slider-active-color = accent-color; # Line On + paper-slider-container-color = "#e5e7ea"; # Line Off + paper-slider-knob-color = text-light-color; # Knob On + paper-slider-knob-start-color = text-light-color; # Knob Off + + # Shadows + ha-card-box-shadow = "inset 0px 0px 0px 1px var(--border-color)"; +} diff --git a/systems/toum/hass/zigbee.nix b/systems/toum/hass/zigbee.nix new file mode 100644 index 0000000..1107f17 --- /dev/null +++ b/systems/toum/hass/zigbee.nix @@ -0,0 +1,112 @@ +{ config, pkgs, lib, ... }: +let + inherit (import ) genid; +in +{ + disabledModules = [ + "services/misc/home-assistant.nix" + ]; + + imports = [ + + + ]; + + ids = { + uids.zigbee2mqtt = genid "zigbee2mqtt"; + gids.zigbee2mqtt = genid "zigbee2mqtt"; + }; + + services.zigbee2mqtt = { + enable = true; + package = pkgs.unstable.zigbee2mqtt; + config = { + permit_join = true; + homeassistant = true; + serial.port = "/dev/ttyACM0"; + mqtt = { + discovery = true; + base_topic = "zigbee"; + server = "mqtt://192.168.178.24"; # Rasperry local IP + user = "albrecht"; + password = lib.strings.fileContents ; + }; + }; + }; + + services.mosquitto = { + enable = true; + host = "0.0.0.0"; + allowAnonymous = false; + checkPasswords = true; + users."albrecht" = { + password = lib.strings.fileContents ; + acl = [ "topic readwrite #" ]; + }; + }; + + environment.systemPackages = [ pkgs.mosquitto ]; + + services.home-assistant = { + config = { + switch = [ + { + platform = "mqtt"; + name = "zigbee2mqtt_join"; + state_topic = "/zigbee2mqtt/bridge/config/permit_join"; + command_topic = "/zigbee2mqtt/bridge/config/permit_join"; + payload_on = "true"; + payload_off = "false"; + } + ]; + timer.zigbee_permit_join = { + name = "Zigbee Time remaining"; + duration = 120; + }; + automation = [ + # Automation to start timer when enable join is turned on + { + id = "zigbee_join_enabled"; + alias = ""; + hide_entity = "true"; + trigger = { + platform = "state"; + entity_id = "switch.zigbee2mqtt_join"; + to = "on"; + }; + action = { + service = "timer.start"; + entity_id = "timer.zigbee_permit_join"; + }; + } + # Automation to stop timer when switch turned off and turn off switch when timer finished + { + id = "zigbee_join_disabled"; + hide_entity = "true"; + trigger = [ + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.zigbee_permit_join"; + } + { + platform = "state"; + entity_id = "switch.zigbee2mqtt_join"; + to = "off"; + } + ]; + action = [ + { + service = "timer.cancel"; + data.entity_id = "timer.zigbee_permit_join"; + } + { + service = "switch.turn_off"; + entity_id = "switch.zigbee2mqtt_join"; + } + ]; + } + ]; + }; + }; +}