This commit is contained in:
Ingolf Wagner 2023-01-19 23:03:24 +01:00
parent 2567f78054
commit 72612b2c3f
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
15 changed files with 0 additions and 1517 deletions

View file

@ -1,294 +0,0 @@
{ pkgs, config, lib, ... }: {
imports = [
./home-assistant/zigbee2mqtt.nix
];
networking.firewall.allowedTCPPorts = [ 8123 ];
networking.firewall.allowedUDPPorts = [ 8123 ];
services.homeAssistantConfig = {
# turn on to edit GUI
lovelace = { };
homeassistant = {
name = "Home";
latitude = 51.444847;
longitude = 6.967006;
elevation = 116;
unit_system = "metric";
time_zone = config.time.timeZone;
auth_providers = [{
type = "trusted_networks";
trusted_networks = [
config.module.cluster.services.tinc."private".networkSubnet
"192.168.178.0/24"
"127.0.0.1"
];
}];
};
# needed, don't know why
default_config = { };
config = { };
# to grab metrics via prometheus
prometheus.namespace = "hass";
# manual state
# ------------
# all scenes
input_select.scene = {
icon = "mdi:brightness-auto";
options = [ "up-bright" "up-dark" "half" "down" "night" "outside" ];
};
# scenes controlled by buttons
input_select.scene_button = {
icon = "mdi:brightness-auto";
options = [ "up-dark" "night" ];
};
input_boolean.situation_toggle.icon = "mdi:toggle-switch";
input_boolean.printer_toggle.icon = "mdi:toggle-switch";
input_boolean.windows_up.icon = "mdi:toggle-switch";
automation = [
{
alias = "Hold Button -> Toggle Printer";
trigger = {
platform = "state";
entity_id = "input_boolean.printer_toggle";
};
action = {
service = "switch.toggle";
data.entity_id = "switch.pal02";
};
}
{
alias = "set light-control scene";
trigger = {
platform = "state";
entity_id = "input_select.scene";
};
action = {
service = "mqtt.publish";
data_template = {
topic = "control/lights/set";
payload_template =
''{"scene":"{{ states('input_select.scene')}}"}'';
};
};
}
# control situation with buttons
{
alias = "Button -> Change Scene";
trigger = {
platform = "state";
entity_id = "input_boolean.situation_toggle";
};
action = {
service = "input_select.select_next";
data.entity_id = "input_select.scene_button";
};
}
{
alias = "Button Scene -> Scene";
trigger = {
platform = "state";
entity_id = "input_select.scene_button";
};
action = {
service = "input_select.select_option";
data_template = {
entity_id = "input_select.scene";
option = "{{ states('input_select.scene_button') }}";
};
};
}
# outside and home
{
alias = "when opening door I'm outside";
trigger = [
{
platform = "state";
# todo : groups are not working right now
entity_id = "binary_sensor.door_sensor_4";
from = "off";
to = "on";
}
{
platform = "state";
# todo : groups are not working right now
entity_id = "binary_sensor.door_sensor_4";
from = "on";
to = "off";
}
];
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.scene";
option = "outside";
};
}];
}
{
alias = "reset everything when back home";
trigger = map
(entity_id: {
platform = "state";
entity_id = entity_id;
from = "off";
to = "on";
}) [
"binary_sensor.motion_sensor_1"
"binary_sensor.motion_sensor_2"
"binary_sensor.motion_sensor_3"
"binary_sensor.motion_sensor_4"
"binary_sensor.motion_sensor_5"
"binary_sensor.motion_sensor_6"
"binary_sensor.motion_sensor_7"
"binary_sensor.motion_sensor_8"
];
condition = {
condition = "template";
value_template =
''{{ states.input_select.scene.state == "outside" }}'';
};
action = [{
service = "input_select.select_option";
data = {
entity_id = "input_select.scene";
option = "up-dark";
};
}];
}
];
group =
let
create_room = { name, description }: {
"${name}" = {
name = "${description}";
entities = [ ];
};
};
create_rooms = rooms:
lib.foldr (a: b: a // b) { } (map create_room rooms);
# rooms
# -----
in
(create_rooms [
{
name = "floor_room";
description = "Flur";
}
{
name = "bed_room";
description = "Schlafzimmer";
}
{
name = "living_room";
description = "Wohnzimmer";
}
{
name = "kitchen_room";
description = "Küche";
}
{
name = "bath_room";
description = "Klo";
}
]) // {
# overview
# --------
all_sensors = { name = "Alle Sensoren"; };
today = {
name = "Today";
entities = [ "input_select.scene" ];
};
# other stuff
# -----------
tv = { name = "TV"; };
all_lights = { name = "Alle Lampen"; };
unknown = {
name = "Not Used";
entities = [ ];
};
};
};
services.home-assistant = {
enable = true;
package = pkgs.unstable.home-assistant;
#package = pkgs.unstable.home-assistant.override {
# python3 = pkgs.unstable.python37;
# extraPackages = python: [
# # todo : check which is still needed
# python.netdisco
# python.xmltodict
# python.mpd2
# # for mqtt
# python.hbmqtt
# python.paho-mqtt
# # needed for platform workday
# #(python.buildPythonPackage rec {
# # pname = "holidays";
# # version = "0.9.10";
# # src = python.fetchPypi {
# # inherit pname version;
# # sha256 =
# # "9f06d143eb708e8732230260636938f2f57114e94defd8fa2082408e0d422d6f";
# # };
# # doCheck = false;
# # buildInputs = [ pkgs.dateutils ];
# # propagatedBuildInputs = [ python."python-dateutil" python."six" ];
# # meta = with pkgs.stdenv.lib; {
# # homepage = "https://github.com/dr-prodigy/python-holidays";
# # license = licenses.mit;
# # description = "Generate and work with holidays in Python";
# # maintainers = with maintainers; [ mrVanDalo ];
# # };
# #})
# ];
#};
};
# host nginx setup
services.nginx = {
enable = true;
recommendedProxySettings = true;
virtualHosts = {
"iot.pepe.private" = {
serverAliases = [ "hass.pepe.private" "home.pepe.private" ];
extraConfig = ''
proxy_buffering off;
'';
locations."/" = {
proxyPass = "http://127.0.0.1:8123";
proxyWebsockets = true;
extraConfig = ''
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection $connection_upgrade;
'';
};
};
};
};
}

