summaryrefslogtreecommitdiffstats
path: root/krebs/2configs/shack
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2019-09-02 13:57:06 +0200
committermakefu <github@syntax-fehler.de>2019-09-02 13:57:06 +0200
commite4c836b9c4901f99fe870dae8c338dbe648494ac (patch)
tree926dbeffadcf1aab6dc69cfb84c5efa4d79ff941 /krebs/2configs/shack
parent86592a723309d45dc09ff90872c0ee4aa7e52dc0 (diff)
shack/glados: init home-assistant config
Diffstat (limited to 'krebs/2configs/shack')
-rw-r--r--krebs/2configs/shack/glados/default.nix130
-rw-r--r--krebs/2configs/shack/glados/deps/dwd_pollen.nix32
-rw-r--r--krebs/2configs/shack/glados/deps/gtts-token.nix27
-rw-r--r--krebs/2configs/shack/glados/deps/pyhaversion.nix33
-rw-r--r--krebs/2configs/shack/glados/sensors/hass.nix22
-rw-r--r--krebs/2configs/shack/glados/sensors/power.nix25
6 files changed, 269 insertions, 0 deletions
diff --git a/krebs/2configs/shack/glados/default.nix b/krebs/2configs/shack/glados/default.nix
new file mode 100644
index 000000000..a984536bd
--- /dev/null
+++ b/krebs/2configs/shack/glados/default.nix
@@ -0,0 +1,130 @@
+{ config, pkgs, lib, ... }:
+let
+in {
+ services.nginx.virtualHosts."hass.shack".locations."/" = {
+ proxyPass = "http://localhost:8123";
+ extraConfig = ''
+ proxy_http_version 1.1;
+ proxy_set_header Upgrade $http_upgrade;
+ proxy_set_header Connection "upgrade";
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+ proxy_set_header Host $host;
+ proxy_set_header X-Real-IP $remote_addr;
+
+ proxy_buffering off;
+ '';
+ };
+ services.home-assistant = let
+ dwd_pollen = pkgs.fetchFromGitHub {
+ owner = "marcschumacher";
+ repo = "dwd_pollen";
+ rev = "0.1";
+ sha256 = "1af2mx99gv2hk1ad53g21fwkdfdbymqcdl3jvzd1yg7dgxlkhbj1";
+ };
+ in {
+ enable = true;
+ package = (pkgs.home-assistant.overrideAttrs (old: {
+ # TODO: find correct python package
+ installCheckPhase = ''
+ echo LOLLLLLLLLLLLLLL
+ '';
+ postInstall = ''
+ cp -r ${dwd_pollen} $out/lib/python3.7/site-packages/homeassistant/components/dwd_pollen
+ '';
+ })).override {
+ extraPackages = ps: with ps; [
+ python-forecastio jsonrpc-async jsonrpc-websocket mpd2
+ (callPackage ./deps/gtts-token.nix { })
+ (callPackage ./deps/pyhaversion.nix { })
+ ];
+ };
+ autoExtraComponents = true;
+ config = {
+ homeassistant = {
+ name = "Bureautomation";
+ time_zone = "Europe/Berlin";
+ latitude = "48.8265";
+ longitude = "9.0676";
+ elevation = 303;
+ auth_providers = [
+ { type = "homeassistant";}
+ { type = "legacy_api_password";}
+ { type = "trusted_networks";
+ # allow_bypass_login = true;
+ }
+ ];
+ };
+ # https://www.home-assistant.io/components/influxdb/
+ influxdb = {
+ database = "hass";
+ tags = {
+ instance = "wolf";
+ source = "hass";
+ };
+ };
+ mqtt = {
+ broker = "localhost";
+ port = 1883;
+ client_id = "home-assistant";
+ keepalive = 60;
+ protocol = 3.1;
+ birth_message = {
+ topic = "glados/hass/status/LWT";
+ payload = "Online";
+ qos = 1;
+ retain = true;
+ };
+ will_message = {
+ topic = "glados/hass/status/LWT";
+ payload = "Offline";
+ qos = 1;
+ retain = true;
+ };
+ };
+ switch = [];
+ light = [];
+ media_player = [
+ { platform = "mpd";
+ host = "lounge.mpd.shack";
+ }
+ ];
+ sensor =
+ [{ platform = "version"; }]
+ ++ (import ./sensors/hass.nix)
+ ++ (import ./sensors/power.nix);
+
+ camera = [];
+
+ frontend = { };
+ http = {
+ # TODO: https://github.com/home-assistant/home-assistant/issues/16149
+ base_url = "http://hass.shack";
+ use_x_forwarded_for = true;
+ trusted_proxies = "127.0.0.1";
+ api_password = "shackit";
+ trusted_networks = [
+ "127.0.0.1/32"
+ "10.42.0.0/16"
+ "::1/128"
+ "fd00::/8"
+ ];
+ };
+ conversation = {};
+ history = {};
+ logbook = {};
+ tts = [
+ { platform = "google";
+ language = "de";
+ }
+ { platform = "picotts";
+ language = "de-DE";
+ }
+ ];
+ recorder = {};
+ sun = {};
+
+ automation = [];
+ device_tracker = [];
+ };
+ };
+}
diff --git a/krebs/2configs/shack/glados/deps/dwd_pollen.nix b/krebs/2configs/shack/glados/deps/dwd_pollen.nix
new file mode 100644
index 000000000..39d9c3069
--- /dev/null
+++ b/krebs/2configs/shack/glados/deps/dwd_pollen.nix
@@ -0,0 +1,32 @@
+{ lib
+, buildPythonPackage
+, fetchFromGitHub
+, python
+, voluptuous
+}:
+
+buildPythonPackage rec {
+ format = "other";
+ pname = "dwd_pollen";
+ version = "0.1";
+
+ src = fetchFromGitHub {
+ owner = "marcschumacher";
+ repo = "dwd_pollen";
+ rev = version;
+ sha256 = "1af2mx99gv2hk1ad53g21fwkdfdbymqcdl3jvzd1yg7dgxlkhbj1";
+ };
+ propagatedBuildInputs = [
+ voluptuous
+ ];
+ installPhase = ''
+ install -D -t $out/${python.sitePackages}/homeassistant/components/sensor/dwd_pollen *
+ '';
+
+ meta = with lib; {
+ description = "Home Assistant component to retrieve Pollen data from DWD (Germany)";
+ homepage = https://github.com/marcschumacher/dwd_pollen;
+ license = licenses.mit;
+ maintainers = [ maintainers.makefu ];
+ };
+}
diff --git a/krebs/2configs/shack/glados/deps/gtts-token.nix b/krebs/2configs/shack/glados/deps/gtts-token.nix
new file mode 100644
index 000000000..69640f03d
--- /dev/null
+++ b/krebs/2configs/shack/glados/deps/gtts-token.nix
@@ -0,0 +1,27 @@
+{ lib
+, buildPythonPackage
+, fetchPypi
+, requests
+}:
+
+buildPythonPackage rec {
+ pname = "gtts-token";
+ version = "1.1.3";
+
+ src = fetchPypi {
+ pname = "gTTS-token";
+ inherit version;
+ sha256 = "9d6819a85b813f235397ef931ad4b680f03d843c9b2a9e74dd95175a4bc012c5";
+ };
+
+ propagatedBuildInputs = [
+ requests
+ ];
+
+ meta = with lib; {
+ description = "Calculates a token to run the Google Translate text to speech";
+ homepage = https://github.com/boudewijn26/gTTS-token;
+ license = licenses.mit;
+ # maintainers = [ maintainers. ];
+ };
+}
diff --git a/krebs/2configs/shack/glados/deps/pyhaversion.nix b/krebs/2configs/shack/glados/deps/pyhaversion.nix
new file mode 100644
index 000000000..a75c6a976
--- /dev/null
+++ b/krebs/2configs/shack/glados/deps/pyhaversion.nix
@@ -0,0 +1,33 @@
+{ lib
+, buildPythonPackage
+, fetchpatch
+, fetchPypi
+, aiohttp
+, async-timeout
+}:
+
+buildPythonPackage rec {
+ pname = "pyhaversion";
+ version = "2.2.1";
+
+ src = fetchPypi {
+ inherit pname version;
+ sha256 = "72b65aa25d7b2dbb839a4d0218df2005c2335e93526035904d365bb668030b9f";
+ };
+ patches = [
+ (fetchpatch { url = "https://github.com/makefu/pyhaversion/commit/f3bdc38970272cd345c2cfbde3037ea492ca27c4.patch";
+ sha256 =
+ "1rhq4z7mdgnwhwpf5fmarnbc1ba3qysk1wqjdr0hvbzi8vmvbfcc";})
+ ];
+ doCheck = false;
+ propagatedBuildInputs = [
+ aiohttp
+ async-timeout
+ ];
+
+ meta = with lib; {
+ description = "";
+ homepage = https://github.com/ludeeus/pyhaversion;
+ # maintainers = [ maintainers. ];
+ };
+}
diff --git a/krebs/2configs/shack/glados/sensors/hass.nix b/krebs/2configs/shack/glados/sensors/hass.nix
new file mode 100644
index 000000000..634758701
--- /dev/null
+++ b/krebs/2configs/shack/glados/sensors/hass.nix
@@ -0,0 +1,22 @@
+let
+ esphome_temp = name:
+ { platform = "mqtt";
+ name = "${name} Temperature";
+ device_class = "temperature";
+ state_topic = "glados/${name}/sensor/temperature/state";
+ availability_topic = "glados/${name}/status";
+ payload_available = "online";
+ payload_not_available = "offline";
+ };
+ esphome_hum = name:
+ { platform = "mqtt";
+ device_class = "humidity";
+ name = "${name} Humidity";
+ state_topic = "glados/${name}/sensor/humidity/state";
+ availability_topic = "glados/${name}/status";
+ payload_available = "online";
+ payload_not_available = "offline";
+ };
+in
+ (map esphome_temp [ "lounge" "werkstatt" "herrenklo" "dusche" "fablab" "whc" ])
+ ++ (map esphome_hum [ "lounge" "werkstatt" "herrenklo" "dusche" "fablab" "whc" ])
diff --git a/krebs/2configs/shack/glados/sensors/power.nix b/krebs/2configs/shack/glados/sensors/power.nix
new file mode 100644
index 000000000..940888c7d
--- /dev/null
+++ b/krebs/2configs/shack/glados/sensors/power.nix
@@ -0,0 +1,25 @@
+let
+ power_x = name: phase:
+ { platform = "mqtt";
+ name = "${phase} ${name}";
+ state_topic = "/power/total/${phase}/${name}";
+ availability_topic = "/power/lwt";
+ payload_available = "Online";
+ payload_not_available = "Offline";
+ };
+ power_consumed =
+ { platform = "mqtt";
+ name = "Power Consumed";
+ state_topic = "/power/total/consumed";
+ availability_topic = "/power/lwt";
+ payload_available = "Online";
+ payload_not_available = "Offline";
+ };
+ power_volt = power_x "Voltage";
+ power_watt = power_x "Power";
+ power_curr = power_x "Current";
+in
+ (map power_volt [ "L1" "L2" "L3" ])
+++ (map power_watt [ "L1" "L2" "L3" ])
+++ (map power_curr [ "L1" "L2" "L3" ])
+++ [ power_consumed ]