diff --git a/hosts/server/configuration.nix b/hosts/server/configuration.nix index e5ef7f83..b82800bb 100644 --- a/hosts/server/configuration.nix +++ b/hosts/server/configuration.nix @@ -25,6 +25,7 @@ ../../server-modules/signal-cli-rest-api.nix ../../server-modules/home-assistant ../../server-modules/miniflux.nix + ../../server-modules/uptime-kuma.nix # You should let those lines as is ./hardware-configuration.nix diff --git a/server-modules/home-assistant/default.nix b/server-modules/home-assistant/default.nix index ceee3ce4..f003814d 100644 --- a/server-modules/home-assistant/default.nix +++ b/server-modules/home-assistant/default.nix @@ -53,6 +53,7 @@ in { "meteo_france" "remote_calendar" "systemmonitor" + "uptime_kuma" ]; customComponents = plugins.customComponents; customLovelaceModules = plugins.customLovelaceModules; @@ -65,7 +66,11 @@ in { scene = "!include scenes.yaml"; automation = "!include automations.yaml"; script = "!include scripts.yaml"; - frontend.themes = nixyTheme; + frontend = { + themes = nixyTheme; + # Load card-mod early so it can style every card + extra_module_url = ["/local/nixos-lovelace-modules/card-mod.js"]; + }; # Timestamp of the last motion detection (trigger-based, survives restarts) template = map (room: { @@ -86,7 +91,61 @@ in { } ]; }) - motionRooms; + motionRooms + ++ [ + # Uptime Kuma monitors that are not up (down, pending or maintenance) + { + sensor = [ + { + name = "Websites not up"; + unique_id = "websites_not_up"; + icon = "mdi:web-off"; + state = '' + {{ integration_entities('uptime_kuma') + | select('match', 'sensor\.') + | select('is_state', ['down', 'pending', 'maintenance']) + | list | count }} + ''; + attributes.sites = '' + {{ integration_entities('uptime_kuma') + | select('match', 'sensor\.') + | select('is_state', ['down', 'pending', 'maintenance']) + | map('device_attr', 'name') + | list }} + ''; + } + ]; + } + # Battery sensors below 15% + { + sensor = [ + { + name = "Batteries to replace"; + unique_id = "batteries_to_replace"; + icon = "mdi:battery-alert-variant-outline"; + state = '' + {{ states.sensor + | selectattr('attributes.device_class', 'defined') + | selectattr('attributes.device_class', 'eq', 'battery') + | map(attribute='state') + | select('is_number') | map('float') + | select('lt', 15) + | list | count }} + ''; + attributes.devices = '' + {% set ns = namespace(low=[]) %} + {% for s in states.sensor + | selectattr('attributes.device_class', 'defined') + | selectattr('attributes.device_class', 'eq', 'battery') + if is_number(s.state) and s.state | float < 15 %} + {% set ns.low = ns.low + [s.name ~ ' (' ~ s.state | int ~ '%)'] %} + {% endfor %} + {{ ns.low }} + ''; + } + ]; + } + ]; alarm_control_panel = [ { platform = "manual"; diff --git a/server-modules/home-assistant/plugins.nix b/server-modules/home-assistant/plugins.nix index 4f321c81..6a57f321 100644 --- a/server-modules/home-assistant/plugins.nix +++ b/server-modules/home-assistant/plugins.nix @@ -64,5 +64,6 @@ in { pkgs.home-assistant-custom-lovelace-modules.bubble-card pkgs.home-assistant-custom-lovelace-modules.auto-entities pkgs.home-assistant-custom-lovelace-modules.mushroom + pkgs.home-assistant-custom-lovelace-modules.card-mod ]; } diff --git a/server-modules/uptime-kuma.nix b/server-modules/uptime-kuma.nix new file mode 100644 index 00000000..6c224452 --- /dev/null +++ b/server-modules/uptime-kuma.nix @@ -0,0 +1,29 @@ +{ + config, + lib, + ... +}: let + inherit (import ./mk-container.nix {inherit lib config;}) mkContainer; +in { + imports = [ + (mkContainer { + name = "uptime-kuma"; + hostIp = "10.233.13.1"; + containerIp = "10.233.13.2"; + internet = true; + nixosConfig = {...}: { + services.uptime-kuma = { + enable = true; + settings = { + HOST = "0.0.0.0"; + PORT = "3001"; + }; + }; + networking.firewall.allowedTCPPorts = [3001]; + system.stateVersion = "24.05"; + }; + }) + ]; + + services.cloudflared.tunnels."${config.var.tunnelId}".ingress."uptime.${config.var.domain}" = "http://10.233.13.2:3001"; +}