Skip to content

Home Assistant integration

roleo edited this page Sep 21, 2022 · 10 revisions

tested on Home Assistant >= 2022.06

Custom integration

If you want to integrate your cam automagically, please visit this repo: https://github.com/roleoroleo/yi-hack_ha_integration

Manual integration

If you want to create entities manually, read below.

Image support

This hack implements a standard ONVIF interface, thanks to @KoynovStas - https://github.com/KoynovStas/onvif_srvd

Configure your cam using standard ONVIF integration in Home Assistant. RTSP stream and snapshot feature are supported. PTZ is also supported for models that have it.

Event detection

The only feature not present in ONVIF is the event detection. You can add it through a binary sensor or an MQTT camera

Binary sensor

If you want to use binary sensor, configure your cam as an MQTT sensor:

  1. Access to the web interface
  2. Go to MQTT section
  3. Enable MQTT and set the server parameters (ip, port, etc...)
  4. Set the topic prefix (e.g. "home-assistant/kitchen")
  5. Set the topic suffix for motion event (e.g. "motion_detection")
  6. Set the motion start message (e.g. "ON")
  7. Set the motion stop message (e.g. "OFF")
  8. Check the other options if you want to configure video list message and baby crying support.
  9. Check advanced options if you want to change qos or retain parameters.
  10. Save configuration

Configure Home Assistant adding a binary sensor like this.

mqtt:
  binary_sensor:
    - state_topic: "home-assistant/kitchen/motion_detection"
      name: "Motion detection - kitchen"
      payload_on: "motion_start"
      payload_off: "motion_stop"
      qos: 1

When a motion is detected the sensor will turn on.

MQTT camera

If you want to use this feature, configure your cam as an MQTT sensor:

  1. Access to the web interface
  2. Go to MQTT section
  3. Enable MQTT and set the server parameters (ip, port, etc...)
  4. Set the topic prefix (e.g. "home-assistant/kitchen")
  5. Set the topic suffix for jpeg image (e.g. "motion_detection_image")
  6. Check advanced options if you want to change qos or retain parameters.
  7. Save configuration

Configure Home Assistant adding an MQTT camera like this and add, if you want, a picture-glance to lovelace.

mqtt:
  camera:
    - topic: "home-assistant/kitchen/motion_detection_image"
      name: "Motion detection image - kitchen"

When a motion is detected a jpeg in binary format will be sent to the topic.

Download videos

If you want to donwload videos recorded from the cam you have two ways:

  1. MQTT
  2. Web services

MQTT method

  1. Configure the topic suffix for video list message in MQTT section
  2. Wait for the json message sent to this topic when the motion event ends

Example:

{
    "start": "2020-02-01T16:28:27+0200",
    "end": "2020-02-01T16:29:27+0200",
    "files": [
        "2020Y02M01D16H/29M00S60.mp4",
        "2020Y02M01D16H/28M24S36.mp4"
    ]
}
  1. Parse the message and extract the urls (e.g. http://IP-CAM:8080/record/2020Y02M01D16H/28M24S36.mp4)
  2. Get the videos using http get

Web services method

  1. Wait for MQTT stop message
  2. Call getlastrecordedvideo web service: http://IP-CAM:8080/cgi-bin/getlastrecordedvideo.sh
  3. See the wiki for details: https://github.com/roleoroleo/yi-hack-Allwinner/wiki/Web-services-description