본문 바로가기
스마트폰 (Mobile)

Windows PC를 HASS.Agent 통해 Home Assistant 센서 등록 및 제어

by 날으는물고기 2025. 8. 10.

Windows PC를 HASS.Agent 통해 Home Assistant 센서 등록 및 제어

728x90

HASS.Agent는 Windows PC를 Home Assistant 생태계에 완벽하게 통합하는 강력한 도구입니다.

핵심 기능

  • 🎵 미디어 플레이어: PC 음악/동영상 제어
  • 📊 시스템 센서: CPU, 메모리, 디스크 사용량 모니터링
  • 🔔 알림 시스템: Home Assistant → PC 알림 전송
  • 🎮 원격 제어: 앱 실행, PC 종료/재시작, 화면 잠금
  • 🔊 TTS: 텍스트를 음성으로 PC에서 재생

시스템 구성도

1️⃣ Home Assistant 준비

MQTT 브로커 설치 (Mosquitto)

설정 → 애드온 → 애드온 스토어 → Mosquitto broker

# Mosquitto 설정 예시
logins:
  - username: mqtt_user
    password: secure_password
anonymous: false
require_certificate: false
certfile: fullchain.pem
keyfile: privkey.pem

Long-Lived Access Token 생성

  1. Home Assistant 프로필 → 보안 → 장기 액세스 토큰
  2. "토큰 생성" 클릭
  3. 이름 입력 (예: "HASS.Agent")
  4. 생성된 토큰 복사 (한 번만 표시됨!)

2️⃣ Windows PC 준비

  • Windows 10/11 (64비트)
  • .NET Framework 4.8 이상
  • 관리자 권한 (일부 기능)

HASS.Agent 설치 및 설정

다운로드 및 설치

  1. GitHub Releases 접속
  2. 최신 HASS.Agent-Setup.exe 다운로드
  3. 설치 실행 (기본 경로 권장)

1단계: MQTT 설정

MQTT 브로커: 192.168.1.100 (또는 homeassistant.local)
포트: 1883
사용자명: mqtt_user
비밀번호: secure_password
디바이스 이름: DESKTOP-MAIN

2단계: Home Assistant 연결

Home Assistant URL: http://192.168.1.100:8123
Access Token: [앞서 생성한 토큰 붙여넣기]

3단계: 기능 선택

  • ✅ 미디어 플레이어 활성화
  • ✅ 알림 활성화
  • ✅ 센서 활성화
  • ✅ 명령 활성화
300x250

센서 구성

시스템 센서 추가 예시

HASS.Agent 트레이 아이콘 → 우클릭 → Configure → Sensors

센서 타입 이름 업데이트 주기 엔티티 ID
CPULoad CPU 사용률 10초 sensor.desktop_main_cpu_usage
MemoryUsage 메모리 사용률 30초 sensor.desktop_main_memory_usage
DiskUsage C드라이브 사용률 300초 sensor.desktop_main_disk_usage_c
ActiveWindow 활성 창 제목 5초 sensor.desktop_main_active_window
SessionState PC 잠금 상태 1초 binary_sensor.desktop_main_locked
MicrophoneActive 마이크 사용 중 1초 binary_sensor.desktop_main_microphone_active
WebcamActive 웹캠 사용 중 1초 binary_sensor.desktop_main_webcam_active

사용자 정의 센서 (PowerShell)

# GPU 온도 센서 예시
Get-WmiObject -Namespace "root\OpenHardwareMonitor" -Class Sensor | 
Where-Object {$_.SensorType -eq "Temperature" -and $_.Name -like "*GPU*"} | 
Select-Object -ExpandProperty Value -First 1

명령(Commands) 설정

기본 명령 예시

명령 타입 이름 실행 내용 스위치 엔티티
SendKeys 볼륨 업 {VOLUME_UP} switch.desktop_main_volume_up
SendKeys 볼륨 다운 {VOLUME_DOWN} switch.desktop_main_volume_down
PowerShell 모니터 끄기 (Add-Type '[DllImport("user32.dll")]public static extern
int SendMessage(int hWnd,int hMsg,int wParam,int lParam);'
-Name a -Pas)::SendMessage(-1,0x0112,0xF170,2)
switch.desktop_main_monitor_off
Custom Chrome 실행 C:\Program Files\Google\Chrome\Application\chrome.exe switch.desktop_main_chrome
Shutdown PC 종료 - switch.desktop_main_shutdown
Restart PC 재시작 - switch.desktop_main_restart
Lock PC 잠금 - switch.desktop_main_lock

고급 PowerShell 명령

# 특정 앱이 실행 중인지 확인 후 종료
if (Get-Process "notepad" -ErrorAction SilentlyContinue) {
    Stop-Process -Name "notepad" -Force
}

미디어 플레이어 활용

기본 제어

# 재생/일시정지
service: media_player.media_play_pause
target:
  entity_id: media_player.desktop_main

# 볼륨 설정
service: media_player.volume_set
target:
  entity_id: media_player.desktop_main
data:
  volume_level: 0.5

# 다음/이전 트랙
service: media_player.media_next_track
target:
  entity_id: media_player.desktop_main

미디어 재생

# 로컬 MP3 재생
service: media_player.play_media
target:
  entity_id: media_player.desktop_main
data:
  media_content_type: music
  media_content_id: "C:\\Music\\song.mp3"

# 온라인 스트림 재생
service: media_player.play_media
target:
  entity_id: media_player.desktop_main