View file

@ -1,80 +0,0 @@
{ config, pkgs, ... }:
let
name = "chaospott";
folderPath = config.services.home-assistant.configDir;
filePath = "${folderPath}/${name}.json";
in
{
services.homeAssistantConfig = {
sensor = [
{
platform = "file";
name = "${name}_aerie";
file_path = filePath;
value_template = "{{ value_json.aerie }}";
}
{
platform = "file";
name = "${name}_cellar";
file_path = filePath;
value_template = "{{ value_json.cellar }}";
}
];
homeassistant = {
whitelist_external_dirs = [ folderPath ];
customize = {
"sensor.${name}_aerie" = {
icon = "mdi:store";
entity_picture = "https://chaospott.de/images/logo.png";
friendly_name = "ChaosPott Oben";
};
"sensor.${name}_cellar" = {
icon = "mdi:store";
entity_picture = "https://chaospott.de/images/logo.png";
friendly_name = "ChaosPott Unten";
};
};
};
group = {
"${name}" = {
name = "ChaosPott (Essen)";
entities = [ "sensor.${name}_aerie" "sensor.${name}_cellar" ];
};
};
};
systemd.services."${name}" = {
enable = true;
before = [ "home-assistant.service" ];
wantedBy = [ "home-assistant.service" ];
serviceConfig = {
User = "hass";
Type = "oneshot";
};
description = "set ${name} for homeassistant";
script = ''
${pkgs.curl}/bin/curl --location --silent https://status.chaospott.de/api \
| ${pkgs.jq}/bin/jq --compact-output \
'.sensors.door_locked |
[.[] | { "\(.location)" : (if .value then "closed" else "open" end) }] |
reduce .[] as $item ({}; . + $item) ' \
>> ${filePath}
'';
};
systemd.timers."${name}" = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "hourly";
Persistent = "true";
};
};
}

View file

