From 64eee34bbeac88ef8c4c27c8b4245ac0aaa7bfe7 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 17 Jun 2019 07:53:44 +0200 Subject: ma wiregrill: init --- makefu/2configs/wireguard/wiregrill.nix | 46 +++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 makefu/2configs/wireguard/wiregrill.nix (limited to 'makefu/2configs') diff --git a/makefu/2configs/wireguard/wiregrill.nix b/makefu/2configs/wireguard/wiregrill.nix new file mode 100644 index 000000000..082090755 --- /dev/null +++ b/makefu/2configs/wireguard/wiregrill.nix @@ -0,0 +1,46 @@ +with import ; +{ config, pkgs, ... }: let + + self = config.krebs.build.host.nets.wiregrill; + isRouter = !isNull self.via; # via "internet" is not set + ext-if = config.makefu.server.primary-itf; + +in mkIf (hasAttr "wiregrill" config.krebs.build.host.nets) { + #hack for modprobe inside containers + systemd.services."wireguard-wiregrill".path = mkIf config.boot.isContainer (mkBefore [ + (pkgs.writeDashBin "modprobe" ":") + ]); + + boot.kernel.sysctl = mkIf isRouter { + "net.ipv6.conf.all.forwarding" = 1; + }; + + networking.firewall = { + allowedUDPPorts = [ self.wireguard.port ]; + extraCommands = '' + iptables -A FORWARD -i wiregrill -o wiregrill -j ACCEPT + ''; + }; + + networking.wireguard.interfaces.wiregrill = { + ips = + (optional (!isNull self.ip4) self.ip4.addr) ++ + (optional (!isNull self.ip6) self.ip6.addr); + listenPort = self.wireguard.port; + privateKeyFile = (toString ) + "/wiregrill.key"; + allowedIPsAsRoutes = true; + peers = mapAttrsToList + (_: host: { + allowedIPs = if isRouter then + (optional (!isNull host.nets.wiregrill.ip4) host.nets.wiregrill.ip4.addr) ++ + (optional (!isNull host.nets.wiregrill.ip6) host.nets.wiregrill.ip6.addr) + else + host.nets.wiregrill.wireguard.subnets + ; + endpoint = mkIf (!isNull host.nets.wiregrill.via) (host.nets.wiregrill.via.ip4.addr + ":${toString host.nets.wiregrill.wireguard.port}"); + persistentKeepalive = mkIf (!isNull host.nets.wiregrill.via) 61; + publicKey = (replaceStrings ["\n"] [""] host.nets.wiregrill.wireguard.pubkey); + }) + (filterAttrs (_: h: hasAttr "wiregrill" h.nets) config.krebs.hosts); + }; +} -- cgit v1.2.3 From ea8d45793ef7375dcb9c324d1a235f47898fdef3 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 17 Jun 2019 07:54:31 +0200 Subject: ma bureautomation: prepare dwd_pollen, update presence --- makefu/2configs/bureautomation/default.nix | 14 +++---- .../bureautomation/device_tracker/openwrt.nix | 3 ++ makefu/2configs/bureautomation/dwd_pollen.nix | 32 ++++++++++++++++ makefu/2configs/bureautomation/gtts-token.nix | 27 ++++++++++++++ makefu/2configs/bureautomation/hass.nix | 43 +++++++++++++++++++--- makefu/2configs/bureautomation/sensor/pollen.nix | 7 ++++ 6 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 makefu/2configs/bureautomation/dwd_pollen.nix create mode 100644 makefu/2configs/bureautomation/gtts-token.nix create mode 100644 makefu/2configs/bureautomation/sensor/pollen.nix (limited to 'makefu/2configs') diff --git a/makefu/2configs/bureautomation/default.nix b/makefu/2configs/bureautomation/default.nix index 1782becd8..56c845744 100644 --- a/makefu/2configs/bureautomation/default.nix +++ b/makefu/2configs/bureautomation/default.nix @@ -24,22 +24,20 @@ in { ./ota.nix ]; services.logstash = { - package = pkgs.logstash5; + package = pkgs.logstash7; + plugins = [ pkgs.logstash-output-exec ]; enable = true; inputConfig = '' http { port => ${toString port} host => "127.0.0.1" + type => "schlechteluft" } ''; - filterConfig = '' - ''; outputConfig = '' - stdout { codec => json } - exec { command => "${runit} '%{ruleName}' '%{state}'" } - ''; - extraSettings = '' - path.plugins: [ "${pkgs.logstash-output-exec}" ] + if [type] == "schlechteluft" { + exec { command => "${runit} '%{ruleName}' '%{state}'" } + } ''; }; } diff --git a/makefu/2configs/bureautomation/device_tracker/openwrt.nix b/makefu/2configs/bureautomation/device_tracker/openwrt.nix index 0db9821a1..d32eab60f 100644 --- a/makefu/2configs/bureautomation/device_tracker/openwrt.nix +++ b/makefu/2configs/bureautomation/device_tracker/openwrt.nix @@ -1,3 +1,6 @@ +# requires `opkg install luci-mod-rpc` on router +# see https://www.home-assistant.io/components/luci/ + [ { platform = "luci"; name = "router"; diff --git a/makefu/2configs/bureautomation/dwd_pollen.nix b/makefu/2configs/bureautomation/dwd_pollen.nix new file mode 100644 index 000000000..39d9c3069 --- /dev/null +++ b/makefu/2configs/bureautomation/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/makefu/2configs/bureautomation/gtts-token.nix b/makefu/2configs/bureautomation/gtts-token.nix new file mode 100644 index 000000000..69640f03d --- /dev/null +++ b/makefu/2configs/bureautomation/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/makefu/2configs/bureautomation/hass.nix b/makefu/2configs/bureautomation/hass.nix index ace1d10ce..ed9cb0905 100644 --- a/makefu/2configs/bureautomation/hass.nix +++ b/makefu/2configs/bureautomation/hass.nix @@ -1,12 +1,32 @@ -{ pkgs, lib, ... }: +{ config, pkgs, lib, ... }: let kodi-host = "192.168.8.11"; + in { networking.firewall.allowedTCPPorts = [ 8123 ]; state = [ "/var/lib/hass/known_devices.yaml" ]; - services.home-assistant = { + 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.override { python3 = pkgs.python36; }; + package = (pkgs.home-assistant.overrideAttrs (old: { + # TODO: find correct python package + postInstall = '' + cp -r ${dwd_pollen} $out/lib/python3.7/site-packages/homeassistant/components/dwd_pollen + ''; + })).override { + extraPackages = ps: with ps; [ + pkgs.pico2wave + python-forecastio jsonrpc-async jsonrpc-websocket + (callPackage ./gtts-token.nix { }) + ]; + }; + autoExtraComponents = true; config = { homeassistant = { name = "Bureautomation"; @@ -84,6 +104,7 @@ in { (import ./binary_sensor/motion.nix); sensor = + (import ./sensor/pollen.nix) ++ (import ./sensor/espeasy.nix) ++ ((import ./sensor/outside.nix) {inherit lib;}) ++ (import ./sensor/influxdb.nix) ++ @@ -99,6 +120,7 @@ in { frontend = { }; http = { # TODO: https://github.com/home-assistant/home-assistant/issues/16149 + base_url = "http://192.168.8.11:8123"; api_password = "sistemas"; trusted_networks = [ "127.0.0.1/32" @@ -110,7 +132,18 @@ in { conversation = {}; history = {}; logbook = {}; - tts = [ { platform = "google";} ]; + tts = [ + { platform = "google"; + language = "de"; + } + { platform = "voicerss"; + api_key = builtins.readFile ; + language = "de-de"; + } + { platform = "picotts"; + language = "de-DE"; + } + ]; recorder = {}; sun = {}; telegram_bot = [ @@ -147,6 +180,7 @@ in { "device_tracker.daniel_phone" "device_tracker.carsten_phone" "device_tracker.thierry_phone" + "device_tracker.frank_phone" # "person.thorsten" # "person.felix" # "person.ecki" @@ -181,7 +215,6 @@ in { "sensor.dark_sky_uv_index" # "sensor.dark_sky_pressure" "sensor.dark_sky_hourly_summary" - "device_tracker.router" ]; }; # only for automation diff --git a/makefu/2configs/bureautomation/sensor/pollen.nix b/makefu/2configs/bureautomation/sensor/pollen.nix new file mode 100644 index 000000000..506dbf123 --- /dev/null +++ b/makefu/2configs/bureautomation/sensor/pollen.nix @@ -0,0 +1,7 @@ +[ { + platform = "dwd_pollen"; + partsregion_ids = [ + 112 + ]; +} +] -- cgit v1.2.3 From 6245b549c66df46a92d76f5d146e545401619258 Mon Sep 17 00:00:00 2001 From: makefu Date: Mon, 17 Jun 2019 08:00:46 +0200 Subject: ma cake.r: remove dangling config --- makefu/2configs/Reaktor/bgt.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 makefu/2configs/Reaktor/bgt.nix (limited to 'makefu/2configs') diff --git a/makefu/2configs/Reaktor/bgt.nix b/makefu/2configs/Reaktor/bgt.nix new file mode 100644 index 000000000..42325bcd6 --- /dev/null +++ b/makefu/2configs/Reaktor/bgt.nix @@ -0,0 +1,15 @@ +{ pkgs, ... }: +{ + krebs.Reaktor.reaktor-bgt = { + nickname = "Reaktor|bgt"; + workdir = "/var/lib/Reaktor/bgt"; + channels = [ "#binaergewitter" ]; + plugins = with pkgs.ReaktorPlugins; + [ titlebot + # stockholm-issue + nixos-version + # shack-correct + # sed-plugin + random-emoji ]; + }; +} -- cgit v1.2.3 From 405d9555e4cf2fc171900f03621acfd523641dee Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 18 Jun 2019 07:47:49 +0200 Subject: ma mail: pin tarball --- makefu/2configs/mail/mail.euer.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'makefu/2configs') diff --git a/makefu/2configs/mail/mail.euer.nix b/makefu/2configs/mail/mail.euer.nix index d27b888a7..f51e54b80 100644 --- a/makefu/2configs/mail/mail.euer.nix +++ b/makefu/2configs/mail/mail.euer.nix @@ -1,7 +1,11 @@ { config, pkgs, ... }: { imports = [ - (builtins.fetchTarball "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/v2.2.1/nixos-mailserver-v2.2.1.tar.gz") + (builtins.fetchTarball { + url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/v2.2.1/nixos-mailserver-v2.2.1.tar.gz"; + sha256 = "03d49v8qnid9g9rha0wg2z6vic06mhp0b049s3whccn1axvs2zzx"; + } + ) ]; mailserver = { -- cgit v1.2.3 From f880fb21ca540506ba27e49c6ba92aa83923cd43 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 19 Jun 2019 19:19:39 +0200 Subject: ma extra-gui: no more rambox --- makefu/2configs/tools/extra-gui.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'makefu/2configs') diff --git a/makefu/2configs/tools/extra-gui.nix b/makefu/2configs/tools/extra-gui.nix index dfb4183df..5f8614719 100644 --- a/makefu/2configs/tools/extra-gui.nix +++ b/makefu/2configs/tools/extra-gui.nix @@ -14,6 +14,6 @@ saleae-logic gitAndTools.gitFull signal-desktop - rambox + # rambox ]; } -- cgit v1.2.3 From 4ecfee1606645c14dc258c34e087342306f698b5 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 28 Jun 2019 22:01:27 +0200 Subject: ma bureautomation: add 10h timers for all participants move into combination folders, fix mittagessen, add working tts with random output --- .../bureautomation/automation/10h_timer.nix | 154 --------- .../bureautomation/automation/bureau-shutdown.nix | 4 +- .../bureautomation/combination/10h_timers.nix | 383 +++++++++++++++++++++ .../2configs/bureautomation/combination/README.md | 3 + .../bureautomation/combination/mittagessen.nix | 89 +++++ makefu/2configs/bureautomation/hass.nix | 56 +-- .../2configs/bureautomation/script/multi_blink.nix | 8 + 7 files changed, 516 insertions(+), 181 deletions(-) delete mode 100644 makefu/2configs/bureautomation/automation/10h_timer.nix create mode 100644 makefu/2configs/bureautomation/combination/10h_timers.nix create mode 100644 makefu/2configs/bureautomation/combination/README.md create mode 100644 makefu/2configs/bureautomation/combination/mittagessen.nix (limited to 'makefu/2configs') diff --git a/makefu/2configs/bureautomation/automation/10h_timer.nix b/makefu/2configs/bureautomation/automation/10h_timer.nix deleted file mode 100644 index dd747114e..000000000 --- a/makefu/2configs/bureautomation/automation/10h_timer.nix +++ /dev/null @@ -1,154 +0,0 @@ -[ - { alias = "start Felix 10h"; - trigger = { - platform = "state"; - entity_id = [ "device_tracker.felix_phone" "device_tracker.felix_laptop" ]; - from = "not_home"; - to = "home"; - }; - condition = { - condition = "and"; - conditions = [ - { - condition = "state"; - entity_id = "timer.felix_10h"; - state = "idle"; - } - { - condition = "time"; - after = "06:00:00"; - before = "12:00:00"; - } - ]; - }; - action = [ - { service = "timer.start"; - entity_id = [ "timer.felix_10h" "timer.felix_8_30h" "timer.felix_7h" ] ; - } - { service = "homeassistant.turn_on"; - entity_id = [ - "script.buzz_red_led_fast" - "script.blitz_10s" - ]; - } - { service = "light.turn_on"; - data = { - effect = "2"; - entity_id = [ "light.status_felix" ]; - }; - } - ]; - } - - { alias = "Disable Felix timer at button press"; - trigger = { - platform = "state"; - entity_id = "binary_sensor.redbutton"; - to = "on"; - }; - condition = { - condition = "and"; - conditions = [ - { - condition = "state"; - entity_id = "timer.felix_10h"; - state = "active"; - } - { - condition = "time"; - after = "12:00:00"; - before = "22:00:00"; - } - ]; - }; - action = - [ - { - service = "timer.cancel"; - entity_id = [ "timer.felix_10h" "timer.felix_8_30h" "timer.felix_7h" ]; - } - { - service = "homeassistant.turn_on"; - entity_id = [ "script.buzz_red_led_fast" ]; - } - { - service = "homeassistant.turn_off"; - entity_id = [ "light.status_felix" ]; - } - ]; - } - - { - alias = "Genug gearbeitet Felix"; - trigger = - { - platform = "event"; - event_type = "timer.finished"; - event_data.entity_id = "timer.felix_7h"; - }; - action = - [ - { service = "light.turn_on"; - data = { - rgb_color= [0 255 0]; - # effect = "0"; - entity_id = [ "light.status_felix" ]; - }; - } - ]; - } - - { - alias = "nun aber nach hause"; - trigger = - { - platform = "event"; - event_type = "timer.finished"; - event_data.entity_id = "timer.felix_8_30h"; - }; - action = - [ - { service = "light.turn_on"; - data = { - rgb_color= [255 255 0]; - # effect = "0"; - entity_id = [ "light.status_felix" ]; - }; - } - ]; - } - - { - alias = "Zu lange Felix!"; - trigger = - { - platform = "event"; - event_type = "timer.finished"; - event_data.entity_id = "timer.felix_10h"; - }; - action = - [ - { - service = "notify.telegrambot"; - data = { - title = "Zu lange Felix!"; - message = "Du bist schon 10 Stunden auf Arbeit, geh jetzt gefälligst nach Hause!"; - }; - } - { - service = "homeassistant.turn_on"; - entity_id = [ - "script.buzz_red_led" - "script.blitz_10s" - ]; - } - { service = "light.turn_on"; - data = { - rgb_color= [255 0 0]; - effect = "0"; - entity_id = [ "light.status_felix" ]; - }; - } - ]; - } -] diff --git a/makefu/2configs/bureautomation/automation/bureau-shutdown.nix b/makefu/2configs/bureautomation/automation/bureau-shutdown.nix index d54d9762a..3fa23a837 100644 --- a/makefu/2configs/bureautomation/automation/bureau-shutdown.nix +++ b/makefu/2configs/bureautomation/automation/bureau-shutdown.nix @@ -25,7 +25,7 @@ } { service = "tts.google_say"; - entity_id = "media_player.kodi"; + entity_id = "media_player.mpd"; data = { message = "Willkommen in deinem Lieblingsbüro"; language = "de"; @@ -35,7 +35,7 @@ service = "notify.telegrambot"; data = { title = "Bureau Startup"; - message = "Willkommen {{ trigger.platform }}"; + message = "Das Büro wurde eröffnet"; }; } ]; diff --git a/makefu/2configs/bureautomation/combination/10h_timers.nix b/makefu/2configs/bureautomation/combination/10h_timers.nix new file mode 100644 index 000000000..d398e8a34 --- /dev/null +++ b/makefu/2configs/bureautomation/combination/10h_timers.nix @@ -0,0 +1,383 @@ +{lib, ... }: +let + persons = [ "frank" "daniel" "thorsten" "carsten" "thierry" "ecki" + # "felix" # custom actions + ]; + random_zu_lange = name: ''{{ [ + "Du musst jetzt endlich nach Hause gehen ${name}!", + "10 Stunden sind rum, bald schenkst du den Franzosen deine Lebenszeit", + "Nur eine Minute über 10 Stunden kann zu einer Stunde Arbeit für Thorsten werden, ${name}.", + "In 10 Minuten kommt dich der Security Mann holen, ${name}", + "Zu lange, ${name}!" ] | random }}'' ; + + + random_announce = name: ''{{ [ + "Guten Tag ${name}!", + "${name} is in da House", + "Ahoi ${name}", + "Moinsen ${name}", + "Moin Moin ${name}", + "Palim, Palim ${name}", + "Vorwärts Genosse ${name}", + "Gemeinsame Grüße, Genosse ${name}", + "Sozialistische Grüße, Genosse ${name}", + "Konzentrierte Grüße, Genosse ${name}", + "Ach, der ${name} ist auch wieder da...", + "Nicht ${name} schon wieder", + "Tri tra tralala, der ${name} ist wieder da.", + "Na sieh mal einer an, ${name} hat es auch her geschafft", + "Wer ist im Büro eingetroffen? ${name} ist es!", + "Willkommen in deinem Lieblingsbüro, ${name}.", + "Klopf, Klopf, wer ist da? ${name} ist da!", + "Messer, Gabel, Schere, Licht sind für kleinen ${name} nicht.", + "Ich kenne ein Geheimnis, ${name} ist abgekommen", + "Wir sind ${name}. Sie werden assimiliert werden", + "Achtung, es erfolgt eine Durchsage. ${name} ist eingetroffen", + "Die Scanner haben eine dem System bekannte Lebensform mit dem Namen ${name} detektiert", + "Das Büro sieht dich, ${name}", + "Im Kalender von ${name} sind heute acht Meetings eingeplant, von denen zwei bereits verpasst wurden", + "Das Postfach von ${name} beinhaltet einhundertachtundzwanzig ungelesene E-Mails.", + "Nachricht von Serge: ${name}, bitte melden Sie sich Umgehend bei mir im Büro!", + "Luftqualität hat sich durch das Eintreffen von ${name} um zweihunder Punkte verschlechtert, bitte alle Fenster öffnen.", + "${name} arbeitet gern für seinen Konzern", + "${name} ist nur froh im Großraumbüro", + "Für ${name} ist die schönste Zeit ... die Arbeit", + "Ein Fleißbienchen für ${name} zum rechtzeitigen Erscheinen im Büro", + "${name} ist heute wohl doch nicht im Office Home", + "${name} ist bereit für einen Tag voller Meetings", + "Trotz schwerer Männergrippe ist ${name} heute im Büro erschienen.", + "${name} kenne keine Parteien mehr, ${name} kenne nur noch Arbeitsplätze", + "${name}, Frage nicht, was dein Arbeitsplatz für dich tun kann. Frage, was du für deinen Arbeitsplatz tun kannst", + "${name} läuft bis in den Jemen - für sein Unternehmen. ${name} schwimmt bis nach Birma - für meine Firma", + "Der Cyberian ${name} ist gekommen um die Bahnwelt vor Cyber-Angriffen zu schützen", + "Alles paletto im Ghetto, ${name}?", + "Hach, ${name}, wenn du hier rein kommst fühlt es sich gleich wieder an wie Montag.", + "Oh nein, nicht schon wieder ${name}", + "Wer wohnt in der Ananas ganz tief im Meer? ${name} Schwammkopf!", + "Arbeit ist Freizeit! Wachstum ist Fortschritt! Sicherheit ist Freiheit!", + "Willkommen ${name}"] | random }}'' ; + patterns = [ + [1000 500 250] # TODO: maybe even play a short audio announcement? + [150 150 150] + [255 255] + [500 500 100] + [100 1000 100] + # [125 250 500] + ]; + tmr_10h = name: { + "${name}_10h" = { + name = "${name} 10h Timer"; + duration = "10:00:00"; + }; + }; + multi_flash = { entity, delays ? [ 500 ], alias ? "${entity}_multi_flash_${toString (lib.length delays)}" }: + { + inherit alias; + sequence = lib.flatten (builtins.map (delay: [ + { service = "homeassistant.turn_on"; + data.entity_id = entity; + } + { delay.milliseconds = delay; } + { service = "homeassistant.turn_off"; + data.entity_id = entity; + } + { delay.milliseconds = delay; } + ] + ) delays); + }; + + buzz_user = name: delays: { "buzz_${name}" = (multi_flash { + entity = "light.redbutton_buzzer"; + inherit delays; + alias = "Red Button Buzz ${name}"; + }); + }; + + zu_lange_user = name: + { "announce_${name}" = { + alias = "Random Zu Lange ${name}"; + sequence = [ + { service = "media_player.play_media"; + data = { + entity_id = "media_player.mpd"; + media_content_type = "playlist"; + media_content_id = "ansage"; + }; + } + { delay.seconds = 5; } + { service = "tts.google_say"; + entity_id = "media_player.mpd"; + data_template = { + message = random_zu_lange name; + language = "de"; + }; + } + ]; + }; + }; + announce_user = name: + { "announce_${name}" = { + alias = "Random Announce ${name}"; + sequence = [ + { delay.seconds = 10; } + { service = "media_player.play_media"; + data = { + entity_id = "media_player.mpd"; + media_content_type = "playlist"; + media_content_id = "ansage"; + }; + } + { delay.seconds = 5; } + { service = "tts.google_say"; + entity_id = "media_player.mpd"; + data_template = { + message = random_announce name; + language = "de"; + }; + } + ]; + }; + }; + automation_10h = name: [ + { alias = "start ${name} 10h"; + trigger = { + platform = "state"; + # TODO: ecki + entity_id = [ "device_tracker.${name}_phone"]; + from = "not_home"; + to = "home"; + }; + condition = { + condition = "and"; + conditions = [ + { + condition = "state"; + entity_id = "timer.${name}_10h"; + state = "idle"; + } + { + condition = "time"; + after = "06:00:00"; + before = "12:00:00"; + } + ]; + }; + action = [ + { service = "timer.start"; + entity_id = [ "timer.${name}_10h" ] ; + } + { service = "homeassistant.turn_on"; + entity_id = [ + # "script.buzz_${name}" + "script.blitz_10s" + "script.announce_${name}" + ]; + } + ]; + } + + { + alias = "Zu lange ${name}!"; + trigger = + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.${name}_10h"; + }; + action = + [ + { service = "homeassistant.turn_on"; + entity_id = [ + "script.blitz_10s" + "script.zu_lange_${name}" + ]; + } + ]; + } + ]; +in +{ + timer =lib.fold lib.recursiveUpdate {} + ([ + (tmr_10h "felix") + { felix_8_30h = { + name = "Felix 8_30h Timer"; + duration = "08:30:00"; + }; + felix_7h = { + name = "Felix 7h Timer"; + duration = "07:00:00"; + }; + } + ] ++ (map tmr_10h persons)); + automation = lib.flatten (map automation_10h persons) ++ + [ + { alias = "start Felix 10h"; + trigger = { + platform = "state"; + entity_id = [ "device_tracker.felix_phone" "device_tracker.felix_laptop" ]; + from = "not_home"; + to = "home"; + }; + condition = { + condition = "and"; + conditions = [ + { + condition = "state"; + entity_id = "timer.felix_10h"; + state = "idle"; + } + { + condition = "time"; + after = "06:00:00"; + before = "12:00:00"; + } + ]; + }; + action = [ + { service = "timer.start"; + entity_id = [ "timer.felix_10h" "timer.felix_8_30h" "timer.felix_7h" ] ; + } + { service = "homeassistant.turn_on"; + entity_id = [ + # "script.buzz_felix" + "script.blitz_10s" + ]; + } + { + service = "tts.google_say"; + entity_id = "media_player.mpd"; + data_template = { + message = "Willkommen, Felix!"; + language = "de"; + }; + } + { service = "light.turn_on"; + data = { + effect = "2"; + entity_id = [ "light.status_felix" ]; + }; + } + ]; + } + + { alias = "Disable Felix timer at button press"; + trigger = { + platform = "state"; + entity_id = "binary_sensor.redbutton"; + to = "on"; + }; + condition = { + condition = "and"; + conditions = [ + { + condition = "state"; + entity_id = "timer.felix_10h"; + state = "active"; + } + { + condition = "time"; + after = "12:00:00"; + before = "22:00:00"; + } + ]; + }; + action = + [ + { + service = "timer.cancel"; + entity_id = [ "timer.felix_10h" "timer.felix_8_30h" "timer.felix_7h" ]; + } + { + service = "homeassistant.turn_on"; + entity_id = [ "script.buzz_red_led_fast" ]; + } + { + service = "homeassistant.turn_off"; + entity_id = [ "light.status_felix" ]; + } + ]; + } + + { + alias = "Genug gearbeitet Felix"; + trigger = + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.felix_7h"; + }; + action = + [ + { service = "light.turn_on"; + data = { + rgb_color= [0 255 0]; + # effect = "0"; + entity_id = [ "light.status_felix" ]; + }; + } + ]; + } + + { + alias = "nun aber nach hause"; + trigger = + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.felix_8_30h"; + }; + action = + [ + { service = "light.turn_on"; + data = { + rgb_color= [255 255 0]; + # effect = "0"; + entity_id = [ "light.status_felix" ]; + }; + } + ]; + } + + { + alias = "Zu lange Felix!"; + trigger = + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.felix_10h"; + }; + action = + [ + { + service = "notify.telegrambot"; + data = { + title = "Zu lange Felix!"; + message = "Du bist schon 10 Stunden auf Arbeit, geh jetzt gefälligst nach Hause!"; + }; + } + { + service = "homeassistant.turn_on"; + entity_id = [ + # "script.buzz_felix" + "script.blitz_10s" + ]; + } + { service = "light.turn_on"; + data = { + rgb_color= [255 0 0]; + effect = "0"; + entity_id = [ "light.status_felix" ]; + }; + } + ]; + } + ] + ; + script = lib.fold lib.recursiveUpdate {} ( + (map (ab: buzz_user ab.fst ab.snd) (lib.zipLists persons patterns)) ++ + (map (p: announce_user p) persons) ++ + (map (p: zu_lange_user p) persons) ++ + [ (announce_user "felix" ) (buzz_user "felix" [125 250 500] ) ] + ); +} diff --git a/makefu/2configs/bureautomation/combination/README.md b/makefu/2configs/bureautomation/combination/README.md new file mode 100644 index 000000000..baad87fda --- /dev/null +++ b/makefu/2configs/bureautomation/combination/README.md @@ -0,0 +1,3 @@ +# Combination Folder +files return a dictionary of different types used in home-assistant instead of +a single thing. diff --git a/makefu/2configs/bureautomation/combination/mittagessen.nix b/makefu/2configs/bureautomation/combination/mittagessen.nix new file mode 100644 index 000000000..3ec70998d --- /dev/null +++ b/makefu/2configs/bureautomation/combination/mittagessen.nix @@ -0,0 +1,89 @@ +{ lib, ... }: +let + # TODO: remove redundant code (from multi_blink) via lib + flash_entity = { entity, delay ? 500, count ? 4, alias ? "${entity}_blink_${toString count}_${toString delay}" }: + { + inherit alias; + sequence = lib.flatten (builtins.genList (i: [ + { service = "homeassistant.turn_on"; + data.entity_id = entity; + } + { delay.milliseconds = delay; } + { service = "homeassistant.turn_off"; + data.entity_id = entity; + } + { delay.milliseconds = delay; } + ] + ) count); + }; + # TODO: use influxdb and check if pommes + random_mittagessen = '' {{ [ + "Es ist 12 uhr 30. Der Aramark Gourmettempel hat, wie jeden Tag, wieder die feinsten Köstlichkeiten für euch Vorbereitet", + "Heute bei Aramark: Rezepte aus Ländern, von denen Ihr noch nie gehört habt, Deutsch zubereitet", + "Heute bei Aramark im Angebot: Scheiss mit Reis oder Reste von Freitag", + "MHHHH es ist wieder mal so weit, lecker Bayerisch Kraut mit asiatischen Nudeln", + "Es ist 12 Uhr 30 und Heute gibt es Pommes - vielleicht", + "Heute gibt es Pommes - leider nicht einzeln zu verkaufen, da die Schälchen alle sind", + "Heute gibt es Pommes - verarscht! Natürlich gibt es nur salzlosen Reis, oder salzlose Nudeln.", + "Heute auf dem Speiseplan: Sushi vom Vortag", + "Aramark Kantinenessen: Der Hunger treibt es rein, der Geiz hält es drin.", + "Das Essen in der Snackeria sieht heute wie die bessere Alternative aus", + "Heute ist wohl wieder ein Beilagen-Tag", + "Lunch time! Good luck, you will need it!", + "Heute vielleicht lieber doch nur einen Salat?", + "Im Büro ist es eh gerade viel zu warm, also ab zur Kantine", + "Im Büro ist es eh gerade viel zu kalt, also ab zur Kantine", + "Heute scheint die Auswahl wieder sehr schwierig zu sein. Vielleicht doch lieber ein Brötchen mit Fleischkäse vom Bäcker beim Baumarkt?", + "Wer hat hier schon wieder ein Meeting auf 12 Uhr gelegt? Skandal!", + "Jetzt nur noch kurz die Mail fertig schreiben und schon kann es los gehen.", + "Es ist 13 Uhr und die Mittagspause ist bald vorbei .... Kleiner Scherz, es ist erst 12:30, aber Ihr hättet auch nicht wirklich etwas verpasst.", + "Hallo, es ist nun 12 Uhr 30! Dies entspricht der Essenszeit aller Büroinsassen. Bitte begebt euch zur Aramark Essensausgabe um euren menschlichen Bedürfnissen nachzukommen."] | random }}''; +in { + automation = [ + { alias = "Mittagessen"; + trigger = { + platform = "time"; + at = "12:30:00"; + }; + action = [ + { service = "homeassistant.turn_on"; + entity_id = [ + "script.mittagessen_announce" + "script.blitz_10s" + "script.mittagessenlicht" + ]; + } + ]; + } + ]; + script = { + mittagessenlicht = (flash_entity { + entity = "switch.bauarbeiterlampe"; + alias = "Bauarbeiterlampe Mittagessenlicht"; + delay = 1000; + count = 5; + }); + mittagessen_announce = { + alias = "Random Mittagessen announce"; + sequence = [ + { + service = "media_player.play_media"; + data = { + entity_id = "media_player.mpd"; + media_content_type = "playlist"; + media_content_id = "ansage"; + }; + } + { delay.seconds = 5; } + { + service = "tts.google_say"; + entity_id = "media_player.mpd"; + data_template = { + message = random_mittagessen; + language = "de"; + }; + } + ]; + }; + }; +} diff --git a/makefu/2configs/bureautomation/hass.nix b/makefu/2configs/bureautomation/hass.nix index ed9cb0905..05b98243d 100644 --- a/makefu/2configs/bureautomation/hass.nix +++ b/makefu/2configs/bureautomation/hass.nix @@ -1,7 +1,8 @@ { config, pkgs, lib, ... }: let kodi-host = "192.168.8.11"; - + ten_hours = import ./combination/10h_timers.nix { inherit lib; }; # provides: timer automation script + mittagessen = import ./combination/mittagessen.nix { inherit lib; }; # provides: automation script in { networking.firewall.allowedTCPPorts = [ 8123 ]; state = [ "/var/lib/hass/known_devices.yaml" ]; @@ -22,7 +23,7 @@ in { })).override { extraPackages = ps: with ps; [ pkgs.pico2wave - python-forecastio jsonrpc-async jsonrpc-websocket + python-forecastio jsonrpc-async jsonrpc-websocket mpd2 (callPackage ./gtts-token.nix { }) ]; }; @@ -42,6 +43,14 @@ in { } ]; }; + # https://www.home-assistant.io/components/influxdb/ + influxdb = { + database = "hass"; + tags = { + instance = "wbob"; + source = "hass"; + }; + }; mqtt = { broker = "localhost"; port = 1883; @@ -62,23 +71,10 @@ in { }; }; switch = (import ./switch/tasmota_switch.nix) ++ - (import ./switch/rfbridge.nix); + (import ./switch/rfbridge.nix); light = (import ./light/statuslight.nix) ++ - (import ./light/buzzer.nix); - timer = { - felix_10h = { - name = "Felix 10h Timer"; - duration = "10:00:00"; - }; - felix_8_30h = { - name = "Felix 8_30h Timer"; - duration = "08:30:00"; - }; - felix_7h = { - name = "Felix 7h Timer"; - duration = "07:00:00"; - }; - }; + (import ./light/buzzer.nix); + timer = ten_hours.timer; notify = [ { platform = "kodi"; @@ -97,8 +93,15 @@ in { { platform = "kodi"; host = kodi-host; } + { platform = "mpd"; + host = "127.0.0.1"; + } + ]; + script = lib.fold lib.recursiveUpdate {} [ + ((import ./script/multi_blink.nix) {inherit lib;}) + ten_hours.script + mittagessen.script ]; - script = (import ./script/multi_blink.nix) {inherit lib;}; binary_sensor = (import ./binary_sensor/buttons.nix) ++ (import ./binary_sensor/motion.nix); @@ -134,7 +137,7 @@ in { logbook = {}; tts = [ { platform = "google"; - language = "de"; + language = "de"; } { platform = "voicerss"; api_key = builtins.readFile ; @@ -162,8 +165,8 @@ in { "group.switches" ]; }; - automation = [ - ]; + automation = []; + switches = [ "switch.bauarbeiterlampe" "switch.blitzdings" @@ -181,6 +184,7 @@ in { "device_tracker.carsten_phone" "device_tracker.thierry_phone" "device_tracker.frank_phone" + "device_tracker.anthony_phone" # "person.thorsten" # "person.felix" # "person.ecki" @@ -202,6 +206,7 @@ in { "script.blitz_10s" "script.buzz_red_led_fast" "timer.felix_10h" + "timer.frank_10h" "sensor.easy2_dht22_humidity" "sensor.easy2_dht22_temperature" # "binary_sensor.redbutton" @@ -222,9 +227,10 @@ in { # we don't use imports because the expressions do not merge in # home-assistant automation = (import ./automation/bureau-shutdown.nix) ++ - (import ./automation/nachtlicht.nix) ++ - (import ./automation/hass-restart.nix) ++ - (import ./automation/10h_timer.nix); + (import ./automation/nachtlicht.nix) ++ + (import ./automation/hass-restart.nix) ++ + ten_hours.automation ++ + mittagessen.automation; device_tracker = (import ./device_tracker/openwrt.nix ); }; }; diff --git a/makefu/2configs/bureautomation/script/multi_blink.nix b/makefu/2configs/bureautomation/script/multi_blink.nix index bb28dd46f..5076111ac 100644 --- a/makefu/2configs/bureautomation/script/multi_blink.nix +++ b/makefu/2configs/bureautomation/script/multi_blink.nix @@ -1,5 +1,7 @@ {lib, ... }: let + # TODO: flash with different delay + # let an entity blink for X times with a delay of Y milliseconds flash_entity = { entity, delay ? 500, count ? 4, alias ? "${entity}_blink_${toString count}_${toString delay}" }: { @@ -34,4 +36,10 @@ in { count = 1; alias = "blitz for 10 seconds"; }); + schlechteluft = (flash_entity { + entity = "switch.bauarbeiterlampe"; + alias = "Schlechte Luft Lampe 5 secs"; + delay = 5000; + count = 1; + }); } -- cgit v1.2.3 From 72d614cf2a266478be71eca34d75a5ab387b8b89 Mon Sep 17 00:00:00 2001 From: makefu Date: Wed, 3 Jul 2019 23:03:33 +0200 Subject: ma bureautomation: refactor air quality alarm --- .../bureautomation/automation/schlechteluft.nix | 40 +++ makefu/2configs/bureautomation/default.nix | 276 ++++++++++++++++++--- makefu/2configs/bureautomation/dwd_pollen.nix | 32 --- makefu/2configs/bureautomation/gtts-token.nix | 27 -- makefu/2configs/bureautomation/hass.nix | 237 ------------------ .../2configs/bureautomation/sensor/airquality.nix | 9 + 6 files changed, 287 insertions(+), 334 deletions(-) create mode 100644 makefu/2configs/bureautomation/automation/schlechteluft.nix delete mode 100644 makefu/2configs/bureautomation/dwd_pollen.nix delete mode 100644 makefu/2configs/bureautomation/gtts-token.nix delete mode 100644 makefu/2configs/bureautomation/hass.nix create mode 100644 makefu/2configs/bureautomation/sensor/airquality.nix (limited to 'makefu/2configs') diff --git a/makefu/2configs/bureautomation/automation/schlechteluft.nix b/makefu/2configs/bureautomation/automation/schlechteluft.nix new file mode 100644 index 000000000..9a5c4c5c8 --- /dev/null +++ b/makefu/2configs/bureautomation/automation/schlechteluft.nix @@ -0,0 +1,40 @@ +let +secs = 60; +in [ + # TODO: trigger if it is before dusk and somebody arives but nachtlichter are + # off from last day + # TODO: do not have nachtlicht turned on at night + { + alias = "Turn on Nachtlicht at dusk"; # when it gets dim + trigger = + { platform = "numeric_state"; + entity_id = "sensor.air_quality"; + above = 1523; + for.seconds = secs; + }; + condition = { + condition = "and"; + conditions = [ + { condition = "state"; + entity_id = "group.team"; + state = "home"; + } + { condition = "time"; + after = "06:00:00"; + before = "20:00:00"; + } + ]; + }; + + action = [ + { service = "homeassistant.turn_on"; + entity_id = [ + "script.schlechteluft" + ]; + } + { service = "notify.matrix_notify"; + data_template.message = "Bad Air Alarm! VOC above threshold for ${toString secs} seconds ({{state.sensor.air_quality.state_with_unit}})"; + } + ]; + } +] diff --git a/makefu/2configs/bureautomation/default.nix b/makefu/2configs/bureautomation/default.nix index 56c845744..564c0c455 100644 --- a/makefu/2configs/bureautomation/default.nix +++ b/makefu/2configs/bureautomation/default.nix @@ -1,43 +1,243 @@ -{ pkgs, lib, ... }: - -with lib; +{ config, pkgs, lib, ... }: let - port = 3001; - runit = pkgs.writeDash "runit" '' - set -xeuf - PATH=${pkgs.mosquitto}/bin:${pkgs.coreutils}/bin - name=''${1?must provide name as first arg} - state=''${2?must provide state as second arg} - # val=''${3?must provide val as third arg} - - # we ignore non-alerting events - test $state = alerting || exit 0 - - echo $name - $state - topic=plug - mosquitto_pub -t /bam/$topic/cmnd/POWER -m ON - sleep 5 - mosquitto_pub -t /bam/$topic/cmnd/POWER -m OFF - ''; + kodi-host = "192.168.8.11"; + ten_hours = import ./combination/10h_timers.nix { inherit lib; }; # provides: timer automation script + mittagessen = import ./combination/mittagessen.nix { inherit lib; }; # provides: automation script + matrix = import ./combination/matrix.nix { inherit lib; }; # provides: matrix automation in { - imports = [ - ./ota.nix - ]; - services.logstash = { - package = pkgs.logstash7; - plugins = [ pkgs.logstash-output-exec ]; + networking.firewall.allowedTCPPorts = [ 8123 ]; + state = [ "/var/lib/hass/known_devices.yaml" ]; + services.home-assistant = let + dwd_pollen = pkgs.fetchFromGitHub { + owner = "marcschumacher"; + repo = "dwd_pollen"; + rev = "0.1"; + sha256 = "1af2mx99gv2hk1ad53g21fwkdfdbymqcdl3jvzd1yg7dgxlkhbj1"; + }; + in { enable = true; - inputConfig = '' - http { - port => ${toString port} - host => "127.0.0.1" - type => "schlechteluft" - } - ''; - outputConfig = '' - if [type] == "schlechteluft" { - exec { command => "${runit} '%{ruleName}' '%{state}'" } - } - ''; + package = (pkgs.home-assistant.overrideAttrs (old: { + # TODO: find correct python package + postInstall = '' + cp -r ${dwd_pollen} $out/lib/python3.7/site-packages/homeassistant/components/dwd_pollen + ''; + })).override { + extraPackages = ps: with ps; [ + pkgs.pico2wave + 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 = "wbob"; + source = "hass"; + }; + }; + matrix = matrix.matrix; + mqtt = { + broker = "localhost"; + port = 1883; + client_id = "home-assistant"; + keepalive = 60; + protocol = 3.1; + birth_message = { + topic = "/bam/hass/tele/LWT"; + payload = "Online"; + qos = 1; + retain = true; + }; + will_message = { + topic = "/bam/hass/tele/LWT"; + payload = "Offline"; + qos = 1; + retain = true; + }; + }; + switch = (import ./switch/tasmota_switch.nix) ++ + (import ./switch/rfbridge.nix); + light = (import ./light/statuslight.nix) ++ + (import ./light/buzzer.nix); + timer = ten_hours.timer; + notify = [ + { + platform = "kodi"; + name = "wbob-kodi"; + host = kodi-host; + } + { + platform = "telegram"; + name = "telegrambot"; + chat_id = builtins.elemAt + (builtins.fromJSON (builtins.readFile + )).allowed_chat_ids 0; + } + ] ++ matrix.notify; + media_player = [ + { platform = "kodi"; + host = kodi-host; + } + { platform = "mpd"; + host = "127.0.0.1"; + } + ]; + script = lib.fold lib.recursiveUpdate {} [ + ((import ./script/multi_blink.nix) {inherit lib;}) + ten_hours.script + mittagessen.script + ]; + binary_sensor = + (import ./binary_sensor/buttons.nix) ++ + (import ./binary_sensor/motion.nix); + + sensor = + [{ platform = "version"; }] ++ + (import ./sensor/pollen.nix) ++ + (import ./sensor/espeasy.nix) ++ + (import ./sensor/airquality.nix) ++ + ((import ./sensor/outside.nix) {inherit lib;}) ++ + (import ./sensor/influxdb.nix) ++ + (import ./sensor/tasmota_firmware.nix); + + camera = + (import ./camera/verkehrskamera.nix); + + # not yet released + #person = + # (import ./person/team.nix ); + + frontend = { }; + http = { + # TODO: https://github.com/home-assistant/home-assistant/issues/16149 + base_url = "http://192.168.8.11:8123"; + api_password = "sistemas"; + trusted_networks = [ + "127.0.0.1/32" + "192.168.8.0/24" + "::1/128" + "fd00::/8" + ]; + }; + conversation = {}; + history = {}; + logbook = {}; + tts = [ + { platform = "google"; + language = "de"; + } + { platform = "voicerss"; + api_key = builtins.readFile ; + language = "de-de"; + } + { platform = "picotts"; + language = "de-DE"; + } + ]; + recorder = {}; + sun = {}; + telegram_bot = [ + (builtins.fromJSON + (builtins.readFile )) + ]; + group = + { default_view = + { view = "yes"; + entities = [ + "group.sensors" + "group.camera" + "group.outside" + "group.team" + "group.nachtlicht" + "group.switches" + ]; + }; + automation = []; + + switches = [ + "switch.bauarbeiterlampe" + "switch.blitzdings" + "switch.fernseher" + "switch.feuer" + "light.status_felix" + "light.status_daniel" + "light.buslicht" + ]; + team = [ + "device_tracker.thorsten_phone" + "device_tracker.felix_phone" + "device_tracker.ecki_tablet" + "device_tracker.daniel_phone" + "device_tracker.carsten_phone" + "device_tracker.thierry_phone" + "device_tracker.frank_phone" + "device_tracker.anthony_phone" + # "person.thorsten" + # "person.felix" + # "person.ecki" + # "person.daniel" + ]; + camera = [ + "camera.Baumarkt" + "camera.Autobahn_Heilbronn" + "camera.Autobahn_Singen" + ]; + nachtlicht = [ + "switch.nachtlicht_a" + "switch.nachtlicht_b" + "switch.nachtlicht_c" + "switch.nachtlicht_d" + ]; + sensors = [ + "media_player.kodi" + "script.blitz_10s" + "script.buzz_red_led_fast" + "timer.felix_10h" + "timer.frank_10h" + "sensor.easy2_dht22_humidity" + "sensor.easy2_dht22_temperature" + # "binary_sensor.redbutton" + ]; + outside = [ + # "sensor.ditzingen_pm10" + # "sensor.ditzingen_pm25" + "sensor.dark_sky_icon" + "sensor.dark_sky_temperature" + "sensor.dark_sky_humidity" + "sensor.dark_sky_uv_index" + # "sensor.dark_sky_pressure" + "sensor.dark_sky_hourly_summary" + ]; + }; + # only for automation + # feedreader.urls = [ "http://www.heise.de/security/rss/news-atom.xml" ]; + # we don't use imports because the expressions do not merge in + # home-assistant + automation = (import ./automation/bureau-shutdown.nix) ++ + (import ./automation/nachtlicht.nix) ++ + (import ./automation/hass-restart.nix) ++ + ten_hours.automation ++ + matrix.automation ++ + mittagessen.automation; + device_tracker = (import ./device_tracker/openwrt.nix ); + }; }; } diff --git a/makefu/2configs/bureautomation/dwd_pollen.nix b/makefu/2configs/bureautomation/dwd_pollen.nix deleted file mode 100644 index 39d9c3069..000000000 --- a/makefu/2configs/bureautomation/dwd_pollen.nix +++ /dev/null @@ -1,32 +0,0 @@ -{ 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/makefu/2configs/bureautomation/gtts-token.nix b/makefu/2configs/bureautomation/gtts-token.nix deleted file mode 100644 index 69640f03d..000000000 --- a/makefu/2configs/bureautomation/gtts-token.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ 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/makefu/2configs/bureautomation/hass.nix b/makefu/2configs/bureautomation/hass.nix deleted file mode 100644 index 05b98243d..000000000 --- a/makefu/2configs/bureautomation/hass.nix +++ /dev/null @@ -1,237 +0,0 @@ -{ config, pkgs, lib, ... }: -let - kodi-host = "192.168.8.11"; - ten_hours = import ./combination/10h_timers.nix { inherit lib; }; # provides: timer automation script - mittagessen = import ./combination/mittagessen.nix { inherit lib; }; # provides: automation script -in { - networking.firewall.allowedTCPPorts = [ 8123 ]; - state = [ "/var/lib/hass/known_devices.yaml" ]; - 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 - postInstall = '' - cp -r ${dwd_pollen} $out/lib/python3.7/site-packages/homeassistant/components/dwd_pollen - ''; - })).override { - extraPackages = ps: with ps; [ - pkgs.pico2wave - python-forecastio jsonrpc-async jsonrpc-websocket mpd2 - (callPackage ./gtts-token.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 = "wbob"; - source = "hass"; - }; - }; - mqtt = { - broker = "localhost"; - port = 1883; - client_id = "home-assistant"; - keepalive = 60; - protocol = 3.1; - birth_message = { - topic = "/bam/hass/tele/LWT"; - payload = "Online"; - qos = 1; - retain = true; - }; - will_message = { - topic = "/bam/hass/tele/LWT"; - payload = "Offline"; - qos = 1; - retain = true; - }; - }; - switch = (import ./switch/tasmota_switch.nix) ++ - (import ./switch/rfbridge.nix); - light = (import ./light/statuslight.nix) ++ - (import ./light/buzzer.nix); - timer = ten_hours.timer; - notify = [ - { - platform = "kodi"; - name = "wbob-kodi"; - host = kodi-host; - } - { - platform = "telegram"; - name = "telegrambot"; - chat_id = builtins.elemAt - (builtins.fromJSON (builtins.readFile - )).allowed_chat_ids 0; - } - ]; - media_player = [ - { platform = "kodi"; - host = kodi-host; - } - { platform = "mpd"; - host = "127.0.0.1"; - } - ]; - script = lib.fold lib.recursiveUpdate {} [ - ((import ./script/multi_blink.nix) {inherit lib;}) - ten_hours.script - mittagessen.script - ]; - binary_sensor = - (import ./binary_sensor/buttons.nix) ++ - (import ./binary_sensor/motion.nix); - - sensor = - (import ./sensor/pollen.nix) ++ - (import ./sensor/espeasy.nix) ++ - ((import ./sensor/outside.nix) {inherit lib;}) ++ - (import ./sensor/influxdb.nix) ++ - (import ./sensor/tasmota_firmware.nix); - - camera = - (import ./camera/verkehrskamera.nix); - - # not yet released - #person = - # (import ./person/team.nix ); - - frontend = { }; - http = { - # TODO: https://github.com/home-assistant/home-assistant/issues/16149 - base_url = "http://192.168.8.11:8123"; - api_password = "sistemas"; - trusted_networks = [ - "127.0.0.1/32" - "192.168.8.0/24" - "::1/128" - "fd00::/8" - ]; - }; - conversation = {}; - history = {}; - logbook = {}; - tts = [ - { platform = "google"; - language = "de"; - } - { platform = "voicerss"; - api_key = builtins.readFile ; - language = "de-de"; - } - { platform = "picotts"; - language = "de-DE"; - } - ]; - recorder = {}; - sun = {}; - telegram_bot = [ - (builtins.fromJSON - (builtins.readFile )) - ]; - group = - { default_view = - { view = "yes"; - entities = [ - "group.sensors" - "group.camera" - "group.outside" - "group.team" - "group.nachtlicht" - "group.switches" - ]; - }; - automation = []; - - switches = [ - "switch.bauarbeiterlampe" - "switch.blitzdings" - "switch.fernseher" - "switch.feuer" - "light.status_felix" - "light.status_daniel" - "light.buslicht" - ]; - team = [ - "device_tracker.thorsten_phone" - "device_tracker.felix_phone" - "device_tracker.ecki_tablet" - "device_tracker.daniel_phone" - "device_tracker.carsten_phone" - "device_tracker.thierry_phone" - "device_tracker.frank_phone" - "device_tracker.anthony_phone" - # "person.thorsten" - # "person.felix" - # "person.ecki" - # "person.daniel" - ]; - camera = [ - "camera.Baumarkt" - "camera.Autobahn_Heilbronn" - "camera.Autobahn_Singen" - ]; - nachtlicht = [ - "switch.nachtlicht_a" - "switch.nachtlicht_b" - "switch.nachtlicht_c" - "switch.nachtlicht_d" - ]; - sensors = [ - "media_player.kodi" - "script.blitz_10s" - "script.buzz_red_led_fast" - "timer.felix_10h" - "timer.frank_10h" - "sensor.easy2_dht22_humidity" - "sensor.easy2_dht22_temperature" - # "binary_sensor.redbutton" - ]; - outside = [ - # "sensor.ditzingen_pm10" - # "sensor.ditzingen_pm25" - "sensor.dark_sky_icon" - "sensor.dark_sky_temperature" - "sensor.dark_sky_humidity" - "sensor.dark_sky_uv_index" - # "sensor.dark_sky_pressure" - "sensor.dark_sky_hourly_summary" - ]; - }; - # only for automation - # feedreader.urls = [ "http://www.heise.de/security/rss/news-atom.xml" ]; - # we don't use imports because the expressions do not merge in - # home-assistant - automation = (import ./automation/bureau-shutdown.nix) ++ - (import ./automation/nachtlicht.nix) ++ - (import ./automation/hass-restart.nix) ++ - ten_hours.automation ++ - mittagessen.automation; - device_tracker = (import ./device_tracker/openwrt.nix ); - }; - }; -} diff --git a/makefu/2configs/bureautomation/sensor/airquality.nix b/makefu/2configs/bureautomation/sensor/airquality.nix new file mode 100644 index 000000000..217fa9595 --- /dev/null +++ b/makefu/2configs/bureautomation/sensor/airquality.nix @@ -0,0 +1,9 @@ +[ + # coming from 2configs/stats/telegraf/ + { platform = "mqtt"; + name = "Air Quality"; + state_topic = "/telegraf/wbob/airquality"; + value_template = "{{ value_json.fields.value }}"; + unit_of_measurement = "VOC"; + } +] -- cgit v1.2.3 From c2230d30c5d75622eb25f3e0df977691cbf01058 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 4 Jul 2019 08:03:50 +0200 Subject: ma bureautomation: remove announcement, fix schlechteluft --- makefu/2configs/bureautomation/automation/bureau-shutdown.nix | 8 -------- makefu/2configs/bureautomation/automation/schlechteluft.nix | 7 ++----- 2 files changed, 2 insertions(+), 13 deletions(-) (limited to 'makefu/2configs') diff --git a/makefu/2configs/bureautomation/automation/bureau-shutdown.nix b/makefu/2configs/bureautomation/automation/bureau-shutdown.nix index 3fa23a837..007f6064a 100644 --- a/makefu/2configs/bureautomation/automation/bureau-shutdown.nix +++ b/makefu/2configs/bureautomation/automation/bureau-shutdown.nix @@ -23,14 +23,6 @@ item.partymode = "music"; }; } - { - service = "tts.google_say"; - entity_id = "media_player.mpd"; - data = { - message = "Willkommen in deinem Lieblingsbüro"; - language = "de"; - }; - } { service = "notify.telegrambot"; data = { diff --git a/makefu/2configs/bureautomation/automation/schlechteluft.nix b/makefu/2configs/bureautomation/automation/schlechteluft.nix index 9a5c4c5c8..4a5fb17c2 100644 --- a/makefu/2configs/bureautomation/automation/schlechteluft.nix +++ b/makefu/2configs/bureautomation/automation/schlechteluft.nix @@ -1,11 +1,8 @@ let secs = 60; in [ - # TODO: trigger if it is before dusk and somebody arives but nachtlichter are - # off from last day - # TODO: do not have nachtlicht turned on at night { - alias = "Turn on Nachtlicht at dusk"; # when it gets dim + alias = "Bad Air Alarm"; trigger = { platform = "numeric_state"; entity_id = "sensor.air_quality"; @@ -33,7 +30,7 @@ in [ ]; } { service = "notify.matrix_notify"; - data_template.message = "Bad Air Alarm! VOC above threshold for ${toString secs} seconds ({{state.sensor.air_quality.state_with_unit}})"; + data_template.message = "Bad Air Alarm! VOC above threshold for ${toString secs} seconds ({{states.sensor.air_quality.state_with_unit}})"; } ]; } -- cgit v1.2.3 From b3b2dd65211fa7bcdb2f5e507895ce5edde45160 Mon Sep 17 00:00:00 2001 From: makefu Date: Thu, 4 Jul 2019 08:05:54 +0200 Subject: ma bureautomation: stream-line 10h timers --- .../bureautomation/combination/10h_timers.nix | 202 ++------------------- 1 file changed, 18 insertions(+), 184 deletions(-) (limited to 'makefu/2configs') diff --git a/makefu/2configs/bureautomation/combination/10h_timers.nix b/makefu/2configs/bureautomation/combination/10h_timers.nix index d398e8a34..4bbae0dda 100644 --- a/makefu/2configs/bureautomation/combination/10h_timers.nix +++ b/makefu/2configs/bureautomation/combination/10h_timers.nix @@ -1,14 +1,15 @@ {lib, ... }: let - persons = [ "frank" "daniel" "thorsten" "carsten" "thierry" "ecki" - # "felix" # custom actions + persons = [ "frank" "daniel" "thorsten" "carsten" "thierry" "ecki" "felix" + "anthony" # antony + "thierry" # tjeri ]; random_zu_lange = name: ''{{ [ "Du musst jetzt endlich nach Hause gehen ${name}!", "10 Stunden sind rum, bald schenkst du den Franzosen deine Lebenszeit", "Nur eine Minute über 10 Stunden kann zu einer Stunde Arbeit für Thorsten werden, ${name}.", "In 10 Minuten kommt dich der Security Mann holen, ${name}", - "Zu lange, ${name}!" ] | random }}'' ; + "Zu lange, ${name}!" ] | random }}'' ; random_announce = name: ''{{ [ @@ -94,8 +95,9 @@ let }; zu_lange_user = name: - { "announce_${name}" = { + { "zu_lange_${name}" = { alias = "Random Zu Lange ${name}"; + sequence = [ { service = "media_player.play_media"; data = { @@ -176,14 +178,21 @@ let ]; } - { - alias = "Zu lange ${name}!"; + { alias = "Zu lange ${name}!"; trigger = { platform = "event"; event_type = "timer.finished"; event_data.entity_id = "timer.${name}_10h"; }; + + condition = + { + condition = "state"; + entity_id = "device_tracker.${name}_phone"; + state = "home"; + }; + action = [ { service = "homeassistant.turn_on"; @@ -198,186 +207,11 @@ let in { timer =lib.fold lib.recursiveUpdate {} - ([ - (tmr_10h "felix") - { felix_8_30h = { - name = "Felix 8_30h Timer"; - duration = "08:30:00"; - }; - felix_7h = { - name = "Felix 7h Timer"; - duration = "07:00:00"; - }; - } - ] ++ (map tmr_10h persons)); - automation = lib.flatten (map automation_10h persons) ++ - [ - { alias = "start Felix 10h"; - trigger = { - platform = "state"; - entity_id = [ "device_tracker.felix_phone" "device_tracker.felix_laptop" ]; - from = "not_home"; - to = "home"; - }; - condition = { - condition = "and"; - conditions = [ - { - condition = "state"; - entity_id = "timer.felix_10h"; - state = "idle"; - } - { -