virtual-insanity
← 리포트 목록

HA Phase 2 준비 — HA_URL/TOKEN rotate 스크립트

2026-04-24 ha [home-assistant, ha, phase2, rotate, smart-home]

Executive Summary

  • HA 복구 후 바로 쓸 수 있게 endpoint/token 회전 스크립트 2개를 준비했다.
  • 실제 교체는 하지 않았다. --list, --dry-run, 엔티티 --list-only만 검증했다.
  • 현재 HA localhost:8123은 아직 안 떠 있어 /api/config 검증은 예상대로 connection refused다.

생성한 스크립트

파일 역할
~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py HA_URL/token을 env, smart-home scripts, LaunchAgent plist, Hermes cron command에 일괄 반영
~/.hermes/workspace/scripts/admin/check_entities.py smart-home 5개 계열 잡이 쓰는 HA entity_id를 추출하고 /api/states에 존재하는지 확인

둘 다 py_compile 통과.

rotate_ha_endpoint.py 기능

지원 옵션:

--list                         영향 파일만 출력
--new-url http://localhost:8123 새 HA base URL
--new-token-stdin              stdin에서 새 토큰 입력, 출력 노출 없음
--token-file <path>            파일에서 토큰 입력
--dry-run                      미적용 preview. 기본값
--apply                        실제 수정
--verify                       /api/config 검증
--allow-verify-fail            HA 미기동 상태에서도 종료코드 0 허용

적용 범위:

  • .env
  • ~/.hermes/.env
  • ~/.openclaw/.env
  • ~/.hermes/workspace/.env 존재 시
  • token file
  • ~/.hermes/secrets/ha_token
  • ~/.openclaw/secrets/ha_token
  • smart-home scripts
  • auto_cold_alert.sh
  • auto_rain_alert.sh
  • auto_late_lights.sh
  • auto_door_alert.sh
  • routine_morning.sh, routine_bedtime.sh
  • tts_morning.sh, tts_bedtime.sh, tts_home.sh, tts_briefing.sh, tts_outing.sh
  • smart_home.py
  • monitor_hmig_5_jobs.py
  • LaunchAgent 5개
  • com.openclaw.cold-alert.plist
  • com.openclaw.rain-alert.plist
  • com.openclaw.late-lights.plist
  • com.openclaw.door-alert.plist
  • com.openclaw.morning-routine.plist
  • Hermes cron 3개
  • hmig-cold-alert
  • hmig-rain-alert
  • hmig-late-lights

백업 규칙:

.bak-ha-rotate-YYYYMMDD_HHMMSS

주의: 실제 --apply 후 LaunchAgent 재bootstrap은 별도 단계에서 해야 한다.

dry-run 검증 결과

영향 파일 목록

python3 ~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py --list

결과:

  • impacted_files: 21
  • 포함: .env 2개, Hermes jobs.json, smart-home scripts, monitor_hmig_5_jobs.py, LaunchAgent 5개

교체 preview

python3 ~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py \
  --new-url http://localhost:8123 \
  --token-file ~/.hermes/secrets/ha_token \
  --dry-run --verify --allow-verify-fail

결과:

  • mode: DRY_RUN
  • changed_files: 21
  • token: provided로만 표기, 값 미노출
  • verify: 실패 예상값
{"ok": false, "status": 0, "error": "URLError: <urlopen error [Errno 61] Connection refused>"}

check_entities.py 기능

지원 옵션:

--url http://localhost:8123
--token-file ~/.hermes/secrets/ha_token
--new-token-stdin
--list-only                  HA 호출 없이 entity 목록만 출력
--file <path>                특정 파일 추가/대체 스캔

검출된 entity_id: 17개

binary_sensor.door_sensor_door
cover.keoteun_curtain
light.jeoncedeung_backlight
scene.eeokeon_ggeo
scene.eeokeon_kyeo
sensor.door_sensor_battery
switch.babjomyeong
switch.bamjomyeong_socket_1
switch.fingerbot_switch_1
switch.hwajangsil_switch_1
switch.hwajangsil_switch_2
switch.jeoncedeung_switch
switch.jeoncedeung_switch_1
switch.jeoncedeung_switch_2
switch.jeoncedeung_switch_3
switch.jeoncedeung_switch_4
weather.forecast_jib

HA 미기동 상태에서 실제 조회:

HA_CHECK_FAILED URLError: <urlopen error [Errno 61] Connection refused>

Phase 2 실제 적용 절차

HA가 http://localhost:8123에서 살아난 뒤:

# 1) 영향 재확인
python3 ~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py --list

# 2) 실제 적용. 토큰은 stdin 권장
cat /path/to/new_ha_token.txt | python3 ~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py \
  --new-url http://localhost:8123 \
  --new-token-stdin \
  --apply --verify

# 3) entity_id 존재 확인
python3 ~/.hermes/workspace/scripts/admin/check_entities.py \
  --url http://localhost:8123 \
  --token-file ~/.hermes/secrets/ha_token

LaunchAgent 재로드는 적용 후 별도:

launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.openclaw.door-alert.plist
launchctl kickstart -k gui/$(id -u)/com.openclaw.cold-alert
launchctl kickstart -k gui/$(id -u)/com.openclaw.rain-alert
launchctl kickstart -k gui/$(id -u)/com.openclaw.late-lights

door-alert는 현재 unload 격리 상태라 bootstrap이 필요하다. 나머지는 상태에 따라 kickstart 또는 다음 schedule 대기.

이번 작업에서 실제 변경한 것

실제 HA 설정 파일/토큰/cron/plist는 건드리지 않았다.

변경한 신규/수정 파일:

  • 신규: ~/.hermes/workspace/scripts/admin/rotate_ha_endpoint.py
  • 신규: ~/.hermes/workspace/scripts/admin/check_entities.py

자체평가

기준 점수
정확성 4.4/5
완성도 4.5/5
검증 4.5/5
최소 변경 4.7/5

종합: 4.5/5

Remaining Risks: - “5개 잡”의 정확한 범위는 smart-home LaunchAgent 5개 기준으로 잡았다. Hermes cron에는 현재 cold/rain/late-lights 3개만 있어 cron 적용은 3개다. - HA가 아직 죽어 있어 /api/config 및 entity 존재 검증은 실패가 정상이다.