@ -1,30 +0,0 @@
{ lib, pkgs, config, ... }: {
users.users.heater-control = { };
#systemd.services.heater-control = {
# enable = true;
# wantedBy = [ "multi-user.target" ];
# serviceConfig = { User = "heater-control"; };
# script =
# let myPython = pkgs.python3.withPackages (ps: with ps; [ paho-mqtt ]);
# in ''
# cd ${<mqtt>}
# ${myPython}/bin/python heater.py
# '';
#};
users.users.fyrtur-control = { };
systemd.services.fyrtur-control = {
enable = true;
wantedBy = [ "multi-user.target" ];
serviceConfig = { User = "fyrtur-control"; };
script =
let myPython = pkgs.python3.withPackages (ps: with ps; [ paho-mqtt ]);
in ''
cd ${<mqtt>}
${myPython}/bin/python fyrtur.py
'';
};
}

View file

@ -1,45 +0,0 @@
{ pkgs, config, lib, ... }: {
services.homeAssistantConfig = {
media_player = [{
platform = "kodi";
host = "127.0.0.1";
}];
shell_command = {
start_kodi = "sudo ${pkgs.systemd}/bin/systemctl start display-manager";
stop_kodi = "sudo ${pkgs.systemd}/bin/systemctl stop display-manager";
};
automation = [
{
alias = "turn kodi on once the tv is turned on";
trigger = {
platform = "state";
entity_id = "group.tv";
from = "off";
to = "on";
for.seconds = 60;
};
action = [{ service = "shell_command.start_kodi"; }];
}
{
alias = "turn off kodi on once the tv is turned off";
trigger = {
platform = "state";
entity_id = "group.tv";
from = "on";
to = "off";
};
action = [{ service = "shell_command.stop_kodi"; }];
}
];
};
security.sudo.extraConfig = ''
hass ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl start display-manager
hass ALL= (root) NOPASSWD: ${pkgs.systemd}/bin/systemctl stop display-manager
'';
}

View file

@ -1,232 +0,0 @@
{ pkgs, lib, config, ... }: {
services.mqtt.light-control.enable = true;
services.mqtt.light-control.loglevel = "debug";
services.mqtt.light-control.config = {
credentials = {
host = "tcp://localhost:1883";
user = "homeassistant";
password = "hallo";
};
scenes = [
{
name = "up-dark";
ignored_sensors = [
"zigbee2mqtt/door_sensor_1"
"zigbee2mqtt/door_sensor_4"
"zigbee2mqtt/door_sensor_5"
];
}
{
name = "half";
ignored_sensors = [
"zigbee2mqtt/door_sensor_1"
"zigbee2mqtt/door_sensor_4"
"zigbee2mqtt/door_sensor_5"
];
disabled_switches = [
"zigbee2mqtt/led_1"
"zigbee2mqtt/led_2"
"zigbee2mqtt/light_2"
"zigbee2mqtt/light_4"
"zigbee2mqtt/light_5"
"zigbee2mqtt/light_7"
];
}
{
name = "down";
ignored_sensors = [
"zigbee2mqtt/door_sensor_1"
"zigbee2mqtt/door_sensor_4"
"zigbee2mqtt/door_sensor_5"
];
}
{
name = "up-bright";
disabled_switches = [
"zigbee2mqtt/led_1"
"zigbee2mqtt/led_2"
"zigbee2mqtt/light_2"
"zigbee2mqtt/light_4"
"zigbee2mqtt/light_5"
"zigbee2mqtt/light_7"
];
ignored_sensors = [ "zigbee2mqtt/door_sensor_4" ];
}
{
name = "outside";
room_tracking_enabled = false;
ignored_sensors = [ "zigbee2mqtt/door_sensor_4" ];
}
{
name = "night";
room_tracking_enabled = false;
brightness = 25;
ignored_sensors =
[ "zigbee2mqtt/motion_sensor_7" "zigbee2mqtt/door_sensor_4" ];
}
];
sensors =
let
door = { topic, room }: {
topic = topic;
key = "contact";
room = room;
invert_state = true;
delay = 90;
};
motion = { topic, room }: {
topic = topic;
key = "occupancy";
room = room;
delay = 60;
};
in
[
(motion {
topic = "zigbee2mqtt/motion_sensor_1";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_2";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_6";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_8";
room = "office_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_7";
room = "sleeping_room";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_5";
room = "kitchen";
})
(motion {
topic = "zigbee2mqtt/motion_sensor_4";
room = "storage_room";
})
(door {
topic = "zigbee2mqtt/door_sensor_1";
room = "storage_room";
})
(door {
topic = "zigbee2mqtt/door_sensor_5";
room = "sleeping_room";
})
(door {
# house door
topic = "zigbee2mqtt/door_sensor_4";
room = "floor";
})
];
switches =
let
sonoff = { id, rooms, delay ? 0 }: {
topic = "stat/${id}/RESULT";
key = "POWER";
rooms = rooms;
delay = delay;
command = {
command = "{{state}}";
init_command = "(null)";
topic = "cmnd/${id}/POWER";
on = "ON";
off = "OFF";
};
};
light = { topic, rooms, delay ? 0 }: {
topic = topic;
key = "state";
rooms = rooms;
delay = delay;
command = {
command = ''{"state":"{{state}}","brightness":{{brightness}}}'';
topic = "${topic}/set";
on = "ON";
off = "OFF";
};
};
led = { topic, rooms, delay ? 0 }: {
topic = topic;
key = "state";
rooms = rooms;
delay = delay;
command = {
# Configure it once to the color you like
# {"state":"{{state}}","brightness":{{brightness}},"color":{"hex":"#FFFFFF},"color_temp":255","transition":0}
command = ''
{"state":"{{state}}","brightness":{{brightness}},"transition":0}'';
topic = "${topic}/set";
on = "ON";
off = "OFF";
};
};
in
[
(light {
topic = "zigbee2mqtt/light_2";
rooms = [ "office_room" ];
})
(light {
topic = "zigbee2mqtt/light_4";
rooms = [ "office_room" ];
})
(light {
topic = "zigbee2mqtt/light_5";
rooms = [ "storage_room" ];
})
(light {
topic = "zigbee2mqtt/light_7";
rooms = [ "sleeping_room" ];
})
(led {
topic = "zigbee2mqtt/led_1";
rooms = [ "office_room" ];
})
(led {
topic = "zigbee2mqtt/led_2";
rooms = [ "kitchen" ];
})
#(sonoff {
# id = "PAL01";
# rooms = [ "bed_room" ];
#})
#(sonoff {
# id = "PAL03";
# rooms = [ "living_room" ];
#})
#(sonoff {
# id = "PAL04";
# rooms = [ "bed_room" ];
#})
#(sonoff {
# id = "PAL06";
# rooms = [ "kitchen" ];
#})
## monitor and speakers
#(sonoff {
# id = "PAL07";
# rooms = [ "bed_room" ];
# delay = 180;
#})
#(sonoff {
# id = "PAL08";
# rooms = [ "bed_room" ];
# delay = 180;
#})
];
};
}

