2019-10-24 02:20:38 +02:00
|
|
|
{ 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 = [
|
2019-12-20 05:54:26 +01:00
|
|
|
{
|
|
|
|
platform = "file";
|
2019-10-24 02:20:38 +02:00
|
|
|
name = "${name}_date";
|
|
|
|
file_path = filePath;
|
|
|
|
value_template = "{{ value_json.date }}";
|
|
|
|
}
|
2019-12-20 05:54:26 +01:00
|
|
|
{
|
|
|
|
platform = "file";
|
2019-10-24 02:20:38 +02:00
|
|
|
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";
|
2019-12-20 05:54:26 +01:00
|
|
|
entities = [ "sensor.${name}_date" "sensor.${name}_name" ];
|
2019-10-24 02:20:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
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";
|
2019-12-20 05:54:26 +01:00
|
|
|
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}
|
|
|
|
'';
|
2019-10-24 02:20:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers."${name}" = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "daily";
|
|
|
|
Persistent = "true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|