virtual-insanity
← 리포트 목록

door-alert HA API timeout 및 sensors 알림 로직 검증

2026-04-15 fix [phase17-followup, smart-home, launchd, home-assistant, door-alert]

결론

  • door-alert의 반복 timeout은 Hermes 경로 오류가 아니라 Home Assistant endpoint 도달 실패다.
  • 현재 Hermes door-alert는 60초 주기로 launchd에 등록되어 있고 실행은 된다.
  • 호출 대상은 원격 HA URL https://srv1321629.hstgr.cloud이며, local :8123 HA는 이 Mac에서 확인되지 않았다.
  • HA token 파일은 존재하고 OpenClaw 원본과 동일하다. 다만 API 도달 실패 때문에 token 유효성까지는 검증 불가.
  • 스크립트는 수정했다: HA_URL/HA_TIMEOUT env override 지원, timeout 10s → 기본 5s, 에러를 HA_UNREACHABLE로 구조화, Telegram token 누락 가드 추가.
  • 수동 실행 + kickstart 결과, 에러는 사라지지 않았다. 다만 원인이 명확히 HA_UNREACHABLE로 드러나고 5초 내 실패한다.

1. door-alert 스크립트 분석

대상:

~/.hermes/skills/smart-home/scripts/auto_door_alert.sh

현재 호출 구조:

LaunchAgent: com.openclaw.door-alert
Schedule: StartInterval 60
Script: /Users/ron/.hermes/skills/smart-home/scripts/auto_door_alert.sh
stdout: /Users/ron/.hermes/logs/door-alert.log
stderr: /Users/ron/.hermes/logs/door-alert.err.log

현재 HA endpoint:

HA_URL = os.environ.get("HA_URL", "https://srv1321629.hstgr.cloud")

HA API 호출:

목적 endpoint
문 상태 /api/states/binary_sensor.door_sensor_door
외출/귀가 판정용 거실등 /api/states/switch.jeoncedeung_switch_1

인증:

~/.hermes/secrets/ha_token
Authorization: Bearer <token>

확인 결과:

/Users/ron/.hermes/secrets/ha_token exists size=183
/Users/ron/.openclaw/secrets/ha_token exists size=183
hermes/openclaw token same=yes

수정 전 timeout:

urllib.request.urlopen(..., timeout=10)

수정 후 timeout:

HA_TIMEOUT = float(os.environ.get("HA_TIMEOUT", "5"))
urllib.request.urlopen(..., timeout=HA_TIMEOUT)

2. 수정 내역

백업:

~/.hermes/skills/smart-home/scripts/auto_door_alert.sh.bak-260415-door-timeout

수정 파일:

~/.hermes/skills/smart-home/scripts/auto_door_alert.sh
~/Library/LaunchAgents/com.openclaw.{cold-alert,door-alert,late-lights,rain-alert}.plist
~/.hermes/skills/smart-home/scripts/auto_cold_alert.sh
~/.hermes/skills/smart-home/scripts/auto_rain_alert.sh
~/.hermes/skills/smart-home/scripts/auto_late_lights.sh

핵심 변경:

  1. door-alertHA_URL, HA_TIMEOUT 환경변수를 읽도록 변경.
  2. 기본 timeout을 5초로 축소해 60초 주기에서 10초씩 밀리는 현상 완화.
  3. HA 실패 로그를 아래 형태로 구조화.
ERROR:HA_UNREACHABLE url=<HA_URL> timeout=5s detail=<...>
  1. Telegram token 누락 시 명확히 missing_telegram_bot_token으로 실패하도록 가드 추가.
  2. cold/rain/late-lights도 같은 HA_URL/HA_TIMEOUT 환경변수 패턴으로 맞춤.
  3. 4개 plist에 환경변수 추가.
HA_URL=https://srv1321629.hstgr.cloud
HA_TIMEOUT=5

검증:

/Users/ron/Library/LaunchAgents/com.openclaw.cold-alert.plist: OK
/Users/ron/Library/LaunchAgents/com.openclaw.door-alert.plist: OK
/Users/ron/Library/LaunchAgents/com.openclaw.late-lights.plist: OK
/Users/ron/Library/LaunchAgents/com.openclaw.rain-alert.plist: OK
OK auto_cold_alert.sh
OK auto_rain_alert.sh
OK auto_late_lights.sh