View file

@ -1,13 +0,0 @@
{ lib, ... }:
{
services.homeAssistantConfig = {
media_player = [{
platform = "mpd";
host = "localhost";
}];
};
}

View file

@ -1,116 +0,0 @@
{ pkgs, config, lib, ... }:
let
sonoffSwitches = {
#"pal01" = {
# label = "Schlafzimmer Lampe Links";
# icon = "mdi:lightbulb";
# groups = [ "bed_room" ];
#};
"pal02" = {
label = "Drucker / Scanner";
icon = "mdi:printer";
groups = [ "bed_room" "today" ];
};
#"pal03" = {
# label = "Wohnzimmer Lampe";
# icon = "mdi:lightbulb";
# groups = [ "living_room" ];
#};
#"pal04" = {
# label = "Schlafzimmer Lampe Rechts";
# icon = "mdi:lightbulb";
# groups = [ "bed_room" ];
#};
"pal05" = {
label = "TV";
icon = "mdi:television";
groups = [ "tv" ];
device = "tv";
};
#"pal06" = {
# label = "Küchen Lampe";
# icon = "mdi:lightbulb";
# groups = ["kitchen_room"];
#};
"pal07" = { label = "Nummer 7"; };
"pal08" = { label = "Nummer 8"; };
};
toSwitch = name: "switch.${name}";
in
{
imports = [ ./mqtt.nix ];
services.homeAssistantConfig = {
# nicer names
# -----------
homeassistant.customize = lib.mapAttrs'
(entity:
{ label, icon ? "mdi:power-plug-off", ... }: {
name = toSwitch entity;
value = {
friendly_name = label;
icon = icon;
};
})
sonoffSwitches;
# define switches
# ---------------
switch = lib.mapAttrsToList
(name:
{ ... }: {
name = name;
platform = "mqtt";
command_topic = "cmnd/${lib.toUpper name}/POWER";
state_topic = "stat/${lib.toUpper name}/POWER";
payload_on = "ON";
payload_off = "OFF";
state_on = "ON";
state_off = "OFF";
})
sonoffSwitches;
# discover state on init
# ----------------------
automation = [{
alias = "Sonoff initial Power state";
trigger = {
platform = "homeassistant";
event = "start";
};
action = lib.mapAttrsToList
(name:
{ ... }: {
service = "mqtt.publish";
data = {
topic = "cmnd/${lib.toUpper name}/power";
payload = "";
};
})
sonoffSwitches;
}];
# append to groups
# ----------------
group =
let
# sort lights into given groups.
sortedInGroups =
let
groupEntries = lib.zipAttrs (lib.flatten (lib.mapAttrsToList
(name:
{ groups ? [ ], ... }:
map (groupName: { "${groupName}" = "switch.${name}"; }) groups)
sonoffSwitches));
in
lib.mapAttrs (name: entities: { inherit entities; }) groupEntries;
in
sortedInGroups;
};
}

