Menu

🔎 How to Integrate SONOFF Camera into Home Assistant?

1. Introduction

This guide walks you through integrating the SONOFF Camera into Home Assistant using the ONVIF protocol. With this setup, you'll be able to:

  • View real-time video in Home Assistant
  • Receive motion and human detection events
  • Set up automation (e.g., trigger recording when motion is detected)

Before you start, make sure your device firmware and app version meet the requirements for ONVIF support.

  • SONOFF CAM-PT2 camera with firmware ≥ v1.0.5
  • SONOFF CAM-S2 camera with firmware ≥ v1.1.5
  • eWeLink App (version ≥ v5.18.0) installed on your phone

*This tutorial takes the SONOFF CAM-PT2 camera as an example.


2. What You'll Need

To complete this integration, make sure you have the following:

Hardware & Software

  • A device running Home Assistant (e.g., Raspberry Pi 4+, PC, or Docker)
  • Both the camera and Home Assistant in the same local network

Account Info & Access

  • Your SONOFF Camera has been added to the eWeLink app
  • ONVIF/RTSP function enabled via:
    Device Settings → More Settings → ONVIF/RTSP

Record the Following Info:

  • IP address of the camera
  • ONVIF port
  • Username and Password (modifiable)

下载.jpg

3. Pair with Home Assistant

Step 1: Install ONVIF Integration

  1. Go to the Home Assistant main dashboard.
  2. Navigate to: Settings → Devices & Services → Add Integration

  1. Search for ONVIF and select it

  1. Click Submit

Step 2: Add the Camera

  1. When CAM-PT2 is detected, select it and click Submit

  1. Enter the ONVIF Username & Password

  1. Click Skip and Finish

You will now see your camera in the Home Assistant dashboard under the Overview tab.


4. What You Can Do

4.1 Real-Time Streaming

  • Watch live video feed directly in Home Assistant
  • Toggle audio on/off

4.2 Motion & Human Detection Status

  • Motion/Human Detection as Automation Triggers

4.3 PTZ Control

  • Create a New Dashboard

  • Edit the Dashboard

  • Create a New section

  • In the "By Entity" panel, check the boxes for your camera’s motion/person detection sensors and the MainStream stream entity. Then, click “Add to Dashboard” to include them in your layout.

  • In the newly created section, click the edit icon (⋮) in the top right corner, and choose “Edit in YAML” from the menu.

  • Identify the text to the left of “_mainstream.”This text represents your camera's name. For example, if your camera string is "cam_pt2_test_mainstream", then the camera name is "cam_pt2_test".

type: grid
square: false
columns: 1
cards:
  - type: entities
    entities:
      - binary_sensor.<camera_name>_cell_motion_detection
      - binary_sensor.<camera_name>_motion_alarm
      - binary_sensor.<camera_name>_person_detection
  - type: picture-glance
    entities:
      - entity: camera.<camera_name>_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.<camera_name>_mainstream
            pan: LEFT
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Pan Left
        show_state: false
        icon: mdi:arrow-left
        show_icon: true
      - entity: camera.<camera_name>_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.<camera_name>_mainstream
            tilt: UP
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Tilt Up
        icon: mdi:arrow-up
      - entity: camera.<camera_name>_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.<camera_name>_mainstream
            tilt: DOWN
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Tilt Down
        icon: mdi:arrow-down
      - entity: camera.<camera_name>_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.<camera_name>_mainstream
            pan: RIGHT
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Pan Right
        icon: mdi:arrow-right
        show_icon: true
    camera_image: camera.<camera_name>_mainstream
    camera_view: live

For example:

type: grid
square: false
columns: 1
cards:
  - type: entities
    entities:
      - binary_sensor.cam_pt2_test_cell_motion_detection
      - binary_sensor.cam_pt2_test_motion_alarm
      - binary_sensor.cam_pt2_test_person_detection
  - type: picture-glance
    entities:
      - entity: camera.cam_pt2_test_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.cam_pt2_test_mainstream
            pan: LEFT
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Pan Left
        show_state: false
        icon: mdi:arrow-left
        show_icon: true
      - entity: camera.cam_pt2_test_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.cam_pt2_test_mainstream
            tilt: UP
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Tilt Up
        icon: mdi:arrow-up
      - entity: camera.cam_pt2_test_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.cam_pt2_test_mainstream
            tilt: DOWN
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Tilt Down
        icon: mdi:arrow-down
      - entity: camera.cam_pt2_test_mainstream
        tap_action:
          action: call-service
          service: onvif.ptz
          service_data:
            entity_id: camera.cam_pt2_test_mainstream
            pan: RIGHT
            speed: 1
            distance: 0.3
            move_mode: ContinuousMove
        name: Pan Right
        icon: mdi:arrow-right
        show_icon: true
    camera_image: camera.cam_pt2_test_mainstream
    camera_view: live

  • After replacing <camera_name> with your camera's name, fully replace the original code with the modified version. Then click SAVE and DONE to apply the changes.

  • At this point, you can see the live feed from the camera as well as the PTZ control buttons. You can use these buttons to rotate the camera up, down, left, and right.

4.4 Automations

Create automations using camera events as triggers. Example:

When motion is detected:

  • Go to Device Info → + Add Automation → Use device as trigger

  • Select “Motion started detecting”

  • Choose an action:
    Camera → Record, set file path like:
    /media/{{ now().strftime('%Y%m%d-%H%M%S') }}.mp4

  • Configure duration and lookback
  • Click Save

You can then find recordings under Media → My media.


5. Feature Overview

SONOFF Camera supports ONVIF and RTSP, enabling easy integration with Home Assistant. To help you get to know the differences, a quick feature overview is provided below.

CAM-PT2

Feature

ONVIF

RTSP

Device Discovery

×

Live View

PTZ Control

Manual configuration via script is required.

×

Event Notification

Triggers Automation (Motion, Human)

×

 

CAM-S2

Feature

ONVIF

RTSP

Device Discovery

×

Live View

Event Notification

Triggers Automation (Motion, Human)

×

 

Previous
🔎 Automate Roller Shutters with MINI-RBS: Time-Based Control
Next
🔎How to Integrate SONOFF Camera into Scrypted?
Last modified: 2025-08-20