setup-infrastructure
Run when setting up this repo for the first time, configuring HA connection, or verifying the infrastructure still works. Trigger phrases: "set up my HA", "configure connection", "first time setup", "run setup", "reconnect to HA", "my token stopped working", "verify my setup".
dcb · 已有 AI 审核记录
安装与使用
运行命令前先阅读来源与依赖说明。复制命令不会自动安装或执行。
npx skills add dcb/homeassistant-claude-kit --skill setup-infrastructure技能说明
name: setup-infrastructure description: > Run when setting up this repo for the first time, configuring HA connection, or verifying the infrastructure still works. Trigger phrases: "set up my HA", "configure connection", "first time setup", "run setup", "reconnect to HA", "my token stopped working", "verify my setup".
Setup Infrastructure
This skill configures the mechanical layer: HA API connectivity, SSH access, and initial config pull. It is idempotent — run it any time to verify or repair the connection without affecting your actual configuration.
Step 1: Data Consent & Privacy Mode
Only ask once per session. If the user already consented during an earlier invocation of this skill in the same conversation, skip this step entirely.
1a. Data consent — Before reading any Home Assistant data, inform the user:
"This skill will connect to your Home Assistant instance and read your entity registry, automation configs, and documentation files. This data is sent to Anthropic's API as part of this Claude conversation. See PRIVACY.md for full details. Continue? (yes / no)"
If the user says no, stop here and explain they can still use the repo manually.
1b. Privacy mode offer — Only ask if consent was given. Only ask once per session.
First check if privacy mode is already active: test -f .claude/privacy-patterns. If it is,
say "Privacy mode is already enabled" and skip the offer.
If not active, ask:
"Would you like to enable privacy mode? This blocks Claude from directly reading your credentials, personal data files, and runtime state. Setup still works — shell commands handle connectivity. You can toggle this later with
make privacy-on/make privacy-off. Enable privacy mode? (yes / no)"
If yes: cp .claude/privacy-patterns.example .claude/privacy-patterns
If no: proceed without it.
Step 2: Check .env
Check whether .env exists in the repo root:
test -f .env && echo "exists" || echo "missing"
If missing: Tell the user to copy .env.example to .env and fill in:
| Variable | Description | Example |
|---|---|---|
HA_TOKEN | Long-lived access token (HA → Profile → Security → Long-Lived Access Tokens) | eyJ... |
HA_URL | Your HA URL (local or remote) | http://homeassistant.local:8123 |
HA_HOST | SSH hostname, IP, or SSH config alias | homeassistant.local or ha |
SSH_USER | SSH add-on user (usually root) | root |
HA_REMOTE_PATH | Remote config directory (see note below) | /config/ or /homeassistant/ |
VITE_GO2RTC_URL | go2rtc URL (camera streams) — leave empty if not using cameras | http://homeassistant.local:1984 |
HA_REMOTE_PATH note: HA OS with the SSH add-on typically uses
/homeassistant/, while HA Container/Supervised uses/config/. If unsure, the SSH test in Step 4 will auto-detect the correct path.
IMPORTANT: The .env file must NOT use inline comments on value lines (e.g.
HA_HOST=foo # comment). Makefile's include treats everything after = as the value,
including # ... text. Use only full-line comments (lines starting with #).
Wait for the user to fill in .env before continuing.
If exists and privacy mode is OFF: Load the values and proceed.
If exists and privacy mode is ON (test -f .claude/privacy-patterns):
Tell the user: "Privacy mode is active — I can't read .env directly. Please verify it
has HA_TOKEN, HA_URL, HA_HOST, SSH_USER filled in. The next step will validate
your connection." Then proceed to Step 3 — the curl test validates the values work via
source .env (shell sourcing is intentionally not blocked by privacy mode).
Step 3: Validate HA API Token
Test the HA API is reachable:
source .env && curl -sf -H "Authorization: Bearer $HA_TOKEN" "$HA_URL/api/" | python3 -c "import sys,json; d=json.load(sys.stdin); print('HA version:', d.get('version','unknown'))"
- Success: Print the HA version and continue.
- Failure: Show the curl error. Common fixes:
- Token expired → generate a new one at HA → Profile → Security
- Wrong URL → check if HA is running, try
http://vshttps:// - Network unreachable → ensure you're on the same network, or check VPN/Nabu Casa
Step 4: Validate SSH Connectivity
Test SSH access (required for make pull / make push).
IMPORTANT: Always include $SSH_USER@ in the SSH command. The .env has a separate
SSH_USER variable (usually root) — do NOT connect as the local macOS/Linux user.
source .env && ssh -o ConnectTimeout=5 -o BatchMode=yes "$SSH_USER@$HA_HOST" "echo ok" 2>&1
- Success (
ok): Continue to auto-detectHA_REMOTE_PATH. Permission denied (publickey): SSH key not authorized. Run:
Or manually addsource .env && ssh-copy-id "$SSH_USER@$HA_HOST"~/.ssh/id_rsa.pub(orid_ed25519.pub) to the SSH add-on's authorized keys in HA Settings → Add-ons → SSH & Web Terminal → Configuration.Connection refused/No route to host: SSH add-on not running or wrong hostname. Check HA Settings → Add-ons → SSH & Web Terminal → Start.
Auto-detect HA_REMOTE_PATH
After SSH is confirmed working, verify that HA_REMOTE_PATH points to the correct directory:
source .env && ssh "$SSH_USER@$HA_HOST" "test -f ${HA_REMOTE_PATH:-/config/}configuration.yaml && echo 'PATH_OK' || echo 'PATH_WRONG'"
If PATH_WRONG: Try the HA OS default path:
source .env && ssh "$SSH_USER@$HA_HOST" "test -f /homeassistant/configuration.yaml && echo '/homeassistant/' || (test -f /config/configuration.yaml && echo '/config/' || echo 'NOT_FOUND')"
Update HA_REMOTE_PATH in .env with the correct path before proceeding. If NOT_FOUND,
ask the user to verify their HA configuration directory location.
Step 5: Generate Derived .env Files
Once HA API + SSH are confirmed working, generate the derived config files:
**`dashboard/.env.
阅读完整来源 ↗