View file

@ -1,182 +0,0 @@
{ lib, config, pkgs, ... }:
let
folderPath = config.services.home-assistant.configDir;
# find symbols with
# https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=<keywords>&apikey=<api_key>
# as described here : https://www.alphavantage.co/documentation/#symbolsearch
#
# example:
# --------
# stocks = [
# {
# symbol = "GOOGL";
# name = "google";
# friendly_name = "Google";
# currency = "$";
# # I own 50 and bought at a price of 1000
# own = {
# pieces = 50;
# price = 1000;
# };
# }
# ];
stocks = import <secrets/home-assistant/stocks>;
filePath = name: "${folderPath}/stock_${name}.json";
cleanup_list = list: lib.filter (entry: entry != { }) (lib.flatten list);
in
{
services.homeAssistantConfig = {
sensor = cleanup_list (map
({ name, currency, own ? { }, ... }: [
{
platform = "file";
name = "stock_${name}";
file_path = filePath name;
value_template = "{{ value_json.price}} ${currency}";
}
{
platform = "file";
name = "stock_${name}_change";
file_path = filePath name;
value_template = "{{ value_json.change}} ${currency}";
}
{
platform = "file";
name = "stock_${name}_change_percent";
file_path = filePath name;
value_template = "{{ value_json.change_percent}} %";
}
(lib.optionalAttrs (own != { }) {
platform = "file";
name = "stock_${name}_profit";
file_path = filePath name;
value_template = ''
{{ "{:,.2f}".format( value_json.price * ${toString own.pieces} - ${
toString (own.pieces * own.price)
} ) }} ${currency}'';
})
])
stocks);
homeassistant = {
whitelist_external_dirs = [ folderPath ];
customize = builtins.listToAttrs (cleanup_list (map
({ name, own ? { }, ... }: [
{
name = "sensor.stock_${name}";
value = {
icon = "mdi:cash-usd-outline";
friendly_name = "Price";
};
}
{
name = "sensor.stock_${name}_change";
value = {
icon = "mdi:radar";
friendly_name = "Difference";
};
}
{
name = "sensor.stock_${name}_change_percent";
value = {
icon = "mdi:radar";
friendly_name = "Percent";
};
}
(lib.optionalAttrs (own != { }) {
name = "sensor.stock_${name}_profit";
value = {
icon = "mdi:radar";
friendly_name = "Profit";
};
})
])
stocks));
};
group = (builtins.listToAttrs (map
({ name, friendly_name, own ? { }, ... }: {
name = "stock_${name}";
value = {
name = "${friendly_name} Aktie";
entities = [
"sensor.stock_${name}"
"sensor.stock_${name}_change"
"sensor.stock_${name}_change_percent"
] ++ (lib.optional (own != { }) "sensor.stock_${name}_profit");
};
})
stocks));
};
systemd.services =
let
pullService = { name, symbol, currency, ... }: {
name = "pull_stock_${name}";
value = {
enable = true;
before = [ "home-assistant.service" ];
wantedBy = [ "home-assistant.service" ];
serviceConfig = {
User = "hass";
Type = "oneshot";
};
description = "pull stock_${name} for homeassistant";
script = ''
SYMBOL="${symbol}"
CURRENCY="${currency}"
APIKEY=${
lib.fileContents <secrets/home-assistant/alphavantage/apikey>
}
${pkgs.curl}/bin/curl --location --silent \
"https://www.alphavantage.co/query?function=GLOBAL_QUOTE&symbol=$SYMBOL&apikey=$APIKEY" \
| ${pkgs.jq}/bin/jq --compact-output \
'.["Global Quote"] |
{
price: .["05. price"] | tonumber,
currency: "'$CURRENCY'",
change_percent: .["10. change percent"] | .[0:-1] | tonumber,
change: .["09. change"] | tonumber,
last_date: .["07. latest trading day"],
}' \
>> ${filePath name}
# old and stupid
#${pkgs.curl}/bin/curl --location --silent \
#"https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=$SYMBOL&interval=5min&apikey=$APIKEY" \
#| ${pkgs.jq}/bin/jq --compact-output \
# '.["Time Series (5min)"] | to_entries | [ .[]
# | { date : .key , value : .value["4. close"], currency: "'$CURRENCY'" } ]
# | sort_by(.date) | reverse | .[0]' \
'';
};
};
in
builtins.listToAttrs (map pullService stocks);
systemd.timers =
let
pullTimer = { name, ... }: {
name = "pull_stock_${name}";
value = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "hourly";
Persistent = "true";
};
};
};
in
builtins.listToAttrs (map pullTimer stocks);
}

