Skip to content

Home Assistant RTSP configuration

Phill Healey edited this page Aug 9, 2019 · 8 revisions

Configuring home-assistant to work with yi-hack-v4 in RTSP is possible by enabling the ffmpeg component in your configuration.yaml and setting up a camera.ffmpeg entity. The creation of a motion binary_sensor is also possible using MQTT.

Note: In this configuration, ffmpeg is utilized solely for providing a still_image every 30 seconds. home-assistant > 0.91.0 is recommended in order to leverage the stream: component.

stream:
ffmpeg:
camera:
  - platform: ffmpeg
    name: yi_hack_v4
    input: -rtsp_transport tcp -i rtsp://<camera_ip>/ch0_0.h264

Obviously if you are using the RTSP SD stream the correct channel is /ch0_1.h264.

Once done, you can easily add your camera to your LoveLace config using a picture-entity card:

name: Yi Hack v4
type: picture-entity
entity: camera.yi_hack_v4

Troubleshooting:

You should be sure to remove any references to the Yi platform as these will take up additional resources trying to grab the video files via FTP. eg:

 #    name: Garage YiCam
 #    host: 
 #    password: 
 #    path: /home/camera/feed
 #    path: /tmp/sd/record
 #    ffmpeg_arguments: '-vf scale=800:450'

Some users on manual installs may see the following error in their logs after restarting:

ERROR (SyncWorker_5) [homeassistant.util.package] Unable to install package av==6.1.2: Command "/home/pi/home-assistant/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-udfl2b3t/av/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-ftn5zmh2/install-record.txt --single-version-externally-managed --compile --install-headers /home/pi/home-assistant/include/site/python3.6/av" failed with error code 1 in /tmp/pip-install-udfl2b3t/av/ 2019-03-12 08:49:59 ERROR (MainThread) [homeassistant.requirements] Not initializing stream because could not install requirement av==6.1.2 2019-03-12 08:49:59 ERROR (MainThread) [homeassistant.setup] Setup failed for stream: Could not install all requirements.

If you see this error you can solve it by running the following commands and restarting Home Assistant (commands do not need to be run as the homeassistant user):

sudo apt-get install -y python-dev pkg-config libavformat-dev libavcodec-dev libavdevice-dev libavutil-dev libswscale-dev libavresample-dev libavfilter-dev

MQTT Motion Sensor:

Configure your broker and authentication in the webUI under Configuration > MQTT.
Assuming you have mqtt: already setup, it should be as easy as:

binary_sensor:
  - platform: mqtt
    state_topic: "yicam/motion_sensor"
    name: "yihack_v4_motion_sensor"
    payload_on: "motion_start"
    payload_off: "motion_stop"
    device_class: motion

The binary_sensor.yihack_v4_motion_sensorcan be used as a trigger for automations, including calling for camera.snapshot and camera.record services.
Beware that the state of a binary_sensor still changes from on to off even if is showed as Detected and Clear in Lovelace.

home-assistant docs:
https://www.home-assistant.io/components/ffmpeg/
https://www.home-assistant.io/components/camera.ffmpeg/
https://www.home-assistant.io/components/stream/
https://www.home-assistant.io/components/binary_sensor.mqtt/