From ce2aadff1c8d1d44a51c3be27570c64e14fd13c1 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 9 Mar 2021 22:14:51 +0100 Subject: ma ham -> ma home/ham --- .../home/ham/automation/firetv_restart.nix | 37 ++++ makefu/2configs/home/ham/automation/giesskanne.nix | 102 +++++++++++ .../2configs/home/ham/automation/light_buttons.nix | 44 +++++ makefu/2configs/home/ham/automation/moodlight.nix | 46 +++++ makefu/2configs/home/ham/automation/urlaub.nix | 44 +++++ .../ham/automation/wohnzimmer_rf_fernbedienung.nix | 135 ++++++++++++++ makefu/2configs/home/ham/calendar/nextcloud.nix | 13 ++ makefu/2configs/home/ham/default.nix | 198 +++++++++++++++++++++ makefu/2configs/home/ham/deps/dwdwfsapi.nix | 38 ++++ makefu/2configs/home/ham/deps/pykodi.nix | 37 ++++ .../2configs/home/ham/device_tracker/openwrt.nix | 13 ++ makefu/2configs/home/ham/lib/default.nix | 44 +++++ makefu/2configs/home/ham/light/arbeitszimmer.nix | 24 +++ makefu/2configs/home/ham/light/schlafzimmer.nix | 14 ++ makefu/2configs/home/ham/light/wohnzimmer.nix | 24 +++ makefu/2configs/home/ham/mqtt.nix | 24 +++ makefu/2configs/home/ham/multi/fliegen-couter.nix | 71 ++++++++ makefu/2configs/home/ham/multi/flurlicht.nix | 57 ++++++ makefu/2configs/home/ham/multi/kurzzeitwecker.nix | 135 ++++++++++++++ makefu/2configs/home/ham/multi/the_playlist.nix | 86 +++++++++ makefu/2configs/home/ham/nginx.nix | 10 ++ makefu/2configs/home/ham/sensor/outside.nix | 25 +++ makefu/2configs/home/ham/zigbee2mqtt/default.nix | 28 +++ makefu/2configs/home/ham/zigbee2mqtt/hass.nix | 130 ++++++++++++++ makefu/2configs/home/ham/zigbee2mqtt/osram.nix | 14 ++ 25 files changed, 1393 insertions(+) create mode 100644 makefu/2configs/home/ham/automation/firetv_restart.nix create mode 100644 makefu/2configs/home/ham/automation/giesskanne.nix create mode 100644 makefu/2configs/home/ham/automation/light_buttons.nix create mode 100644 makefu/2configs/home/ham/automation/moodlight.nix create mode 100644 makefu/2configs/home/ham/automation/urlaub.nix create mode 100644 makefu/2configs/home/ham/automation/wohnzimmer_rf_fernbedienung.nix create mode 100644 makefu/2configs/home/ham/calendar/nextcloud.nix create mode 100644 makefu/2configs/home/ham/default.nix create mode 100644 makefu/2configs/home/ham/deps/dwdwfsapi.nix create mode 100644 makefu/2configs/home/ham/deps/pykodi.nix create mode 100644 makefu/2configs/home/ham/device_tracker/openwrt.nix create mode 100644 makefu/2configs/home/ham/lib/default.nix create mode 100644 makefu/2configs/home/ham/light/arbeitszimmer.nix create mode 100644 makefu/2configs/home/ham/light/schlafzimmer.nix create mode 100644 makefu/2configs/home/ham/light/wohnzimmer.nix create mode 100644 makefu/2configs/home/ham/mqtt.nix create mode 100644 makefu/2configs/home/ham/multi/fliegen-couter.nix create mode 100644 makefu/2configs/home/ham/multi/flurlicht.nix create mode 100644 makefu/2configs/home/ham/multi/kurzzeitwecker.nix create mode 100644 makefu/2configs/home/ham/multi/the_playlist.nix create mode 100644 makefu/2configs/home/ham/nginx.nix create mode 100644 makefu/2configs/home/ham/sensor/outside.nix create mode 100644 makefu/2configs/home/ham/zigbee2mqtt/default.nix create mode 100644 makefu/2configs/home/ham/zigbee2mqtt/hass.nix create mode 100644 makefu/2configs/home/ham/zigbee2mqtt/osram.nix (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/automation/firetv_restart.nix b/makefu/2configs/home/ham/automation/firetv_restart.nix new file mode 100644 index 000000000..12e0e845a --- /dev/null +++ b/makefu/2configs/home/ham/automation/firetv_restart.nix @@ -0,0 +1,37 @@ +let + cmd = command: { + service = "androidtv.adb_command"; + data = { + entity_id = "media_player.firetv_stick"; + inherit command; + }; + }; + sec = seconds: { delay.seconds = seconds; }; +in +{ + services.home-assistant.config.automation = + [ + { + alias = "Nightly reboot of firetv"; + trigger = { + platform = "time"; + at = "03:00:00"; + }; + action = [ + (cmd "reboot") + (sec 90) # go to my music because apparently select_source does not seem to always work + (cmd "HOME") + (sec 2) + (cmd "DOWN") + (sec 2) + (cmd "DOWN") + (sec 2) + (cmd "ENTER") + (sec 4) + (cmd "RIGHT") + (sec 2) + (cmd "RIGHT") + ]; + } + ]; +} diff --git a/makefu/2configs/home/ham/automation/giesskanne.nix b/makefu/2configs/home/ham/automation/giesskanne.nix new file mode 100644 index 000000000..4b0fb61dd --- /dev/null +++ b/makefu/2configs/home/ham/automation/giesskanne.nix @@ -0,0 +1,102 @@ +# uses: +# switch.crafting_giesskanne_relay +let + cam = { + name = "chilicam"; + camera = "camera.espcam_02"; + light = "light.espcam_02_light"; + seconds = 60; # default shutoff to protect the LED from burning out + }; + seconds = 60; + pump = "switch.arbeitszimmer_giesskanne_relay"; + # sensor = "sensor.statistics_for_sensor_crafting_brotbox_soil_moisture"; +in +{ + services.home-assistant.config = + { + #sensor = map ( entity_id: { + # platform = "statistics"; + # name = "Statistics for ${entity_id}"; + # inherit entity_id; + # max_age.minutes = "60"; + # sampling_size = 1000; + # }) [ "sensor.crafting_brotbox_soil_moisture" ]; + + automation = + [ + + ##### brotbox + { alias = "Water the plant for ${toString seconds} seconds"; + trigger = [ + { # trigger at 23:15 no matter what + # TODO: retry or run only if switch.wasser is available + platform = "time"; + at = "23:15:00"; + } + ]; + action = + [ + { # take a snapshot before watering + service = "homeassistant.turn_on"; + entity_id = [ cam.light ]; + } + { # TODO: we could also create a recording with camera.record + service = "camera.snapshot"; + data = { + entity_id = cam.camera; + # TODO: create /var/lib/hass/cam/ - now being done manually + filename = "/var/lib/hass/cam/${cam.name}_{{ now().strftime('%Y%m%d-%H%M%S') }}.jpg"; + }; + } + + { # now turn on the pumping services + # i do not start hte pump and light before the snapshot because i do + # not know how long it takes (do not want to water the plants for too long) + service = "homeassistant.turn_on"; + entity_id = [ pump ]; + } + { delay.seconds = seconds; } + { + service = "homeassistant.turn_off"; + entity_id = [ pump cam.light ]; + } + ]; + } + { alias = "Always turn off the light after ${toString (cam.seconds)}s"; + trigger = [ + { + platform = "state"; + entity_id = cam.light; + to = "on"; + for.seconds = cam.seconds; + } + ]; + action = + [ + { + service = "homeassistant.turn_off"; + entity_id = [ pump cam.light ]; + } + ]; + } + + { alias = "Always turn off water after ${toString (seconds * 2)}s"; + trigger = [ + { + platform = "state"; + entity_id = pump; + to = "on"; + for.seconds = seconds*2; + } + ]; + action = + [ + { + service = "homeassistant.turn_off"; + entity_id = [ pump cam.light ]; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/automation/light_buttons.nix b/makefu/2configs/home/ham/automation/light_buttons.nix new file mode 100644 index 000000000..32d134ecc --- /dev/null +++ b/makefu/2configs/home/ham/automation/light_buttons.nix @@ -0,0 +1,44 @@ +# light.wohnzimmerbeleuchtung +# light.wohnzimmer_deko +# light.arbeitszimmerbeleuchtung +# light.arbeitszimmer_deko +# light.schlafzimmerbeleuchtung + +let + toggle = light: btn: + { + alias = "Toggle Light ${light} via ${btn}"; + trigger = { + platform = "state"; + entity_id = "sensor.${btn}_click"; + to = "single"; + }; + action = { + service = "light.toggle"; + data.entity_id = light; + data.transition = 0; + }; + }; + turn_off_all = btn: + { + alias = "Turn of all lights via ${btn} double click"; + trigger = { + platform = "state"; + entity_id = "sensor.${btn}_click"; + to = "double"; + }; + action = { + service = "light.turn_off"; + entity_id = "all"; + }; + }; +in { + services.home-assistant.config.automation = [ + (toggle "light.arbeitszimmerbeleuchtung" "arbeitszimmer_btn1") + (toggle "light.schlafzimmerbeleuchtung" "schlafzimmer_btn2") + (toggle "light.wohnzimmerbeleuchtung" "wohnzimmer_btn3") + (turn_off_all "arbeitszimmer_btn1") + (turn_off_all "schlafzimmer_btn2") + (turn_off_all "wohnzimmer_btn3") + ]; +} diff --git a/makefu/2configs/home/ham/automation/moodlight.nix b/makefu/2configs/home/ham/automation/moodlight.nix new file mode 100644 index 000000000..d0e336851 --- /dev/null +++ b/makefu/2configs/home/ham/automation/moodlight.nix @@ -0,0 +1,46 @@ +# uses: + +let + wohnzimmer = "light.wohnzimmer_fenster_lichterkette_licht"; + arbeitszimmer = "light.box_led_status"; + final_off = "01:00"; + + turn_on = entity_id: at: extra: + { alias = "Turn on ${entity_id} at ${at}"; + trigger = [ + { platform = "time"; inherit at; } + ]; + action = + [ + ({ service = "light.turn_on"; + data = { + inherit entity_id; + + } // extra; + }) + ]; + }; +in +{ + services.home-assistant.config = + { + automation = + [ + # (turn_on wohnzimmer "17:30") + (turn_on arbeitszimmer "9:00" { effect = "Slow Random Twinkle";}) + + { alias = "Always turn off the lights at ${final_off}"; + trigger = [ + { platform = "time"; at = final_off; } + ]; + action = + [ + { + service = "light.turn_off"; + entity_id = [ wohnzimmer arbeitszimmer]; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/automation/urlaub.nix b/makefu/2configs/home/ham/automation/urlaub.nix new file mode 100644 index 000000000..a6b9be96f --- /dev/null +++ b/makefu/2configs/home/ham/automation/urlaub.nix @@ -0,0 +1,44 @@ +# uses: +# light.wohnzimmer_schrank_osram +# light.wohnzimmer_fernseher_led_strip +# "all" lights + +let + schranklicht = "light.wohnzimmer_schrank_osram"; + fernsehlicht = "light.wohnzimmer_fernseher_led_strip"; + final_off = "01:00"; + + turn_on = entity_id: at: + { alias = "Turn on ${entity_id} at ${at}"; + trigger = [ + { platform = "time"; inherit at; } + ]; + action = + [ + { service = "light.turn_on"; inherit entity_id; } + ]; + }; +in +{ + services.home-assistant.config = + { + automation = + [ + (turn_on schranklicht "17:30") + (turn_on fernsehlicht "19:00") + + { alias = "Always turn off the urlaub lights at ${final_off}"; + trigger = [ + { platform = "time"; at = final_off; } + ]; + action = + [ + { + service = "light.turn_off"; + entity_id = [ schranklicht fernsehlicht ]; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/automation/wohnzimmer_rf_fernbedienung.nix b/makefu/2configs/home/ham/automation/wohnzimmer_rf_fernbedienung.nix new file mode 100644 index 000000000..4303cdfa5 --- /dev/null +++ b/makefu/2configs/home/ham/automation/wohnzimmer_rf_fernbedienung.nix @@ -0,0 +1,135 @@ +# This module maps the RF433 Remote Control to zigbee and wifi lights +let + rf_turn_off = code: light: + { + alias = "Turn off ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.turn_off"; + data.entity_id = light; + }; + }; + rf_turn_on = code: light: + { + alias = "Turn on ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.turn_on"; + data.entity_id = light; + }; + }; + rf_state = code: light: halfbright: + let + maxbright = 255; + transition = 0.2; # seconds + in + # this function implements a simple state machine based on the state and brightness of the light (light must support brightness + { + alias = "Cycle through states of ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + choose = [ + { + # state 0: off to half + conditions = { + condition = "template"; + value_template = ''{{ states("${light}") == "off" }}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = halfbright; + }; + } + ]; + } + { + # state 1: half to full + conditions = { + condition = "template"; + value_template = ''{{ states('${light}') == 'on' and ( ${toString (halfbright - 1)} <= state_attr("${light}","brightness") <= ${toString (halfbright + 1)})}}''; + }; + sequence = [ + { + service = "light.turn_on"; + data = { + entity_id = light; + brightness = maxbright; + }; + } + ]; + } + { + # state 2: full to off + conditions = { + condition = "template"; + # TODO: it seems like the devices respond with brightness-1 , maybe off-by-one somewhere? + value_template = ''{{ states("${light}") == "on" and state_attr("${light}","brightness") >= ${toString (maxbright - 1)}}}''; + }; + sequence = [ + { + service = "light.turn_off"; + data = { + entity_id = light; + }; + } + ]; + } + ]; + # default: on to off + # this works because state 0 checks for "state == off" + default = [{ + service = "light.turn_off"; + data = { + entity_id = light; + }; + }]; + }; + } +; + rf_toggle = code: light: + { + alias = "Toggle ${light} via rf code ${code}"; + trigger = { + platform = "event"; + event_type = "esphome.rf_code_received"; + event_data.code = code; + }; + action = { + service = "light.toggle"; + data.entity_id = light; + }; + }; +in +{ + services.home-assistant.config.automation = [ + (rf_toggle "400551" "light.wohnzimmer_fernseher_led_strip") # A + (rf_state "401151" "light.wohnzimmer_stehlampe_osram" 128) # B + (rf_state "401451" "light.wohnzimmer_komode_osram" 128) # C + (rf_state "401511" "light.wohnzimmer_schrank_osram" 128) # D + + # OFF Lane + (rf_turn_off "400554" "all") # A + (rf_toggle "401154" "light.wohnzimmer_fenster_lichterkette_licht") # B + (rf_toggle "401454" "light.wohnzimmer_fernsehwand_led") # C + # (rf_toggle "401514" "") # D + ]; + # "400554" # A OFF + # "401154" # B OFF + # "401454" # C OFF + # "401514" # D OFF +} diff --git a/makefu/2configs/home/ham/calendar/nextcloud.nix b/makefu/2configs/home/ham/calendar/nextcloud.nix new file mode 100644 index 000000000..80e51b348 --- /dev/null +++ b/makefu/2configs/home/ham/calendar/nextcloud.nix @@ -0,0 +1,13 @@ +let + cred = import ; +in +{ + services.home-assistant.config.calendar = + [ + { + platform = "caldav"; + inherit (cred) username password; + url = "https://o.euer.krebsco.de/remote.php/dav"; + } + ]; +} diff --git a/makefu/2configs/home/ham/default.nix b/makefu/2configs/home/ham/default.nix new file mode 100644 index 000000000..8ed5f8f3c --- /dev/null +++ b/makefu/2configs/home/ham/default.nix @@ -0,0 +1,198 @@ +{ pkgs, lib, config, ... }: + +# Ideas: +## wake-on-lan server +## +let + prefix = (import ./lib).prefix; + firetv_stick = "192.168.1.24"; + hassdir = "/var/lib/hass"; + unstable = import (pkgs.fetchFromGitHub { + owner = "nixos"; + repo = "nixpkgs"; + rev = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).rev; + sha256 = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).sha256; + }) {}; + + +in { + imports = [ + ./nginx.nix + ./mqtt.nix + ./zigbee2mqtt + ./signal-rest + + # hass config + ./zigbee2mqtt/hass.nix + # ./multi/flurlicht.nix + ./multi/kurzzeitwecker.nix + ./multi/the_playlist.nix + # ./multi/fliegen-couter.nix + + ./device_tracker/openwrt.nix + + ./sensor/outside.nix + + ./calendar/nextcloud.nix + + ./automation/fenster_auf.nix + ./automation/firetv_restart.nix + ./automation/light_buttons.nix + ./automation/wohnzimmer_rf_fernbedienung.nix + ./automation/giesskanne.nix + #./automation/urlaub.nix + ./automation/moodlight.nix + + ./light/arbeitszimmer.nix + ./light/schlafzimmer.nix + ./light/wohnzimmer.nix + ]; + + services.home-assistant = { + package = (unstable.home-assistant.overrideAttrs (old: { + doInstallCheck = false; + })).override { + extraPackages = p: [ + (p.callPackage ./deps/dwdwfsapi.nix {}) + (p.callPackage ./deps/pykodi.nix {}) + p.APScheduler ]; + }; + + config = { + influxdb = { + database = "ham"; + host = "localhost"; + tags = { + instance = "omo"; + source = "hass"; + }; + }; + + config = {}; + homeassistant = { + name = "Home"; time_zone = "Europe/Berlin"; + latitude = "48.7687"; + longitude = "9.2478"; + elevation = 247; + auth_providers = [ + { type = "trusted_networks"; + trusted_networks = [ "192.168.1.0/24" ]; + allow_bypass_login = true; + } + { type = "homeassistant"; } + ]; + }; + discovery = {}; + conversation = {}; + history = {}; + logbook = {}; + logger = { + default = "info"; + }; + rest_command = {}; + tts = [ + { platform = "google_translate"; + language = "de"; + time_memory = 57600; + service_name = "google_say"; + } + ]; + api = {}; + esphome = {}; + camera = []; + #telegram_bot = [ + # # secrets file: { + # # "platform": "broadcast", + # # "api_key": "", # talk to Botfather /newbot + # # "allowed_chat_ids": [ ID ] # curl -X GET # https://api.telegram.org/bot/getUpdates + # # } + # (builtins.fromJSON + # (builtins.readFile )) + #]; + notify = [ + { + platform = "kodi"; + name = "Kodi Wohnzimmer"; + host = firetv_stick; + } + { + platform = "nfandroidtv"; + name = "FireTV Wohnzimmer"; + host = firetv_stick; + } + #{ + # platform = "telegram"; + # name = "telegrambot"; + # chat_id = builtins.elemAt + # (builtins.fromJSON (builtins.readFile + # )).allowed_chat_ids 0; + #} + ]; + sun.elevation = 247; + recorder = {}; + media_player = [ + { platform = "kodi"; + name = "FireTV Stick kodi"; + host = firetv_stick; + } + { platform = "androidtv"; + name = "FireTV Stick"; + device_class = "firetv"; + # adb_server_ip = firetv_stick; + host = firetv_stick; + port = 5555; + } + ]; + mqtt = { + broker = "localhost"; + discovery = true; #enable esphome discovery + discovery_prefix = "homeassistant"; + port = 1883; + client_id = "home-assistant"; + username = "hass"; + password = lib.removeSuffix "\n" (builtins.readFile ); + keepalive = 60; + protocol = 3.1; + birth_message = { + topic = "${prefix}/hass/tele/LWT"; + payload = "Online"; + qos = 1; + retain = true; + }; + will_message = { + topic = "${prefix}/hass/tele/LWT"; + payload = "Offline"; + qos = 1; + retain = true; + }; + }; + luftdaten = { + show_on_map = true; + sensor_id = 10529; + sensors.monitored_conditions = [ "P1" "P2" ]; + }; + #binary_sensor = + # flurlicht.binary_sensor; + sensor = [ + { platform = "speedtest"; + monitored_conditions = [ "ping" "download" "upload" ]; + } + # https://www.home-assistant.io/cookbook/automation_for_rainy_days/ + ]; + frontend = { }; + http = { + use_x_forwarded_for = true; + server_host = "127.0.0.1"; + trusted_proxies = [ "127.0.0.1" ]; + #trusted_proxies = [ "192.168.1.0/24" ]; + }; + switch = []; + automation = []; + script = { }; + }; + enable = true; + configDir = hassdir; + }; + + state = [ "/var/lib/hass/known_devices.yaml" ]; +} diff --git a/makefu/2configs/home/ham/deps/dwdwfsapi.nix b/makefu/2configs/home/ham/deps/dwdwfsapi.nix new file mode 100644 index 000000000..d59dfa9e8 --- /dev/null +++ b/makefu/2configs/home/ham/deps/dwdwfsapi.nix @@ -0,0 +1,38 @@ +{ lib +, buildPythonPackage +, fetchPypi +, requests +, ciso8601 +, urllib3 +}: + +buildPythonPackage rec { + pname = "dwdwfsapi"; + version = "1.0.3"; + + disabled = false; # requires python version >=3.6 + + src = fetchPypi { + inherit pname version; + sha256 = "3d7d5bd66b1a647f07295068dc653b4ceafc2e8ec834b8e32419031c7b3a9b39"; + }; + + # # Package conditions to handle + # # might have to sed setup.py and egg.info in patchPhase + # # sed -i "s/...//" + # requests>=2.23.0,<3 + # ciso8601>=2.1.3,<3 + # urllib3>=1.25.8,<2 + propagatedBuildInputs = [ + requests + ciso8601 + urllib3 + ]; + + meta = with lib; { + description = "Python client to retrieve data provided by DWD via their geoserver WFS API"; + homepage = https://github.com/stephan192/dwdwfsapi; + license = licenses.mit; + # maintainers = [ maintainers. ]; + }; +} diff --git a/makefu/2configs/home/ham/deps/pykodi.nix b/makefu/2configs/home/ham/deps/pykodi.nix new file mode 100644 index 000000000..85a541f8a --- /dev/null +++ b/makefu/2configs/home/ham/deps/pykodi.nix @@ -0,0 +1,37 @@ +{ lib +, buildPythonPackage +, fetchPypi +, jsonrpc-async +, jsonrpc-websocket +, aiohttp +}: + +buildPythonPackage rec { + pname = "pykodi"; + version = "0.2.2"; + + disabled = false; # requires python version >=3.7.0 + + src = fetchPypi { + inherit pname version; + sha256 = "43e7036a00a76f65c34dc5e7f1065a3ef071eea7619c2e6228e521b638e640bc"; + }; + + # # Package conditions to handle + # # might have to sed setup.py and egg.info in patchPhase + # # sed -i "s/...//" + # jsonrpc-async>=1.1.0 + # jsonrpc-websocket>=1.2.1 + propagatedBuildInputs = [ + jsonrpc-async + jsonrpc-websocket + aiohttp + ]; + + meta = with lib; { + description = "An async python interface for Kodi over JSON-RPC"; + homepage = https://github.com/OnFreund/PyKodi; + license = licenses.mit; + # maintainers = [ maintainers. ]; + }; +} diff --git a/makefu/2configs/home/ham/device_tracker/openwrt.nix b/makefu/2configs/home/ham/device_tracker/openwrt.nix new file mode 100644 index 000000000..0a34f702a --- /dev/null +++ b/makefu/2configs/home/ham/device_tracker/openwrt.nix @@ -0,0 +1,13 @@ +{ + services.home-assistant.config.device_tracker = + [ + { platform = "luci"; + host = "192.168.1.5"; + username = "root"; + password = import ; + interval_seconds = 30; # instead of 12seconds + consider_home = 300; # 5 minutes timeout + new_device_defaults.track_new_devices = true; + } + ]; +} diff --git a/makefu/2configs/home/ham/lib/default.nix b/makefu/2configs/home/ham/lib/default.nix new file mode 100644 index 000000000..45c86138b --- /dev/null +++ b/makefu/2configs/home/ham/lib/default.nix @@ -0,0 +1,44 @@ +let + prefix = "/ham"; +in +{ + inherit prefix; + say = let + # returns a list of actions to be performed on an mpd to say something + tts = { message, entity }: + [ + { + service = "media_player.turn_on"; + data.entity_id = entity; + } + { + service = "media_player.play_media"; + data = { + entity_id = entity; + media_content_type = "playlist"; + media_content_id = "ansage"; + }; + } + { + service = "media_player.turn_on"; + data.entity_id = entity; + } + { delay.seconds = 8; } + { + service = "tts.say"; + entity_id = entity; + data_template = { + inherit message; + language = "de"; + }; + } + ]; + in + { + firetv = message: tts { + inherit message; + entity = "firetv"; + }; + }; + zigbee.prefix = "/ham/zigbee"; +} diff --git a/makefu/2configs/home/ham/light/arbeitszimmer.nix b/makefu/2configs/home/ham/light/arbeitszimmer.nix new file mode 100644 index 000000000..bc60678b3 --- /dev/null +++ b/makefu/2configs/home/ham/light/arbeitszimmer.nix @@ -0,0 +1,24 @@ +let + arbeitszimmer_deko = [ + "light.led_wand" + "light.box_led_status" + "light.arbeitszimmer_led1_led_strip" # LED-Kreis in cube + ]; + arbeitszimmerbeleuchtung = [ + "light.arbeitszimmer_schrank_dimmer" + "light.arbeitszimmer_kerze" # arbeitszimmer_kerze + ]; +in { + services.home-assistant.config.light = [ + { + platform = "group"; + name = "Arbeitszimmerbeleuchtung"; + entities = arbeitszimmerbeleuchtung; + } + { + platform = "group"; + name = "Arbeitszimmer Deko"; + entities = arbeitszimmer_deko; + } + ]; +} diff --git a/makefu/2configs/home/ham/light/schlafzimmer.nix b/makefu/2configs/home/ham/light/schlafzimmer.nix new file mode 100644 index 000000000..e5370e3f8 --- /dev/null +++ b/makefu/2configs/home/ham/light/schlafzimmer.nix @@ -0,0 +1,14 @@ +let + schlafzimmer_licht = [ + "light.schlafzimmer_komode_osram" + # "light.schlafzimmer_schrank_osram" + ]; +in { + services.home-assistant.config.light = [ + { + platform = "group"; + name = "Schlafzimmerbeleuchtung"; + entities = schlafzimmer_licht; + } + ]; +} diff --git a/makefu/2configs/home/ham/light/wohnzimmer.nix b/makefu/2configs/home/ham/light/wohnzimmer.nix new file mode 100644 index 000000000..bc9c2778a --- /dev/null +++ b/makefu/2configs/home/ham/light/wohnzimmer.nix @@ -0,0 +1,24 @@ +let + wohnzimmerbeleuchtung = [ + "light.wohnzimmer_komode_osram_light" + "light.wohnzimmer_schrank_osram_light" + ]; + wohnzimmer_deko = [ + "light.wohnzimmer_fernseher_led_strip" # led um fernseher + "light.wohnzimmer_lichterkette_led_strip" # led um fernsehwand + "light.kinderzimmer_lichterkette_licht" # led um fenster + ]; +in { + services.home-assistant.config.light = [ + { + platform = "group"; + name = "Wohnzimmerbeleuchtung"; + entities = wohnzimmerbeleuchtung; + } + { + platform = "group"; + name = "Wohnzimmer Deko"; + entities = wohnzimmer_deko; + } + ]; +} diff --git a/makefu/2configs/home/ham/mqtt.nix b/makefu/2configs/home/ham/mqtt.nix new file mode 100644 index 000000000..cd1c328d7 --- /dev/null +++ b/makefu/2configs/home/ham/mqtt.nix @@ -0,0 +1,24 @@ +{ pkgs, config, ... }: +{ + services.mosquitto = { + enable = true; + host = "0.0.0.0"; + allowAnonymous = false; + checkPasswords = true; + # see /mosquitto + users.sensor = { + hashedPassword = "$6$2DXU7W1bvqXPqxkF$vtdz5KTd/T09hmoc9LjgEGFjvpwQbQth6vlVcr5hJNLgcBHv4U03YCKC8TKXbmQAa8xiJ76xJIg25kcL+KI3tg=="; + acl = [ "topic readwrite #" ]; + }; + users.hass = { + hashedPassword = "$6$SHuYGrE5kPSUc/hu$EomZ0KBy+vkxLt/6eJkrSBjYblCCeMjhDfUd2mwqXYJ4XsP8hGmZ59mMlmBCd3AvlFYQxb4DT/j3TYlrqo7cDA=="; + acl = [ "topic readwrite #" ]; + }; + users.stats = { + hashedPassword = "$6$j4H7KXD/YZgvgNmL$8e9sUKRXowDqJLOVgzCdDrvDE3+4dGgU6AngfAeN/rleGOgaMhee2Mbg2KS5TC1TOW3tYbk9NhjLYtjBgfRkoA=="; + acl = [ "topic read #" ]; + }; + }; + environment.systemPackages = [ pkgs.mosquitto ]; + # port open via trusted interface +} diff --git a/makefu/2configs/home/ham/multi/fliegen-couter.nix b/makefu/2configs/home/ham/multi/fliegen-couter.nix new file mode 100644 index 000000000..5b8abb2ff --- /dev/null +++ b/makefu/2configs/home/ham/multi/fliegen-couter.nix @@ -0,0 +1,71 @@ +# uses: +# sensor.btn1_click +# sensor.btn2_click +let + hlib = import ../lib; + fly_swat = for: btn: method: incr: { + alias = "Increment ${method} for ${for}"; + trigger = { + platform = "state"; + entity_id = "sensor.${btn}_click"; + to = method; + }; + action = builtins.genList (cnt: { + service = "counter.increment"; + data.entity_id = "counter.${for}_fliegen"; + }) incr; + }; +in +{ + services.home-assistant.config = + { + counter = { + felix_fliegen = {}; + misa_fliegen = {}; + }; + automation = [ + (fly_swat "misa" "btn1" "single" 1) + (fly_swat "misa" "btn1" "double" 2) + (fly_swat "misa" "btn1" "triple" 3) + (fly_swat "felix" "btn2" "single" 1) + (fly_swat "felix" "btn2" "double" 2) + (fly_swat "felix" "btn2" "triple" 3) + { + alias = "Send Fly Counter Update"; + trigger = [ + { + platform = "state"; + entity_id = "counter.felix_fliegen"; + } + { + platform = "state"; + entity_id = "counter.misa_fliegen"; + #above = -1; + } + ]; + action = { + service = "mqtt.publish"; + data_template = { # gauge-style + payload = "{{ trigger.to_state.state }}"; + topic = "${hlib.prefix}/flycounter/{{ trigger.to_state.object_id }}"; + }; + }; + } + { + alias = "Reset Fly counters on midnight"; + trigger = { + platform = "time"; + at = "01:00:00"; + }; + action = [ + { service = "counter.reset"; + data.entity_id = "counter.misa_fliegen"; + } + { service = "counter.reset"; + data.entity_id = "counter.felix_fliegen"; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/multi/flurlicht.nix b/makefu/2configs/home/ham/multi/flurlicht.nix new file mode 100644 index 000000000..25eb78b7f --- /dev/null +++ b/makefu/2configs/home/ham/multi/flurlicht.nix @@ -0,0 +1,57 @@ +# provides: +# light +# automation +# binary_sensor +let + hlib = (import ../lib); + tasmota = hlib.tasmota; +in +{ + binary_sensor = [ + (tasmota.motion { name = "Flur Bewegung"; host = "flurlicht";}) + ]; + light = [ (tasmota.rgb { name = "Flurlicht"; host = "flurlicht";} ) ]; + automation = [ + { alias = "Dunkel bei Sonnenuntergang"; + trigger = { + platform = "sun"; + event = "sunset"; + # offset: "-00:45:00" + }; + action = [ + { + service= "light.turn_on"; + data = { + entity_id= "light.flurlicht"; + # rgb_color = [ 0,0,0 ]; <-- TODO default color + brightness_pct = 15; + }; + } + { + service= "light.turn_off"; + entity_id= "light.flurlicht"; + } + ]; + } + { alias = "Hell bei Sonnenaufgang"; + trigger = { + platform = "sun"; + event = "sunrise"; + # offset: "-00:00:00" + }; + action = [ + { + service= "light.turn_on"; + data = { + entity_id= "light.flurlicht"; + brightness_pct = 85; + }; + } + { + service= "light.turn_off"; + entity_id= "light.flurlicht"; + } + ]; + } + ]; +} diff --git a/makefu/2configs/home/ham/multi/kurzzeitwecker.nix b/makefu/2configs/home/ham/multi/kurzzeitwecker.nix new file mode 100644 index 000000000..bd81465cb --- /dev/null +++ b/makefu/2configs/home/ham/multi/kurzzeitwecker.nix @@ -0,0 +1,135 @@ +# Provides: +# timer +# automation +# script + +# Needs: +# sensor.zigbee_btn1_click +# notify.telegrambot +let + button = "sensor.zigbee_btn2_click"; +in +{ + services.home-assistant.config = { + timer.kurzzeitwecker = + { + name = "Zigbee Kurzzeitwecker"; + duration = 300; + }; + script.add_5_minutes_to_kurzzeitwecker = + { + alias = "Add 5 minutes to kurzzeitwecker"; + sequence = [ + { service = "timer.pause"; + entity_id = "timer.kurzzeitwecker"; + } + { service = "timer.start"; + data_template = { + entity_id = "timer.kurzzeitwecker"; + duration = '' + {% set r = state_attr('timer.kurzzeitwecker', 'remaining') ~ '-0000' %} + {% set t = strptime(r, '%H:%M:%S.%f%z') %} + {{ (as_timestamp(t) + 300) | timestamp_custom('%H:%M:%S', false) }} + ''; + }; + } + ]; + }; + automation = + [ + { + alias = "Start Timer 5min"; + trigger = { + platform = "state"; + entity_id = button; + to = "single"; + }; + condition = + { condition = "state"; + entity_id = "timer.kurzzeitwecker"; + state = "idle"; + }; + + action = [ + { service = "timer.start"; + entity_id = "timer.kurzzeitwecker"; + data.duration = "00:05:00"; + } + { + service = "notify.telegrambot"; + data.message = "Timer gestartet {{state_attr('timer.kurzzeitwecker', 'remaining') }}, verbleibend "; + } + ]; + } + { + alias = "Add Timer 5min"; + trigger = { + platform = "state"; + entity_id = button; + to = "single"; + }; + condition = + { condition = "state"; + entity_id = "timer.kurzzeitwecker"; + state = "active"; + }; + + action = [ + { service = "homeassistant.turn_on"; + entity_id = "script.add_5_minutes_to_kurzzeitwecker"; + } + { + service = "notify.telegrambot"; + data.message = ''Timer um 5 minuten verlängert, {{ state_attr('timer.kurzzeitwecker', 'remaining') | truncate(9,True," ") }} verbleibend ''; + } + ]; + } + { + alias = "Stop timer on double click"; + trigger = [ + { + platform = "state"; + entity_id = button; + to = "double"; + } + { + platform = "state"; + entity_id = button; + to = "triple"; + } + ]; + condition = + { + condition = "state"; + entity_id = "timer.kurzzeitwecker"; + state = "active"; + }; + + action = [ + { + service = "timer.cancel"; + entity_id = "timer.kurzzeitwecker"; + } + { + service = "notify.telegrambot"; + data.message = "Timer gestoppt, abgebrochen"; + } + ]; + } + { + alias = "Timer Finished"; + trigger = { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.kurzzeitwecker"; + }; + action = [ + { + service = "notify.telegrambot"; + data.message = "Timer beendet"; + } + ]; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/multi/the_playlist.nix b/makefu/2configs/home/ham/multi/the_playlist.nix new file mode 100644 index 000000000..0d714ea44 --- /dev/null +++ b/makefu/2configs/home/ham/multi/the_playlist.nix @@ -0,0 +1,86 @@ +# Inputs: +# binary_sensor.playlist_button_good +# binary_sensor.playlist_button_bad + +# outputs +# rest_command +# automation +# sensor +{ + services.home-assistant.config = + { + rest_command = { + good_song = { + url = "http://prism.r:8001/good"; + method = "POST"; + }; + bad_song = { + url = "http://prism.r:8001/skip"; + method = "POST"; + }; + }; + automation = [ + { + alias = "playlist song publish"; + trigger = { + #platform = "event"; + #event_data.entity_id = "sensor.the_playlist_song"; + platform = "state"; + entity_id = "sensor.the_playlist_song"; + }; + action = { + service = "mqtt.publish"; + data = { + topic = "/ham/the_playlist/song"; + payload_template = "{{ states.sensor.the_playlist_song.state }}"; + }; + }; + } + { + alias = "playlist upvote on button"; + trigger = { + platform = "state"; + entity_id = "binary_sensor.playlist_button_good"; + from = "off"; + to = "on"; + }; + action.service = "rest_command.good_song"; + } + { + alias = "playlist downvote on button"; + trigger = { + platform = "state"; + entity_id = "binary_sensor.playlist_button_bad"; + from = "off"; + to = "on"; + }; + action.service = "rest_command.bad_song"; + } + ]; + sensor = [ + { platform = "rest"; + name = "pl"; + resource = "http://prism.r:8001/current"; + scan_interval = 30; + value_template = "1"; + json_attributes = [ "name" "filename" "youtube" ]; + } + { platform = "template"; + sensors = { + the_playlist_song = { + friendly_name = "Current Song"; + value_template = ''{{ states.sensor.pl.attributes['name'] }}''; + }; + the_playlist_url = { + friendly_name = "Song Youtube URL"; + value_template = ''{{ states.sensor.pl.attributes['youtube'] }}''; + }; + the_playlist_filename = { + friendly_name = "Song Filename"; + value_template = ''{{ states.sensor.pl.attributes['filename'] }}''; + }; + }; + } + ]; + }; +} diff --git a/makefu/2configs/home/ham/nginx.nix b/makefu/2configs/home/ham/nginx.nix new file mode 100644 index 000000000..2048ff215 --- /dev/null +++ b/makefu/2configs/home/ham/nginx.nix @@ -0,0 +1,10 @@ +let + internal-ip = "192.168.1.11"; +in { + services.nginx.recommendedProxySettings = true; + services.nginx.virtualHosts."hass" = { + serverAliases = [ "hass.lan" "ha" "ha.lan" ]; + locations."/".proxyPass = "http://localhost:8123"; + locations."/".proxyWebsockets = true; + }; +} diff --git a/makefu/2configs/home/ham/sensor/outside.nix b/makefu/2configs/home/ham/sensor/outside.nix new file mode 100644 index 000000000..332746be8 --- /dev/null +++ b/makefu/2configs/home/ham/sensor/outside.nix @@ -0,0 +1,25 @@ +{lib,...}: + +{ + services.home-assistant.config.sensor = + [ + { platform = "darksky"; + api_key = lib.removeSuffix "\n" + (builtins.readFile ); + language = "de"; + monitored_conditions = [ + "summary" "icon" + "nearest_storm_distance" "precip_probability" + "precip_intensity" + "temperature" # "temperature_high" "temperature_low" + "apparent_temperature" + "hourly_summary" # next 24 hours text + "humidity" + "pressure" + "uv_index" + ]; + units = "si" ; + scan_interval = "00:30:00"; + } + ]; +} diff --git a/makefu/2configs/home/ham/zigbee2mqtt/default.nix b/makefu/2configs/home/ham/zigbee2mqtt/default.nix new file mode 100644 index 000000000..a75075273 --- /dev/null +++ b/makefu/2configs/home/ham/zigbee2mqtt/default.nix @@ -0,0 +1,28 @@ +{config, pkgs, lib, ...}: + +let + dataDir = "/var/lib/zigbee2mqtt"; +in + { + # symlink the zigbee controller + services.udev.extraRules = '' + SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" + ''; + + services.zigbee2mqtt = { + enable = true; + inherit dataDir; + }; + + state = [ "${dataDir}/configuration.yaml" "${dataDir}/state.json" ]; + + systemd.services.zigbee2mqtt = { + # override automatic configuration.yaml deployment + serviceConfig.ExecStartPre = lib.mkForce "${pkgs.coreutils}/bin/true"; + after = [ + "home-assistant.service" + "mosquitto.service" + "network-online.target" + ]; + }; +} diff --git a/makefu/2configs/home/ham/zigbee2mqtt/hass.nix b/makefu/2configs/home/ham/zigbee2mqtt/hass.nix new file mode 100644 index 000000000..faf864ba6 --- /dev/null +++ b/makefu/2configs/home/ham/zigbee2mqtt/hass.nix @@ -0,0 +1,130 @@ +# provides: +# switch +# automation +# binary_sensor +# sensor +# input_select +# timer +let + inherit (import ../lib) zigbee; + prefix = zigbee.prefix; +in +{ + services.home-assistant.config = { + sensor = + + [ + # Sensor for monitoring the bridge state + { + platform = "mqtt"; + name = "Zigbee2mqtt Bridge state"; + state_topic = "${prefix}/bridge/state"; + icon = "mdi:router-wireless"; + } + # Sensor for Showing the Zigbee2mqtt Version + { + platform = "mqtt"; + name = "Zigbee2mqtt Version"; + state_topic = "${prefix}/bridge/config"; + value_template = "{{ value_json.version }}"; + icon = "mdi:zigbee"; + } + # Sensor for Showing the Coordinator Version + { + platform = "mqtt"; + name = "Coordinator Version"; + state_topic = "${prefix}/bridge/config"; + value_template = "{{ value_json.coordinator }}"; + icon = "mdi:chip"; + } + ]; + switch = [ + { + platform = "mqtt"; + name = "Zigbee2mqtt Main join"; + state_topic = "${prefix}/bridge/config/permit_join"; + command_topic = "${prefix}/bridge/config/permit_join"; + payload_on = "true"; + payload_off = "false"; + } + ]; + automation = [ + { + alias = "Zigbee2mqtt Log Level"; + initial_state = "on"; + trigger = { + platform = "state"; + entity_id = "input_select.zigbee2mqtt_log_level"; + }; + action = [ + { + service = "mqtt.publish"; + data = { + payload_template = "{{ states('input_select.zigbee2mqtt_log_level') }}"; + topic = "${prefix}/bridge/config/log_level"; + }; + } + ]; + } + # Automation to start timer when enable join is turned on + { + id = "zigbee_join_enabled"; + alias = "Zigbee Join Enabled"; + trigger = + { + platform = "state"; + entity_id = "switch.zigbee2mqtt_main_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"; + alias = "Zigbee Join Disabled"; + trigger = [ + { + platform = "event"; + event_type = "timer.finished"; + event_data.entity_id = "timer.zigbee_permit_join"; + } + { + platform = "state"; + entity_id = "switch.zigbee2mqtt_main_join"; + to = "off"; + } + ]; + action = [ + { service = "timer.cancel"; + data.entity_id = "timer.zigbee_permit_join"; + } + { service = "switch.turn_off"; + entity_id = "switch.zigbee2mqtt_main_join"; + } + ]; + } + ]; + input_select.zigbee2mqtt_log_level = + { + name = "Zigbee2mqtt Log Level"; + options = [ + "debug" + "info" + "warn" + "error" + ]; + initial = "info"; + icon = "mdi:format-list-bulleted"; + }; + + timer.zigbee_permit_join = + { + name = "Zigbee Time remaining"; + duration = 120; + }; + }; +} diff --git a/makefu/2configs/home/ham/zigbee2mqtt/osram.nix b/makefu/2configs/home/ham/zigbee2mqtt/osram.nix new file mode 100644 index 000000000..d1bf2b296 --- /dev/null +++ b/makefu/2configs/home/ham/zigbee2mqtt/osram.nix @@ -0,0 +1,14 @@ +{ + + +availability_topic: /ham/zigbee/bridge/state +command_topic: /ham/zigbee/flur_arbeitszimmer_osram2/set + + - platform: "mqtt" + state_topic: "zigbee2mqtt/" + availability_topic: "zigbee2mqtt/bridge/state" + payload_on: true + payload_off: false + value_template: "{{ value_json.battery_low}}" + device_class: "battery" +} -- cgit v1.2.3 From 833e7455b3d7f0e90553d229e0cac0b391474745 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 9 Mar 2021 22:15:34 +0100 Subject: ma home: init photoprism --- makefu/2configs/home/photoprism.nix | 146 ++++++++++++++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 makefu/2configs/home/photoprism.nix (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/photoprism.nix b/makefu/2configs/home/photoprism.nix new file mode 100644 index 000000000..aaccd7350 --- /dev/null +++ b/makefu/2configs/home/photoprism.nix @@ -0,0 +1,146 @@ +{ pkgs, lib, ...}: +# Start | docker-compose up -d +# Stop | docker-compose stop +# Update | docker-compose pull +# Logs | docker-compose logs --tail=25 -f +# Terminal | docker-compose exec photoprism bash +# Help | docker-compose exec photoprism photoprism help +# Config | docker-compose exec photoprism photoprism config +# Reset | docker-compose exec photoprism photoprism reset +# Backup | docker-compose exec photoprism photoprism backup -a -i +# Restore | docker-compose exec photoprism photoprism restore -a -i +# Index | docker-compose exec photoprism photoprism index +# Reindex | docker-compose exec photoprism photoprism index -a +# Import | docker-compose exec photoprism photoprism import +# ------------------------------------------------------------------- +let + port = "2347"; + photodir = "/media/cryptX/photos"; + statedir = "/var/lib/photoprism/appsrv"; + db-dir = "/var/lib/photoprism/mysql"; + internal-ip = "192.168.1.11"; + sec = import ; +in +{ + virtualisation.oci-containers.backend = "docker"; + + services.nginx.virtualHosts."photos" = { + serverAliases = [ + "photos.lan" + "foto" "foto.lan" + "fotos" "fotos.lan" + ]; + + locations."/".proxyPass = "http://localhost:${port}"; + locations."/".proxyWebsockets = true; + extraConfig = '' + if ( $server_addr != "${internal-ip}" ) { + return 403; + } + ''; + }; + + systemd.services.workadventure-network = { + enable = true; + wantedBy = [ "multi-user.target" ]; + script = '' + ${pkgs.docker}/bin/docker network create --driver bridge photoprism ||: + ''; + after = [ "docker" ]; + before = [ + "docker-photoprism.service" + "docker-mysql-photoprism.service" + ]; + }; + + + virtualisation.oci-containers.containers.photoprism = { + image = "photoprism/photoprism:preview"; + ports = ["${port}:${port}" ]; + volumes = [ + "${photodir}:/photoprism/originals" + "${statedir}:/photoprism/storage" + ]; + extraOptions = [ + "--security-opt" "seccomp=unconfined" + "--security-opt" "apparmor=unconfined" + "--network=photoprism" + ]; + environment = { + PHOTOPRISM_HTTP_PORT = port; # Built-in Web server port + PHOTOPRISM_HTTP_COMPRESSION = "gzip"; # Improves transfer speed and bandwidth utilization (none or gzip) + PHOTOPRISM_DEBUG = "false"; # Run in debug mode (shows additional log messages) + PHOTOPRISM_PUBLIC = "true"; # No authentication required (disables password protection) + PHOTOPRISM_READONLY = "false"; # Don't modify originals directory (reduced functionality) + PHOTOPRISM_EXPERIMENTAL = "true"; # Enables experimental features + PHOTOPRISM_DISABLE_WEBDAV = "false"; # Disables built-in WebDAV server + PHOTOPRISM_DISABLE_SETTINGS = "false"; # Disables Settings in Web UI + PHOTOPRISM_DISABLE_TENSORFLOW = "false"; # Disables using TensorFlow for image classification + PHOTOPRISM_DARKTABLE_PRESETS = "false"; # Enables Darktable presets and disables concurrent RAW conversion + PHOTOPRISM_DETECT_NSFW = "false"; # Flag photos as private that MAY be offensive (requires TensorFlow) + PHOTOPRISM_UPLOAD_NSFW = "true"; # Allow uploads that MAY be offensive + + #PHOTOPRISM_DATABASE_DRIVER = "postgres"; + #PHOTOPRISM_DATABASE_SERVER = "postgres-prism:5432"; + #PHOTOPRISM_DATABASE_NAME = "photoprism"; + #PHOTOPRISM_DATABASE_USER = "photoprism"; + #PHOTOPRISM_DATABASE_PASSWORD = "photoprism"; + + PHOTOPRISM_DATABASE_DRIVER= "mysql"; # Use MariaDB (or MySQL) instead of SQLite for improved performance + PHOTOPRISM_DATABASE_SERVER= "mysql-photoprism:3306" ; # MariaDB database server (hostname:port) + PHOTOPRISM_DATABASE_NAME= "photoprism"; # MariaDB database schema name + PHOTOPRISM_DATABASE_USER= sec.db.username; # MariaDB database user name + PHOTOPRISM_DATABASE_PASSWORD= sec.db.password; # MariaDB database user password + + PHOTOPRISM_SITE_URL = "http://localhost:2342/"; # Public PhotoPrism URL + PHOTOPRISM_SITE_TITLE = "PhotoPrism"; + PHOTOPRISM_SITE_CAPTION = "FeMi Fotos"; + PHOTOPRISM_SITE_DESCRIPTION = "Unsere Fotos"; + PHOTOPRISM_SITE_AUTHOR = "FeMi"; + + }; + }; + + virtualisation.oci-containers.containers.mysql-photoprism = { + image = "mariadb:10.5"; + extraOptions = [ + "--security-opt" "seccomp=unconfined" + "--security-opt" "apparmor=unconfined" + "--network=photoprism" + ]; + ports = [ "3306:3306" ]; # no need to expose the database + #cmd = [ "mysqld" + # "--transaction-isolation=READ-COMMITTED" + # "--character-set-server=utf8mb4" + # "--collation-server=utf8mb4_unicode_ci" + # "--max-connections=512" + # "--innodb-rollback-on-timeout=OFF" + # "--innodb-lock-wait-timeout=50" + #]; + volumes= [ "${db-dir}:/var/lib/mysql" ]; + environment = { + MYSQL_ROOT_PASSWORD = "dickidibutt"; + MYSQL_DATABASE= "photoprism"; + MYSQL_USER = sec.db.username; + MYSQL_PASSWORD = sec.db.password; + }; + }; + #virtualisation.oci-containers.containers.postgres-prism = { + # image = "postgres:12-alpine"; + # ports = [ "5432" ]; # no need to expose the database + # environment = { + # POSTGRES_DB = "photoprism"; + # POSTGRES_USER = "photoprism"; + # POSTGRES_PASSWORD = "photoprism"; + # }; + #}; + + systemd.services.photoprism.serviceConfig = { + StandardOutput = lib.mkForce "journal"; + StandardError = lib.mkForce "journal"; + }; + systemd.services.mysql-photoprism.serviceConfig = { + StandardOutput = lib.mkForce "journal"; + StandardError = lib.mkForce "journal"; + }; +} -- cgit v1.2.3 From 52035a5ce4b7d0ff71826e6e63c0a5a410e69e12 Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 9 Mar 2021 22:16:13 +0100 Subject: ma ham/zigbee2mqtt: add secrets --- makefu/2configs/home/ham/zigbee2mqtt/default.nix | 49 ++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/zigbee2mqtt/default.nix b/makefu/2configs/home/ham/zigbee2mqtt/default.nix index a75075273..83c3c187c 100644 --- a/makefu/2configs/home/ham/zigbee2mqtt/default.nix +++ b/makefu/2configs/home/ham/zigbee2mqtt/default.nix @@ -2,23 +2,66 @@ let dataDir = "/var/lib/zigbee2mqtt"; + sec = import ; in { # symlink the zigbee controller + #services.udev.extraRules = '' + # SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" + #''; services.udev.extraRules = '' - SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" + SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" ''; services.zigbee2mqtt = { enable = true; inherit dataDir; + config = { + permit_join = true; + serial.port = "/dev/cc2531"; + homeassistant = true; + mqtt = { + server = "mqtt://omo.lan:1883"; + base_topic = "/ham/zigbee"; + user = sec.mqtt.username; + password = sec.mqtt.password; + include_device_information = true; + client_id = "zigbee2mqtt"; + }; + advanced = { + log_level = "debug"; + log_output = [ "console" ]; + last_seen = "ISO_8601"; + elapsed = true; + reporting = true; # TODO test if it is better with groups + pan_id = 6755; + inherit (sec.zigbee) network_key; + }; + map_options.graphviz.colors = { + fill = { + enddevice = "#fff8ce" ; + coordinator = "#e04e5d"; + router = "#4ea3e0"; + }; + font = { + coordinator= "#ffffff"; + router = "#ffffff"; + enddevice = "#000000"; + }; + line = { + active = "#009900"; + inactive = "#994444"; + }; + }; + }; }; - state = [ "${dataDir}/configuration.yaml" "${dataDir}/state.json" ]; + state = [ "${dataDir}/devices.yaml" "${dataDir}/state.json" ]; systemd.services.zigbee2mqtt = { # override automatic configuration.yaml deployment - serviceConfig.ExecStartPre = lib.mkForce "${pkgs.coreutils}/bin/true"; + environment.ZIGBEE2MQTT_DATA = dataDir; + #serviceConfig.ExecStartPre = lib.mkForce "${pkgs.coreutils}/bin/true"; after = [ "home-assistant.service" "mosquitto.service" -- cgit v1.2.3 From 07147023ddf7796562017a62369348a6a1b02fdc Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 9 Mar 2021 22:16:33 +0100 Subject: ma ham: use --- makefu/2configs/home/ham/default.nix | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/default.nix b/makefu/2configs/home/ham/default.nix index 8ed5f8f3c..e164b177f 100644 --- a/makefu/2configs/home/ham/default.nix +++ b/makefu/2configs/home/ham/default.nix @@ -7,12 +7,7 @@ let prefix = (import ./lib).prefix; firetv_stick = "192.168.1.24"; hassdir = "/var/lib/hass"; - unstable = import (pkgs.fetchFromGitHub { - owner = "nixos"; - repo = "nixpkgs"; - rev = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).rev; - sha256 = (lib.importJSON ../../../krebs/nixpkgs-unstable.json).sha256; - }) {}; + unstable = import {}; in { -- cgit v1.2.3 From 64bc6f1f6578de055ebdec5748f9af7c6a7d875c Mon Sep 17 00:00:00 2001 From: makefu Date: Tue, 9 Mar 2021 22:17:00 +0100 Subject: ma ham: add fenster_auf automation --- .../2configs/home/ham/automation/fenster_auf.nix | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 makefu/2configs/home/ham/automation/fenster_auf.nix (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/automation/fenster_auf.nix b/makefu/2configs/home/ham/automation/fenster_auf.nix new file mode 100644 index 000000000..ccebd5b00 --- /dev/null +++ b/makefu/2configs/home/ham/automation/fenster_auf.nix @@ -0,0 +1,33 @@ +let + min = 20; + fenster_offen = name: entity: + { alias = "${name} seit ${toString min} Minuten offen"; + trigger = [ + { + platform = "state"; + entity_id = entity; + to = "on"; + for.minutes = min; + } + ]; + action = + [ + { + service = "notify.firetv_wohnzimmer"; + data = { + title = "${name} seit ${toString min} Minuten offen"; + message = "Bitte einmal checken ob das ok ist :)"; + data = { + interrupt = 1; + duration = 300; + }; + }; + } + ]; + }; +in { + services.home-assistant.config.automation = [ + (fenster_offen "Badezimmerfenster" "binary_sensor.badezimmer_fenster_contact") + (fenster_offen "Duschfenster" "binary_sensor.dusche_fenster_contact") + ]; +} -- cgit v1.2.3 From ba614307cdc027dddd9aee2fecdaac86336957eb Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 12 Mar 2021 20:10:27 +0100 Subject: ma omo.r: deploy airsonic,photoprism,metube --- makefu/2configs/home/airsonic.nix | 29 +++++++++++++++++++++++++++++ makefu/2configs/home/metube.nix | 35 +++++++++++++++++++++++++++++++++++ makefu/2configs/home/photoprism.nix | 9 +++++---- 3 files changed, 69 insertions(+), 4 deletions(-) create mode 100644 makefu/2configs/home/airsonic.nix create mode 100644 makefu/2configs/home/metube.nix (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/airsonic.nix b/makefu/2configs/home/airsonic.nix new file mode 100644 index 000000000..15e77438d --- /dev/null +++ b/makefu/2configs/home/airsonic.nix @@ -0,0 +1,29 @@ +{ config, ... }: +let + internal-ip = "192.168.1.11"; + port = 4040; +in +{ + # networking.firewall.allowedTCPPorts = [ 4040 ]; + services.airsonic = { + enable = true; + listenAddress = "0.0.0.0"; + inherit port; + }; + state = [ config.services.airsonic.home ]; + services.nginx.virtualHosts."airsonic" = { + serverAliases = [ + "airsonic.lan" + "music" "music.lan" + "musik" "musik.lan" + ]; + + locations."/".proxyPass = "http://localhost:${toString port}"; + locations."/".proxyWebsockets = true; + extraConfig = '' + if ( $server_addr != "${internal-ip}" ) { + return 403; + } + ''; + }; +} diff --git a/makefu/2configs/home/metube.nix b/makefu/2configs/home/metube.nix new file mode 100644 index 000000000..c872bea08 --- /dev/null +++ b/makefu/2configs/home/metube.nix @@ -0,0 +1,35 @@ +{ pkgs, lib, ...}: +# docker run -d -p 8081:8081 -v /path/to/downloads:/downloads --user 1001:1001 alexta69/metube +with import ; +let + port = "2348"; + dl-dir = "/media/cryptX/youtube/music"; + uid = 20421; + internal-ip = "192.168.1.11"; +in + { + systemd.tmpfiles.rules = [ + "d ${dl-dir} metube nogroup - -" + ]; + virtualisation.oci-containers.backend = "docker"; + + services.nginx.virtualHosts."tube" = { + serverAliases = [ "tube.lan" ]; + locations."/".proxyPass = "http://localhost:${port}"; + }; + + virtualisation.oci-containers.containers.metube = { + image = "alexta69/metube:latest"; + ports = [ "${port}:8081" ]; + volumes = [ + "${dl-dir}:/downloads" + ]; + user = "metube"; + }; + users.users.metube.uid = uid; + + systemd.services.docker-metube.serviceConfig = { + StandardOutput = lib.mkForce "journal"; + StandardError = lib.mkForce "journal"; + }; +} diff --git a/makefu/2configs/home/photoprism.nix b/makefu/2configs/home/photoprism.nix index aaccd7350..ef4200576 100644 --- a/makefu/2configs/home/photoprism.nix +++ b/makefu/2configs/home/photoprism.nix @@ -16,8 +16,8 @@ let port = "2347"; photodir = "/media/cryptX/photos"; - statedir = "/var/lib/photoprism/appsrv"; - db-dir = "/var/lib/photoprism/mysql"; + statedir = "/media/cryptX/lib/photoprism/appsrv"; + db-dir = "/media/cryptX/lib/photoprism/mysql"; internal-ip = "192.168.1.11"; sec = import ; in @@ -97,6 +97,7 @@ in PHOTOPRISM_SITE_CAPTION = "FeMi Fotos"; PHOTOPRISM_SITE_DESCRIPTION = "Unsere Fotos"; PHOTOPRISM_SITE_AUTHOR = "FeMi"; + PHOTOPRISM_SPONSOR = "true"; }; }; @@ -135,11 +136,11 @@ in # }; #}; - systemd.services.photoprism.serviceConfig = { + systemd.services.docker-photoprism.serviceConfig = { StandardOutput = lib.mkForce "journal"; StandardError = lib.mkForce "journal"; }; - systemd.services.mysql-photoprism.serviceConfig = { + systemd.services.docker-mysql-photoprism.serviceConfig = { StandardOutput = lib.mkForce "journal"; StandardError = lib.mkForce "journal"; }; -- cgit v1.2.3 From cd6a3637d4ca727b0f3277e1478130a8aa1fd8c0 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 12 Mar 2021 20:27:57 +0100 Subject: ma ham: protect application server from external requests --- makefu/2configs/home/ham/nginx.nix | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/nginx.nix b/makefu/2configs/home/ham/nginx.nix index 2048ff215..e166b2a4b 100644 --- a/makefu/2configs/home/ham/nginx.nix +++ b/makefu/2configs/home/ham/nginx.nix @@ -6,5 +6,10 @@ in { serverAliases = [ "hass.lan" "ha" "ha.lan" ]; locations."/".proxyPass = "http://localhost:8123"; locations."/".proxyWebsockets = true; + extraConfig = '' + if ( $server_addr != "${internal-ip}" ) { + return 403; + } + ''; }; } -- cgit v1.2.3 From 31cb697190ea6d5c50925048a897880278eaf511 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 12 Mar 2021 20:28:20 +0100 Subject: ma ham/zigbee2mqtt: enable frontend --- makefu/2configs/home/ham/zigbee2mqtt/default.nix | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'makefu/2configs/home') diff --git a/makefu/2configs/home/ham/zigbee2mqtt/default.nix b/makefu/2configs/home/ham/zigbee2mqtt/default.nix index 83c3c187c..6ccf8b241 100644 --- a/makefu/2configs/home/ham/zigbee2mqtt/default.nix +++ b/makefu/2configs/home/ham/zigbee2mqtt/default.nix @@ -3,12 +3,16 @@ let dataDir = "/var/lib/zigbee2mqtt"; sec = import ; + internal-ip = "192.168.1.11"; + webport = 8521; in { # symlink the zigbee controller #services.udev.extraRules = '' # SUBSYSTEM=="tty", ATTRS{idVendor}=="0451", ATTRS{idProduct}=="16a8", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" #''; + + # /dev/serial/by-id/usb-Silicon_Labs_slae.sh_cc2652rb_stick_-_slaesh_s_iot_stuff_00_12_4B_00_21_CC_45_BD-if00-port0 services.udev.extraRules = '' SUBSYSTEM=="tty", ATTRS{idVendor}=="10c4", ATTRS{idProduct}=="ea60", SYMLINK+="cc2531", MODE="0660", GROUP="dialout" ''; @@ -28,6 +32,9 @@ in include_device_information = true; client_id = "zigbee2mqtt"; }; + frontend = { + port = webport; + }; advanced = { log_level = "debug"; log_output = [ "console" ]; @@ -56,6 +63,19 @@ in }; }; + services.nginx.recommendedProxySettings = true; + services.nginx.virtualHosts."zigbee" = { + serverAliases = [ "zigbee.lan" ]; + locations."/".proxyPass = "http://localhost:${toString webport}"; + locations."/api".proxyPass = "http://localhost:${toString webport}"; + locations."/api".proxyWebsockets = true; + extraConfig = '' + if ( $server_addr != "${internal-ip}" ) { + return 403; + } + ''; + }; + state = [ "${dataDir}/devices.yaml" "${dataDir}/state.json" ]; systemd.services.zigbee2mqtt = { -- cgit v1.2.3 From 46c9132c5a0b94427bee5ad8bf7d41f421d0208d Mon Sep 17 00:00:00