View file

@ -1,225 +0,0 @@
{ config, ... }: {
imports = [ ./mpd.nix ];
services.homeAssistantConfig = {
sensor = [{
platform = "time_date";
display_options = [ "time" "date" ];
}];
input_datetime = {
wakeup = {
name = "Arbeitswecker";
has_time = true;
has_date = false;
icon = "mdi:alarm";
};
leave = {
name = "Turn off Time";
has_time = true;
has_date = false;
icon = "mdi:alarm";
};
return = {
name = "Return home";
has_time = true;
has_date = false;
icon = "mdi:alarm";
};
sleep = {
name = "Turn off Time";
has_time = true;
has_date = false;
icon = "mdi:alarm";
};
};
input_boolean = {
wakeup = {
name = "enable";
icon = "mdi:toggle-switch";
};
leave = {
name = "enable";
icon = "mdi:toggle-switch";
};
return = {
name = "enable";
icon = "mdi:toggle-switch";
};
sleep = {
name = "enable";
icon = "mdi:toggle-switch";
};
};
input_select = {
wakeup = {
name = "Playlist";
icon = "mdi:library-music";
options = [ "wakeup" "wakeup1" "wakeup2" ];
};
};
binary_sensor = [
{
platform = "tod";
name = "night";
after = "sunset";
before = "sunrise";
}
{
platform = "tod";
name = "daytime";
after = "sunrise";
before = "sunset";
}
];
group = {
timer_wakeup = {
name = "Arbeits Aufwachen";
entities = [
"input_boolean.wakeup"
"input_datetime.wakeup"
"input_select.wakeup"
];
};
timer_leave = {
name = "Leave Time";
entities = [ "input_boolean.leave" "input_datetime.leave" ];
};
timer_return = {
name = "Nach Hause kommen";
entities = [ "input_boolean.sleep" "input_datetime.sleep" ];
};
timers.entities = [
"group.timer_wakeup"
"group.timer_leave"
"group.timer_return"
"group.timer_sleep"
"binary_sensor.night"
"binary_sensor.daytime"
];
today.entities = [ "sensor.date" "sensor.time" ];
};
automation = [
{
alias = "Wecker Arbeiten";
trigger = {
platform = "template";
value_template =
"{{ states('sensor.time') == (states.input_datetime.wakeup.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}";
};
condition = {
condition = "and";
conditions = [
{
condition = "state";
entity_id = "input_boolean.wakeup";
state = "on";
}
{
condition = "state";
entity_id = "binary_sensor.workday";
state = "on";
}
];
};
action = [
{
alias = "Play wakeup list";
service = "media_player.play_media";
data_template = {
entity_id = "media_player.mpd";
media_content_type = "playlist";
media_content_id = "{{ states('input_select.wakeup') }}";
};
}
{
alias = "turn all on";
service = "script.turn_on";
entity_id = "script.turn_all_on";
}
];
}
{
alias = "Leave Turn all off Timer";
trigger = {
platform = "template";
value_template =
"{{ states('sensor.time') == (states.input_datetime.leave.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}";
};
condition = {
condition = "and";
conditions = [{
condition = "state";
entity_id = "input_boolean.leave";
state = "on";
}];
};
action = [{
alias = "turn all off";
service = "script.turn_on";
entity_id = "script.turn_all_off";
}];
}
{
alias = "Return to Home";
trigger = {
platform = "template";
value_template =
"{{ states('sensor.time') == (states.input_datetime.return.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}";
};
condition = {
condition = "and";
conditions = [{
condition = "state";
entity_id = "input_boolean.return";
state = "on";
}];
};
action = [{
alias = "turn all on";
service = "script.turn_on";
entity_id = "script.turn_all_on";
}];
}
{
alias = "Sleep Turn all off Timer";
trigger = {
platform = "template";
value_template =
"{{ states('sensor.time') == (states.input_datetime.sleep.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}";
};
condition = {
condition = "and";
conditions = [{
condition = "state";
entity_id = "input_boolean.sleep";
state = "on";
}];
};
action = [{
alias = "turn all off";
service = "script.turn_on";
entity_id = "script.turn_all_off";
}];
}
];
};
}