3. HA 연결 상태 확인

curl probe 원문:

=== curl HA probes 2026-04-15 ===
--- https://srv1321629.hstgr.cloud/api/
curl: (6) Could not resolve host: srv1321629.hstgr.cloud

--- https://srv1321629.hstgr.cloud/api/states/binary_sensor.door_sensor_door
curl: (6) Could not resolve host: srv1321629.hstgr.cloud

--- http://homeassistant.local:8123/api/
curl: (6) Could not resolve host: homeassistant.local

--- http://127.0.0.1:8123/api/
curl: (7) Failed to connect to 127.0.0.1 port 8123 after 0 ms: Couldn't connect to server

--- http://192.168.0.1:8123/api/
curl: (7) Failed to connect to 192.168.0.1 port 8123 after 0 ms: Couldn't connect to server

--- http://192.168.0.8:8123/api/
curl: (7) Failed to connect to 192.168.0.8 port 8123 after 0 ms: Couldn't connect to server

--- http://192.168.0.53:8123/api/
curl: (7) Failed to connect to 192.168.0.53 port 8123 after 0 ms: Couldn't connect to server

추가 진단:

scutil --dns -> No DNS configuration available
srv1321629.hstgr.cloud -> gaierror [Errno 8]
homeassistant.local -> gaierror [Errno 8]
ping 192.168.0.1 / 192.168.0.8 / 192.168.0.53 -> Operation not permitted

ARP에서 보이는 주요 IP:

192.168.0.1  router 후보
192.168.0.8  Google Home 후보
192.168.0.53 현재 Mac(en1)

판단: - 현재 Codex shell에서는 DNS/ICMP/TCP 일부가 제한되어 직접 확정은 어렵다. - launchd door-alert 로그는 DNS 에러가 아니라 timeout으로 찍히므로 launchd 컨텍스트에서는 resolver/route가 다를 가능성이 있다. - 그러나 launchd에서도 원격 HA endpoint가 5초 내 응답하지 않는 것은 확인됐다.

4. 기존 OpenClaw 경로 비교

OpenClaw 원본도 같은 원격 HA URL을 사용했다.

~/.openclaw/skills/smart-home/scripts/auto_door_alert.sh
HA_URL = "https://srv1321629.hstgr.cloud"

과거 OpenClaw 로그에는 정상 상태도 있었다.

[22:47:03] Door: CLOSED
[22:48:03] Door: CLOSED
...
[23:06:12] Door: CLOSED

하지만 이후 같은 원본 경로에서도 timeout이 반복됐다.

[15:11:02] Door: ERROR:<urlopen error timed out>
...
[16:08:19] Door: ERROR:<urlopen error timed out>

따라서 이번 문제는 Hermes rewrite 자체보다는, 기존 원격 HA endpoint 또는 네트워크/DNS 상태가 불안정한 쪽에 가깝다.

5. 다른 센서 로그 분석

현재 Hermes 로그:

cold-alert.log      [SKIP] 기온 정상 범위
cold-alert.err.log  ERROR:<urlopen error timed out>
late-lights.log     [SKIP] 조명 모두 꺼져있음
late-lights.err.log 0B
rain-alert.log      [SKIP] 비/눈 예보 없음
rain-alert.err.log  ERROR:<urlopen error timed out>

해석: - late-lights: 마지막 실행은 조명 모두 꺼짐으로 skip. 에러 없음. - cold-alert, rain-alert: stderr에 HA timeout이 있었는데 stdout은 skip으로 남아 오해 소지가 있었다. 그래서 에러는 stderr에 명시하고, HA_URL/HA_TIMEOUT 환경변수를 읽도록 수정했다. - cold/rain은 HA API 실패 시에도 실제 TTS/Telegram을 보내지 않으므로 오탐 알림은 없다.

6. 알림 조건 + 발송 경로

