{ 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"; }; }; }