View file

@ -1,18 +0,0 @@
{ config, ... }: {
services.homeAssistantConfig = {
sensor = [
# Weather prediction
{
platform = "zamg";
name = "weather";
}
];
sun = { };
group.today.entities = [ "sensor.weather_temperature" "sun.sun" ];
};
}

View file

@ -1,56 +0,0 @@
{ config, lib, ... }:
let
holiday-range = month: dayA: dayB:
map (day: "${month}-${toString day}")
(map (lib.fixedWidthNumber 2) (lib.range dayA dayB));
privateHolidays = import <secrets/home-assistant/holidays>;
# for example :
# holidays = lib.flatten [
# (holiday-range "2020-06" 7 24)
# (holiday-range "2020-10" 10 16)
#];
holidays = lib.flatten (privateHolidays holiday-range);
in
{
services.homeAssistantConfig = {
binary_sensor = [
{
name = "before_workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
days_offset = 1;
add_holidays = holidays;
}
{
name = "workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
add_holidays = holidays;
}
];
homeassistant.customize = {
"binary_sensor.workday" = {
icon = "mdi:calendar";
friendly_name = "Workday?";
};
"binary_sensor.before_workday" = {
icon = "mdi:calendar";
friendly_name = "Workday Tomorrow?";
};
};
group = {
today.entities =
[ "binary_sensor.before_workday" "binary_sensor.workday" ];
};
};
}

View file

@ -1,33 +0,0 @@
{ pkgs, lib, ... }:
let
# https://www.zigbee2mqtt.io/devices/WSDCGQ11LM.html
allDevices = {
"temperature_sensor_1" = {
id = "0x00158d0002d79220";
groups = [ "living_room" ];
};
"temperature_sensor_2" = {
id = "0x00158d0002d7913d";
groups = [ "living_room" ];
};
};
in
{
services.zigbee2mqtt.settings = lib.mapAttrs'
(name:
{ id, ... }: {
name = id;
value = {
retain = false;
friendly_name = name;
};
})
allDevices;
};
}

View file

@ -33,7 +33,6 @@
#../../system/server
#./hardware-configuration.nix
#./mail-fetcher.nix
#./finance.nix
#./grafana.nix
#./graylog.nix

View file