센서 실제 알림 조건 발송/동작 경로 Telegram/sector
cold-alert 오늘 최저기온 < 0℃ 또는 최고기온 >= 33℃ Google Home TTS, 영하 시 온수매트 자동 ON Telegram 없음, sector 없음
door-alert 문 상태 on이 5분 이상 지속 Telegram Harry DM 직접 API send_dm/send_sector 아님. 직접 sendMessage to 492860021
door-alert routine open -> closed 전환 + 거실등 상태 외출/귀가 루틴, TTS, 조명/온수매트/커튼 제어 Telegram 없음
late-lights 23:00에 조명 1개 이상 ON TTS 후 조명 OFF, 온수매트 ON, 커튼 닫기 Telegram 없음, sector 없음
rain-alert 오늘 예보 rainy/pouring 또는 강수량 >0, 또는 snowy Google Home TTS Telegram 없음, sector 없음

주의: - user context의 cold < 10℃, late-lights 00:00 이후는 현재 코드와 다르다. - 실제 코드는 cold < 0℃, late-lights 23:00이다.

7. 라이브 재실행 결과

수동 실행:

[16:38:15] Door: ERROR:HA_UNREACHABLE url=https://srv1321629.hstgr.cloud timeout=5s detail=<urlopen error [Errno 8] nodename nor servname provided, or not known>

launchd kickstart:

launchctl kickstart -k gui/501/com.openclaw.door-alert

이후 로그:

[16:38:20] Door: ERROR:HA_UNREACHABLE url=https://srv1321629.hstgr.cloud timeout=5s detail=<urlopen error timed out>
[16:39:26] Door: ERROR:HA_UNREACHABLE url=https://srv1321629.hstgr.cloud timeout=5s detail=<urlopen error timed out>

판정: - 반복 timeout 자체는 사라지지 않았다. - 단, timeout이 10초에서 5초로 줄고, 로그가 구조화되어 원인 추적이 쉬워졌다. - HA endpoint가 살아나거나 HA_URL을 reachable local URL로 바꾸면 같은 스크립트가 바로 정상화될 구조다.

8. 권고

  1. Home Assistant의 실제 reachable URL을 확정해야 한다.
  2. 현재 기본값: https://srv1321629.hstgr.cloud
  3. local 후보 127.0.0.1:8123, homeassistant.local:8123, 192.168.0.1:8123, 192.168.0.8:8123, 192.168.0.53:8123는 실패.
  4. HA가 로컬 네트워크 어딘가에 있으면, ~/Library/LaunchAgents/com.openclaw.*.plistHA_URL만 local URL로 바꾸면 된다.
  5. DNS 상태도 별도 확인 필요.
  6. 이 컨텍스트에서는 scutil --dnsNo DNS configuration available로 나옴.
  7. door-alert는 60초 주기이므로 timeout은 5초 이하 유지 권장.
  8. door open 알림은 직접 Telegram DM이다. 향후 중앙 정책에 맞추려면 shared.telegram.send_dm(..., level="critical")로 통일할 수 있지만, 이번 작업에서는 오탐 방지를 위해 발송 경로를 바꾸지 않았다.

변경 파일

~/.hermes/skills/smart-home/scripts/auto_door_alert.sh
~/.hermes/skills/smart-home/scripts/auto_cold_alert.sh
~/.hermes/skills/smart-home/scripts/auto_rain_alert.sh
~/.hermes/skills/smart-home/scripts/auto_late_lights.sh
~/Library/LaunchAgents/com.openclaw.cold-alert.plist
~/Library/LaunchAgents/com.openclaw.door-alert.plist
~/Library/LaunchAgents/com.openclaw.late-lights.plist
~/Library/LaunchAgents/com.openclaw.rain-alert.plist

자체평가

  • 정확성: 4.1/5 — endpoint, token, timeout, 알림 조건, 발송 경로를 확인했고 최소 수정했다.
  • 완성도: 3.8/5 — HA 자체 도달 실패는 남아 있어 door 정상 CLOSED까지는 확인 못 했다.
  • 검증: 4.0/5 — 수동 실행, kickstart, 로그 확인, plist lint, bash syntax 확인 완료.
  • 최소 변경: 4.4/5 — HA 시스템은 건드리지 않고 Hermes scripts/plist만 수정.

종합: 4.1/5