data:
  media_content_type: music
  media_content_id: "http://stream.example.com/radio.mp3"

알림 시스템

기본 알림

service: notify.desktop_main
data:
  message: "세탁기 작동이 완료되었습니다!"
  title: "Home Assistant 알림"

고급 알림 (이미지 포함)

service: notify.desktop_main
data:
  message: "현관에 방문자가 있습니다"
  title: "보안 알림"
  data:
    image: "http://192.168.1.100:8123/local/camera_snapshot.jpg"

자동화 예제

예제 1: PC 사용 중 조명 자동 조절

alias: "PC 사용 시 조명 자동화"
trigger:
  - platform: state
    entity_id: binary_sensor.desktop_main_locked
    from: "on"
    to: "off"
condition:
  - condition: time
    after: "18:00:00"
    before: "23:59:00"
action:
  - service: light.turn_on
    target:
      entity_id: light.desk_lamp
    data:
      brightness_pct: 70
      color_temp: 350

예제 2: 게임 실행 시 방해금지 모드

alias: "게임 모드 자동화"
trigger:
  - platform: template
    value_template: >
      {{ 'game' in state_attr('sensor.desktop_main_active_window', 'title')|lower or
         'steam' in state_attr('sensor.desktop_main_active_window', 'title')|lower }}
action:
  - service: light.turn_on
    target:
      entity_id: light.gaming_rgb
    data:
      effect: "gaming"
  - service: switch.turn_on
    target:
      entity_id: switch.do_not_disturb

예제 3: 화상회의 중 알림

alias: "화상회의 알림"
trigger:
  - platform: state
    entity_id: binary_sensor.desktop_main_webcam_active
    to: "on"
action:
  - service: light.turn_on
    target:
      entity_id: light.office_door_indicator
    data:
      color_name: "red"
  - service: notify.family_phones
    data:
      message: "화상회의 중입니다. 조용히 해주세요."

예제 4: 작업 리마인더

alias: "휴식 시간 알림"
trigger:
  - platform: time_pattern
    hours: "*"
    minutes: "0"
condition:
  - condition: state
    entity_id: binary_sensor.desktop_main_locked
    state: "off"
  - condition: numeric_state
    entity_id: sensor.desktop_main_uptime_hours
    above: 1
action:
  - service: notify.desktop_main
    data:
      message: "1시간마다 잠시 휴식을 취하세요!"
      title: "건강 알림"
  - service: tts.google_translate_say
    target:
      entity_id: media_player.desktop_main
    data:
      message: "잠시 휴식 시간입니다"

보안 설정

Windows 방화벽 규칙

# MQTT 포트 허용 (인바운드)
New-NetFirewallRule -DisplayName "HASS.Agent MQTT" -Direction Inbound -LocalPort 1883 -Protocol TCP -Action Allow

# HASS.Agent API 포트 허용
New-NetFirewallRule -DisplayName "HASS.Agent API" -Direction Inbound -LocalPort 5115 -Protocol TCP -Action Allow

MQTT 보안 강화

# Mosquitto 고급 설정
listener 1883
protocol mqtt

listener 8883
protocol mqtt
cafile /ssl/ca.crt
certfile /ssl/server.crt
keyfile /ssl/server.key
require_certificate true

문제 해결

일반적인 문제와 해결책

문제 원인 해결 방법
장치가 Home Assistant에 나타나지 않음 MQTT 연결 실패 MQTT 브로커 설정 확인, 방화벽 규칙 점검
미디어 플레이어가 작동하지 않음 권한 부족 HASS.Agent를 관리자 권한으로 실행
센서 업데이트가 느림 업데이트 주기가 너무 김 센서 설정에서 업데이트 주기 단축
알림이 표시되지 않음 Windows 알림 설정 Windows 설정 → 알림에서 HASS.Agent 허용

로그 확인

%APPDATA%\HASSAgent\logs\

대시보드 예제

Lovelace 카드 구성

type: vertical-stack
cards:
  - type: entities
    title: PC 상태
    entities:
      - entity: binary_sensor.desktop_main_locked
        name: PC 잠금 상태
      - entity: sensor.desktop_main_cpu_usage
        name: CPU 사용률
      - entity: sensor.desktop_main_memory_usage
        name: 메모리 사용률

  - type: media-control
    entity: media_player.desktop_main

  - type: horizontal-stack
    cards:
      - type: button
        entity: switch.desktop_main_lock
        name: PC 잠금
        icon: mdi:lock
      - type: button
        entity: switch.desktop_main_monitor_off
        name: 모니터 끄기
        icon: mdi:monitor-off

고급 활용 팁

1. 작업 스케줄러 자동 실행

<!-- 작업 스케줄러 XML 예시 -->
<Task>
  <Triggers>
    <LogonTrigger>
      <Enabled>true</Enabled>
    </LogonTrigger>
  </Triggers>
  <Actions>
    <Exec>
      <Command>C:\Program Files\HASS.Agent\HASS.Agent.exe</Command>
    </Exec>
  </Actions>
  <Principals>
    <Principal>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
</Task>

2. 다중 PC 관리

각 PC마다 고유한 디바이스 이름을 설정하여 여러 대의 PC를 동시에 관리할 수 있습니다.

3. 웹훅 연동

HASS.Agent는 웹훅을 지원하여 외부 서비스와도 연동 가능합니다.

참고 자료

728x90
그리드형(광고전용)

댓글