pepe: home-assistant cleanup

This commit is contained in:
Ingolf Wagner 2020-04-12 13:36:15 +02:00
parent 2dc5647f87
commit 000ee7974b
No known key found for this signature in database
GPG key ID: 76BF5F1928B9618B
6 changed files with 68 additions and 178 deletions

View file

@ -4,13 +4,13 @@ in {
imports = [
#./home-assistant/chaospott.nix
#./home-assistant/holiday.nix
#./home-assistant/mpd.nix
./home-assistant/sonoff.nix
./home-assistant/mqtt.nix
#./home-assistant/dayOfWeek.nix
#./home-assistant/timer.nix
./home-assistant/kodi.nix
./home-assistant/mqtt.nix
./home-assistant/sonoff.nix
./home-assistant/weather.nix
./home-assistant/workday.nix
./home-assistant/zigbee2mqtt.nix
];
@ -82,6 +82,7 @@ in {
# entity_id = "group.kitchen";
# };
#}
];
group = {
@ -116,7 +117,6 @@ in {
name = "Not Used";
view = false;
};
view_rooms = {
name = "Räume";
view = true;
@ -128,7 +128,6 @@ in {
"group.tv"
];
};
view_overview = {
name = "Übersicht";
view = true;
@ -143,33 +142,6 @@ in {
script.turn_all_on.sequence = [ ];
sensor = [
# Weather prediction
{
platform = "zamg";
name = "Weather";
}
];
# todo: add holidays package to home-assiatnt
binary_sensor = [
{
name = "before_workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
days_offset = 1;
}
{
name = "workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
}
];
};
services.home-assistant = {

View file

@ -1,52 +0,0 @@
{ config, ... }:
let
folderPath = config.services.home-assistant.configDir;
filePath = "${folderPath}/dayOfWeek.json";
in {
services.homeAssistantConfig = {
sensor = [{
platform = "file";
name = "day_of_week";
file_path = filePath;
value_template = "{{ value_json.dayOfWeek }}";
}];
homeassistant = {
whitelist_external_dirs = [ folderPath ];
customize."sensor.day_of_week" = {
icon = "mdi:calendar-today";
friendly_name = "Wochen Tag";
};
};
group = { overview.entities = [ "sensor.day_of_week" ]; };
};
systemd.services.dayOfWeek = {
enable = true;
before = [ "home-assistant.service" ];
wantedBy = [ "home-assistant.service" ];
serviceConfig = {
User = "hass";
Type = "oneshot";
};
description = "set day of wek for homeassistant";
script = # sh
''
date +'{"dayOfWeek":"%A"}' >> ${filePath}
'';
};
systemd.timers.dayOfWeek = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "00:01:00";
Persistent = "true";
};
};
}

View file

@ -1,92 +0,0 @@
{ config, pkgs, ... }:
let
state = "NW"; # NRW
# state = "BE"; # Berlin
name = "holiday";
folderPath = config.services.home-assistant.configDir;
filePath = "${folderPath}/${name}.json";
in {
services.homeAssistantConfig = {
# todo : use the python tool
sensor = [
{
platform = "file";
name = "${name}_date";
file_path = filePath;
value_template = "{{ value_json.date }}";
}
{
platform = "file";
name = "${name}_name";
file_path = filePath;
value_template = "{{ value_json.name }}";
}
];
homeassistant = {
whitelist_external_dirs = [ folderPath ];
customize = {
"sensor.${name}_date" = {
icon = "mdi:calendar";
friendly_name = "Nächster Feiertag";
};
"sensor.${name}_name" = {
icon = "mdi:calendar";
friendly_name = "Nächster Feiertag";
};
};
};
group = {
holidays = {
name = "Feiertage";
view = false;
control = "hidden";
entities = [ "sensor.${name}_date" "sensor.${name}_name" ];
};
view_overview.entities = [ "group.holidays" ];
};
};
systemd.services."${name}" = {
enable = true;
before = [ "home-assistant.service" ];
wantedBy = [ "home-assistant.service" ];
serviceConfig = {
User = "hass";
Type = "oneshot";
};
description = "set ${name} for homeassistant";
script = # sh
''
${pkgs.curl}/bin/curl \
-Ls "https://feiertage-api.de/api/?jahr=$( date +%Y )&nur_land=${state}" \
| ${pkgs.jq}/bin/jq --compact-output '
map_values( .datum ) |
to_entries |
map( { date: .value, name : .key } ) |
sort_by( .date ) |
map(select ( .date >= "'`date +%Y-%m-%d`'" )) |
.[0]' \
>> ${filePath}
'';
};
systemd.timers."${name}" = {
enable = true;
wantedBy = [ "multi-user.target" ];
timerConfig = {
OnCalendar = "daily";
Persistent = "true";
};
};
}

View file

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

View file

@ -0,0 +1,45 @@
{ config, ... }: {
services.homeAssistantConfig = {
# todo: add holidays package to home-assiatnt
binary_sensor = [
{
name = "before_workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
days_offset = 1;
}
{
name = "workday";
platform = "workday";
country = "DE";
province = "NW";
workdays = [ "mon" "tue" "wed" "thu" "fri" ];
}
];
homeassistant.customize = {
"binary_sensor.workday" = {
icon = "mdi:calendar";
friendly_name = "Today?";
};
"binary_sensor.before_workday" = {
icon = "mdi:calendar";
friendly_name = "Tomorrow?";
};
};
group = {
is_workday = {
name = "Workday";
control = "hidden";
entities = [ "binary_sensor.before_workday" "binary_sensor.workday" ];
};
view_overview.entities = [ "group.is_workday" ];
};
};
}

View file

@ -110,7 +110,8 @@ in {
};
sputnik = {
realAddress = [
# "195.201.134.247:443"
"195.201.134.247"
"195.201.134.247:443"
"static.247.134.201.195.clients.your-server.de"
"static.247.134.201.195.clients.your-server.de:443"
];