2020-04-08 16:43:09 +02:00
|
|
|
{ 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";
|
2020-04-17 20:59:12 +02:00
|
|
|
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}
|
|
|
|
'';
|
2020-04-08 16:43:09 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.timers."${name}" = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
timerConfig = {
|
|
|
|
OnCalendar = "hourly";
|
|
|
|
Persistent = "true";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|