forked from roger/k3s-cluster
94 lines
5.8 KiB
YAML
94 lines
5.8 KiB
YAML
# One-shot Job that seeds Hermes' built-in cron schedule on first install.
|
|
# Idempotent: skips job names that already exist.
|
|
#
|
|
# Cron prompts are deliberately written as plain-English instructions (no inline
|
|
# curl commands) to avoid tripping Hermes' threat-pattern scanner, which blocks
|
|
# cron prompts containing curl+auth-header patterns. The exact HA REST API
|
|
# endpoints and examples are documented in the agent's SOUL.md instead.
|
|
#
|
|
# Tailor the schedules/prompts below to your actual Home Assistant entities.
|
|
---
|
|
apiVersion: batch/v1
|
|
kind: Job
|
|
metadata:
|
|
name: hermes-cron-seed
|
|
namespace: home-manager
|
|
labels:
|
|
app: hermes
|
|
annotations:
|
|
argocd.argoproj.io/sync-options: Replace=true
|
|
argocd.argoproj.io/hook: Sync
|
|
argocd.argoproj.io/hook-delete-policy: BeforeHookCreation
|
|
spec:
|
|
backoffLimit: 4
|
|
ttlSecondsAfterFinished: 86400
|
|
template:
|
|
metadata:
|
|
labels:
|
|
app: hermes
|
|
spec:
|
|
serviceAccountName: cron-seeder
|
|
restartPolicy: OnFailure
|
|
containers:
|
|
- name: seed
|
|
image: alpine:3.20
|
|
command: ["sh", "-c"]
|
|
args:
|
|
- |
|
|
set -e
|
|
apk add --no-cache curl
|
|
ARCH=$(uname -m)
|
|
case "$ARCH" in
|
|
x86_64) KARCH=amd64 ;;
|
|
aarch64) KARCH=arm64 ;;
|
|
armv7l) KARCH=arm ;;
|
|
*) echo "unsupported arch: $ARCH" >&2; exit 1 ;;
|
|
esac
|
|
curl -fsSL -o /usr/local/bin/kubectl \
|
|
"https://dl.k8s.io/release/v1.35.0/bin/linux/${KARCH}/kubectl"
|
|
chmod +x /usr/local/bin/kubectl
|
|
|
|
echo "Waiting for hermes pod to be Ready..."
|
|
kubectl -n home-manager wait --for=condition=Ready pod -l app=hermes --timeout=300s || true
|
|
|
|
POD=$(kubectl -n home-manager get pod -l app=hermes -o jsonpath='{.items[0].metadata.name}')
|
|
echo "Using pod: $POD"
|
|
|
|
exists() { kubectl -n home-manager exec "$POD" -- hermes cron list 2>/dev/null | grep -qi " $1 "; }
|
|
|
|
create() {
|
|
name="$1"; schedule="$2"; deliver="$3"; prompt="$4"
|
|
if exists "$name"; then
|
|
echo "cron job '$name' already exists — skipping"
|
|
else
|
|
echo "creating cron job '$name' ..."
|
|
kubectl -n home-manager exec "$POD" -- hermes cron create "$schedule" "$prompt" --name "$name" --deliver "$deliver"
|
|
fi
|
|
}
|
|
|
|
# ---- Watchdog checks (silent unless something is wrong) ----
|
|
create "door-window-check" "every 15m" "discord" \
|
|
"Check the Home Assistant REST API as documented in your SOUL.md. List all door and window sensor entities (binary_sensor.* for doors, windows, contact sensors). If any are open and either no one is home (check zone.home or presence sensors) or it is between 23:00 and 06:00, notify Roger with which sensor is open. If all closed, reply with exactly [SILENT]."
|
|
|
|
create "leak-moisture-check" "every 10m" "discord" \
|
|
"Check the Home Assistant REST API as documented in your SOUL.md. Look for moisture, water leak, or flood sensor entities (binary_sensor.* moisture/water/leak, sensor.* moisture). If any report wet/active, alert Roger immediately with the sensor name and location. If all dry, reply with exactly [SILENT]."
|
|
|
|
create "energy-anomaly" "every 30m" "discord" \
|
|
"Check the Home Assistant REST API as documented in your SOUL.md. Read the current power draw sensor (sensor.* power, sensor.* current_power). If the total power draw is unusually high for the time of day (over 4000 W during the day, or over 800 W when no one is home at night), alert Roger with the reading. Otherwise reply with exactly [SILENT]."
|
|
|
|
create "comfort-check" "every 1h" "discord" \
|
|
"Check the Home Assistant REST API as documented in your SOUL.md. Read indoor temperature and humidity sensors. If a room is outside a comfortable range (below 18C or above 26C, or humidity above 65 percent), you may toggle a fan entity in that room (safe). Do NOT change climate/HVAC settings yourself — if it is uncomfortable, propose a climate change to Roger on Discord and wait. If everything is comfortable, reply with exactly [SILENT]."
|
|
|
|
create "left-on-check" "every 1h" "discord" \
|
|
"Check the Home Assistant REST API as documented in your SOUL.md. If no one is home (zone.home is away or presence sensors all off), find any lights, media players, fans, or non-critical switches that are on. Turn off the safe non-essential ones (lights, media, fans) and report what you turned off. Do NOT touch anything security-critical. If someone is home, or nothing is left on, reply with exactly [SILENT]."
|
|
|
|
# ---- Routines (always delivered) ----
|
|
create "goodnight-routine" "0 23 * * *" "discord" \
|
|
"Run the goodnight routine via the Home Assistant REST API as documented in your SOUL.md. Turn off all non-essential lights and pause media players (safe actions). Then propose — but do NOT execute — locking the doors (lock.*), closing the garage (cover.* garage), and arming the alarm (alarm_control_panel.*). Ask Roger on Discord for confirmation before calling any of those security-critical services. Deliver a short summary of what you turned off and what you are waiting for confirmation on."
|
|
|
|
create "morning-briefing" "0 7 * * *" "discord" \
|
|
"Produce a morning home briefing for Roger using the Home Assistant REST API as documented in your SOUL.md. Include: (1) who is home (zone.home / presence), (2) any lights or media still on, (3) any doors or windows open, (4) indoor temperatures, (5) today's calendar events if a calendar entity exists, (6) overnight energy use if an energy sensor exists, (7) any sensors in an alert/unavailable state. Keep it under 1800 chars. Always deliver (no [SILENT])."
|
|
|
|
echo "Done. Listing all cron jobs:"
|
|
kubectl -n home-manager exec "$POD" -- hermes cron list
|