Custom component under integrations/home-assistant/: registers the
/api/webhook/ai_agent webhook, renders notify events with the per-type
channel map, and renders asks on a dedicated 'Claude · Ask' channel with
the '. .. .._' vibration pattern as persistent tappable notifications —
the tapped answer is POSTed back to /api/ask/{id}/answer and the
notification cleared. install.sh copies it into the HA config and wires
configuration.yaml.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
52 lines
1.9 KiB
Bash
Executable File
52 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Install (or update) the ai_agent custom integration into the homelab's
|
|
# Home Assistant config, wire its configuration.yaml block, and optionally
|
|
# restart HA to load it.
|
|
#
|
|
# Usage:
|
|
# ./install.sh # copy component + ensure config block
|
|
# ./install.sh --restart # …then docker restart home-assistant
|
|
#
|
|
# Idempotent: re-running just refreshes the component files.
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
REPO_ROOT="$(cd "$SCRIPT_DIR/../../../.." && pwd)"
|
|
HA_CONFIG="${HA_CONFIG:-$REPO_ROOT/services/home-assistant/config}"
|
|
RESTART=0
|
|
[[ "${1:-}" == "--restart" ]] && RESTART=1
|
|
|
|
[[ -d "$HA_CONFIG" ]] || { echo "error: HA config dir not found: $HA_CONFIG" >&2; exit 1; }
|
|
|
|
mkdir -p "$HA_CONFIG/custom_components"
|
|
rm -rf "$HA_CONFIG/custom_components/ai_agent"
|
|
cp -r "$SCRIPT_DIR/custom_components/ai_agent" "$HA_CONFIG/custom_components/ai_agent"
|
|
echo "installed custom_components/ai_agent -> $HA_CONFIG/custom_components/"
|
|
|
|
# Ensure the ai_agent: block exists in configuration.yaml (append if missing).
|
|
CONF="$HA_CONFIG/configuration.yaml"
|
|
if ! grep -qE '^ai_agent:' "$CONF"; then
|
|
cat >>"$CONF" <<'EOF'
|
|
|
|
# AI Agent notifications: webhook target for the ai-agent backend's notify hub
|
|
# (services/ai-agent/integrations/home-assistant). Receives notify/ask events
|
|
# on /api/webhook/ai_agent and pushes them to the phone; ask answers are
|
|
# POSTed back to the ai-agent backend on the host port.
|
|
ai_agent:
|
|
webhook_id: ai_agent
|
|
notify_target: mobile_app_pixel_9
|
|
callback_url: http://127.0.0.1:8096
|
|
EOF
|
|
echo "appended ai_agent: block to configuration.yaml"
|
|
else
|
|
echo "configuration.yaml already has an ai_agent: block — left untouched"
|
|
fi
|
|
|
|
if [[ "$RESTART" == "1" ]]; then
|
|
echo "restarting home-assistant…"
|
|
docker restart home-assistant
|
|
echo "done — check the log: docker logs home-assistant 2>&1 | grep ai_agent"
|
|
else
|
|
echo "now restart HA to load it: docker restart home-assistant"
|
|
fi
|