@ -1,140 +0,0 @@
{ config, lib, pkgs, ... }:
let
host = "gitlab.ingolf-wagner.de";
in
#let
#
# errorPages = pkgs.fetchgit {
# url = "https://git.ingolf-wagner.de/palo/http-errors.git";
# rev = "74b8e4c1d9bbba3db6ad858b888e1867318af1f0";
# sha256 = "0czdzafx4k76q773lyf3vsjm74g1995iz542dhw15kpy5xbivsrg";
# };
#
# error = {
# extraConfig = ''
# error_page 400 /errors/400.html;
# error_page 401 /errors/401.html;
# error_page 402 /errors/402.html;
# error_page 403 /errors/403.html;
# error_page 404 /errors/404.html;
# error_page 405 /errors/405.html;
# error_page 406 /errors/406.html;
# error_page 500 /errors/500.html;
# error_page 501 /errors/501.html;
# error_page 502 /errors/502.html;
# error_page 503 /errors/503.html;
# error_page 504 /errors/504.html;
# '';
# locations."^~ /errors/" = {
# extraConfig = "internal;";
# root = "${errorPages}/";
# };
# };
#
#in
{
#services.nginx = {
# enable = true;
# statusPage = true;
# virtualHosts = {
# "git.${config.networking.hostName}.private" = {
# extraConfig = error.extraConfig;
# locations."/" = {
# proxyPass = "http://${config.networking.hostName}.private:${
# toString config.services.gogs.httpPort
# }";
# };
# };
# };
#};
#services.gogs = {
# enable = true;
# appName = "Kruck GoGs";
# domain = "git.ingolf-wagner.de";
# httpPort = 3000;
# repositoryRoot = "/home/gogs/repositories";
# stateDir = "/home/gogs";
# rootUrl = "https://git.ingolf-wagner.de/";
# extraConfig = ''
# [service]
# DISABLE_REGISTRATION = true
# SHOW_REGISTRATION_BUTTON = false
# [server]
# SSH_DOMAIN = "git.ingolf-wagner.de"
# SSH_PORT = 2222
# START_SSH_SERVER = true
# SSH_LISTEN_PORT = 2222
# [log.file]
# LEVEL = Warn
# [log.console]
# LEVEL = Warn
# [log.sublogger.macaron]
# LEVEL = Warn
# '';
#};
#backup.dirs = [ config.services.gogs.repositoryRoot ];
services.nginx = {
enable = true;
recommendedGzipSettings = true;
recommendedOptimisation = true;
recommendedProxySettings = true;
recommendedTlsSettings = true;
virtualHosts.${host} = {
enableACME = true;
forceSSL = true;
locations."/".proxyPass = "http://unix:/run/gitlab/gitlab-workhorse.socket";
};
};
sops.secrets.gitlab_database_password.owner = config.services.gitlab.user;
sops.secrets.gitlab_initial_root_password.owner = config.services.gitlab.user;
sops.secrets.gitlab_secrets_db.owner = config.services.gitlab.user;
sops.secrets.gitlab_secrets_jws.owner = config.services.gitlab.user;
sops.secrets.gitlab_secrets_otp.owner = config.services.gitlab.user;
sops.secrets.gitlab_secrets_secret.owner = config.services.gitlab.user;
services.postgresql = {
enable = true;
package = pkgs.postgresql_12;
};
services.gitlab = {
enable = true;
host = host;
port = 443;
https = true;
smtp.enable = false;
databasePasswordFile = config.sops.secrets.gitlab_database_password.path;
initialRootPasswordFile = config.sops.secrets.gitlab_initial_root_password.path;
secrets = {
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks
dbFile = config.sops.secrets.gitlab_secrets_db.path;
# openssl genrsa 2048
jwsFile = config.sops.secrets.gitlab_secrets_jws.path;
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks
otpFile = config.sops.secrets.gitlab_secrets_otp.path;
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks
secretFile = config.sops.secrets.gitlab_secrets_secret.path;
};
# smtp?
# gitlab-runner?
};
}

View file

@ -1,52 +0,0 @@
{ pkgs, config, ... }:
let
maxPower = 90;
pool = "eu1.ethermine.org";
toolkit = "opencl";
wallet = "";
rig = config.networking.hostName;
recheckInterval = 2000;
package = pkgs.ethminer;
in
{
systemd.services.ethminer = {
description = "ethminer ethereum mining service";
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
serviceConfig = {
DynamicUser = true;
ExecStartPre = "${package}/bin/.ethminer-wrapped --list-devices";
Restart = "always";
};
script = ''
${package}/bin/.ethminer-wrapped \
--farm-recheck ${toString recheckInterval} \
--report-hashrate \
--${toolkit} \
--pool stratum1+tcp://${wallet}.${rig}@${pool}:4444
'';
};
# https://wiki.archlinux.org/title/GPGPU#Intel
hardware.opengl = {
enable = true;
extraPackages = with pkgs; [ intel-ocl intel-compute-runtime beignet ];
driSupport = true;
driSupport32Bit = true;
};
environment.systemPackages = with pkgs; [
package
# go-ethereum
go-ethereum
# to check opencl config
clinfo
# check temperature
i7z
];
}