산업 제조
산업용 사물 인터넷 | 산업자재 | 장비 유지 보수 및 수리 | 산업 프로그래밍 |
home  MfgRobots >> 산업 제조 >  >> Manufacturing Technology >> 제조공정

라즈베리 파이 Home Assistant로 안전한 홈 모니터링: 모션, 알람, 비디오 캡처

라즈베리 파이에 Home Assistant(HA)로 신뢰할 수 있는 홈 보안 시스템을 구축하는 것은 핵심 구성요소인 모션 센서, 알람 패널, 카메라 기반 비디오 캡처를 이해하면 간단합니다. 이 가이드는 HC-SR501 PIR 센서 배선부터 HA 설정, mjpg-streamer 실행, 사진 첨부 즉각 이메일 알림 발송까지 전체 설정을 안내합니다.

전제 조건

1. HC-SR501을 파이에 배선

센서에 세 핀이 있습니다: VCC(+), GND(–), OUT. 다음과 같이 연결하세요:

이 연결로 HA가 rpi_gpio 플랫폼을 통해 센서의 이진 상태를 읽을 수 있습니다.

2. mjpg-Streamer 설치

이 가이드를 사용해 mjpg-streamer와 선택적 FFMpeg 레코더를 설정하세요. 저장소의 스크립트가 스트림을 시작하고 필요 시 녹화를 시작/중지합니다.

3. Home Assistant 설정

/usr/share/hassio/homeassistant/configuration.yaml (또는 HA 설정 폴더)를 여세요. 다음 섹션을 추가하세요:

# PIR 바이너리 센서
binary_sensor:
  - platform: rpi_gpio
    ports:
      7: Sensor HC-SR501
    invert_logic: false

# 수동 알람 패널
alarm_control_panel:
  - platform: manual
    name: Home Alarm
    pending_time: 60
    delay_time: 40
    code: 1234

# mjpg-streamer 제어용 커맨드라인 스위치
switch:
  - platform: command_line
    switches:
      start_stop_motion_rec_timelapse:
        friendly_name: 'Record motion timelapse'
        command_on: "curl https://localhost/start_mjpgstrm.php && curl https://localhost/rec-motion-mjpg.php"
        command_off: "curl https://localhost/stop_mjpgstrm.php && curl https://localhost/rec-motion-mjpg-stop.php"

# 커스텀 스크립트용 쉘 명령
shell_command:
  take_snapshot_webcam: '/config/scripts/takeSnapshotWebcam.sh'
  start_mgpg_streamer: 'curl https://localhost/start_mjpgstrm.php'
  stop_mgpg_streamer: 'curl https://localhost/stop_mjpgstrm.php'
  start_motion_rec: 'curl https://localhost/rec-motion-mjpg.php'
  stop_motion_rec: 'curl https://localhost/rec-motion-mjpg-stop.php'

# 이메일 알림 (Gmail 예시)
notify:
  - name: ha_sendmail
    platform: smtp
    server: smtp.gmail.com
    port: 587
    timeout: 15
    sender: 
    encryption: starttls
    username: 
    password: 
    recipient:
      - 
    sender_name: My Home Assistant

편집 후 Configuration → Server Controls → Check Config로 설정 검증 후 자동화와 스크립트 리로드하세요.

4. 자동화 로직

automation.yaml에 다음 자동화를 생성해 센서, 알람, 카메라를 연동하세요.

# 1. 무장 상태에서 모션 감지 시 알람 트리거
- alias: 'Trigger alarm while armed away'
  trigger:
    - platform: state
      entity_id: binary_sensor.sensor_hc_sr501
      to: 'on'
  condition:
    - condition: state
      entity_id: alarm_control_panel.home_alarm
      state: armed_away
  action:
    - service: shell_command.start_mgpg_streamer
    - service: shell_command.start_motion_rec
    - service: alarm_control_panel.alarm_trigger
      target:
        entity_id: alarm_control_panel.home_alarm

# 2. 알람 해제 시 녹화 중지
- alias: 'Stop recording when alarm disarmed'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: 'disarmed'
  action:
    - service: shell_command.stop_mgpg_streamer
    - service: shell_command.stop_motion_rec
    - service: persistent_notification.create
      data:
        message: 'The alarm is disarmed at {{ states('sensor.date_time') }}'

# 3. 알람 트리거 시 사진 이메일 전송
- alias: 'Email alert on alarm trigger'
  trigger:
    - platform: state
      entity_id: alarm_control_panel.home_alarm
      to: 'triggered'
  action:
    - service: persistent_notification.create
      data:
        message: 'Alarm triggered by motion sensor.'
    - delay: { seconds: 4 }
    - service: script.webcam_snapshot
    - service: notify.ha_sendmail
      data:
        title: 'Intruder alert'
        message: '{{now().strftime("%H:%M %Y-%m-%d")}}: Alarm triggered by motion sensor.'
      data:
        images:
          - /config/camera/snapshot.jpg

script.webcam_snapshot은 takeSnapshotWebcam.sh를 호출해 단일 프레임을 캡처하고 /config/camera/snapshot.jpg로 저장해 이메일 첨부용으로 사용합니다.

5. Docker 볼륨 주의사항

HA가 Docker에서 실행 중이면 컨테이너의 /config 폴더가 호스트의 /usr/share/hassio/homeassistant에 매핑됩니다. docker inspect homeassistant | less로 볼륨 바인딩을 확인하세요.

6. 시스템 테스트

  1. HA UI에서 알람을 armed_away로 무장하세요.
  2. PIR 센서 트리거 (예: 센서 앞을 지나가기).
  3. mjpg-streamer 시작, 모션 레코더가 짧은 클립 캡처, 스냅샷 포함 이메일 수신 확인.
  4. 알람 해제하고 녹화 중지 및 해제 알림 나타나는지 확인.

결론

이 단계를 통해 모션 감지, 알람 제어, 즉각 사진 알림을 모두 라즈베리 파이의 Home Assistant가 오케스트레이션하는 독립형 저비용 홈 보안 솔루션을 갖게 됩니다.

스크립트와 알림 설정을 본인 환경에 맞게 자유롭게 조정하세요. 즐거운 자동화!

제조공정

  1. 5달러 I2C 센서로 라즈베리 파이 온도 로거 만들기
  2. 라즈베리 파이와 파이썬으로 원격 온도 센서 만들기 – 단계별 가이드
  3. 라즈베리 파이 기상 관측소 만들기: 매일 이메일로 날씨 데이터 전송
  4. DS1820 원와이어 온도 센서를 라즈베리 파이 GPIO로 연결하는 방법
  5. HC-SR04 초음파 거리 센서를 라즈베리 파이 3에 연결하는 완벽 가이드
  6. 라즈베리 파이용 DIY 적외선 모션 센서 만들기 – 단계별 가이드
  7. 가정용 저렴한 무선 센서 네트워크 구축하기
  8. 라즈베리 파이에서 PIR 모션 센서로 LED 제어하기
  9. Adafruit T-코블러 플러스로 헤드리스 라즈베리 파이 2 물 감지 알람 만들기
  10. 스마트 관수용 저가 라즈베리 파이 토양 수분 센서 만들기