From 63288dbb4b2bf125098067563a6db29b01104417 Mon Sep 17 00:00:00 2001 From: Claus Dethlefsen Date: Sat, 16 May 2026 10:35:28 +0200 Subject: [PATCH] Gallery: add prune button (behold 100), webhook automation, shell_command --- dashboards/views/06c_indkorsel_snapshots.yaml | 2 +- include/automations/snapshots_indkorsel.yaml | 13 + include/shell_commands/indkorsel.yaml | 1 + python_scripts/generate_indkorsel_gallery.py | 22 +- .../indkorsel/2026-05-16_10-33-52.jpg | Bin 0 -> 35206 bytes www/snapshots/indkorsel/latest.jpg | Bin 33300 -> 35166 bytes www/snapshots/indkorsel_gallery.html | 414 +++++++++--------- www/snapshots/indkorsel_loader.html | 2 +- 8 files changed, 256 insertions(+), 198 deletions(-) create mode 100644 www/snapshots/indkorsel/2026-05-16_10-33-52.jpg diff --git a/dashboards/views/06c_indkorsel_snapshots.yaml b/dashboards/views/06c_indkorsel_snapshots.yaml index 0116c17..05d4a7f 100644 --- a/dashboards/views/06c_indkorsel_snapshots.yaml +++ b/dashboards/views/06c_indkorsel_snapshots.yaml @@ -5,5 +5,5 @@ panel: true cards: - type: iframe - url: /local/snapshots/indkorsel_loader.html?v=20260516130000 + url: /local/snapshots/indkorsel_loader.html?v=20260516103510 aspect_ratio: 100% diff --git a/include/automations/snapshots_indkorsel.yaml b/include/automations/snapshots_indkorsel.yaml index 4f10070..2be5e8a 100644 --- a/include/automations/snapshots_indkorsel.yaml +++ b/include/automations/snapshots_indkorsel.yaml @@ -1,3 +1,16 @@ +- alias: 'Indkorsel: Slet gamle snapshots (behold 100)' + description: Køres via webhook fra galleriet – sletter alle undtagen de 100 nyeste snapshots og regenererer galleriet. + trigger: + - platform: webhook + webhook_id: indkorsel_prune_100 + allowed_methods: [POST] + local_only: true + action: + - action: shell_command.indkorsel_prune_keep_100 + - delay: '00:00:02' + - action: shell_command.indkorsel_generate_gallery + mode: single + - alias: 'Snapshot ved person i indkorsel' description: > Gemmer et tidsstemplet snapshot + opdaterer latest.jpg + regenererer HTML-galleri, diff --git a/include/shell_commands/indkorsel.yaml b/include/shell_commands/indkorsel.yaml index 188f8e4..9d993cd 100644 --- a/include/shell_commands/indkorsel.yaml +++ b/include/shell_commands/indkorsel.yaml @@ -1 +1,2 @@ indkorsel_generate_gallery: "/usr/local/bin/docker exec homeassistant python3 /config/python_scripts/generate_indkorsel_gallery.py" +indkorsel_prune_keep_100: "ls -1 /config/www/snapshots/indkorsel/*.jpg | grep -v '/latest.jpg$' | sort -r | tail -n +101 | xargs rm -f" diff --git a/python_scripts/generate_indkorsel_gallery.py b/python_scripts/generate_indkorsel_gallery.py index 7ef670e..ae1bc6d 100644 --- a/python_scripts/generate_indkorsel_gallery.py +++ b/python_scripts/generate_indkorsel_gallery.py @@ -56,6 +56,9 @@ html = f""" -

Viser {len(files)} person-snapshots – Indkorsel

+

Viser {len(files)} person-snapshots – Indkorsel + +

{"
" + items_html + "
" if files else "
Ingen snapshots endnu.
"}
Nye billeder – tryk for at opdatere