News

So you can see any IP camera in Home Assistant thanks to RTSP

Most home IP cameras have the RTSP protocol, this protocol will allow us to view the camera in real time from any device compatible with this standard protocol. For example, you could integrate the cameras directly into your home's Ajax Systems alarm, you could also view them through VLC and even into recording software (NVR) such as QVR Elite on QNAP NAS. Of course, we can also integrate these cameras into Home Assistant, with the aim of viewing it along with other entities that we have in the main menu, but also to carry out automations if it detects movement.

Add any camera with RTSP to the home automation system

Currently there are some brands of IP cameras that have official integration, such as Reolink or EZVIZ, so the installation and configuration of these cameras through the home automation system is really simple, in addition, we will have additional entities such as motion detection among other. TP-Link Tapo cameras can also be integrated, but through third-party integration and using HACS. All cameras usually incorporate the RTSP protocol, which is standard, and this protocol is the key to adding it to Home Assistant without official compatibility.

Before starting the process, it is advisable to make sure that our camera supports the RTSP protocol, and what URL to use is generally found in the official documentation. The address is usually similar to this: «rtsp://user:password@ip_address/live/profile.0«. If we use the VLC program, which is completely free, we can try to view it to see if it is capable of loading the video. If so, we can add it to the system without problems. Otherwise, we must review the URL entered so that it does not cause problems. To prove it, we simply have to go to «Media / Open network location» and enter the URL, click on «play» and if we see the image it means that everything is correct.

The first thing we have to do is go directly to the main menu of the home automation system, to click on the «Settings» and proceed with the device integration.

Within the menu of «Settings» we must go to «Devices and services«.

Inside the «Integrations» we have to click on the « buttonAdd integration«.

Now we search for “camera” and choose the first option of “generic camera» to later configure the RTSP.

When we click on «generic camera«We have different options that we must fill out. In principle, it is only mandatory to fill out the following:

  • Stream Source URL: is the URL to access the video streaming, as we have indicated previously, it should look like “rtsp://user:key@ip_address/live/profile.0”.
  • Transport protocol: TCP.
  • Authentication:basic.
  • Uncheck “SSL verification”.

Once everything is configured, click on the «Send» to check if it is capable of receiving video streaming, and add it to the list of integrations.

If we have several IP cameras registered, all of them will appear in the list of generic cameras, as you can see here:

If we click on «1 device«, we can access within the device in question, and we will be able to see the related automations, scenes, scripts, and we can also see the camera itself in real time and even the record.

By clicking on the circle with the image, we will see the real-time display of the camera, in our case it is a camera from the manufacturer D-Link.

If we enter the entity, we have the possibility of giving it a name and changing the icon, we can also configure the ID of the entity that we will later use to add it to the main menu. We also have other configuration options that are perfectly explained. For example, we can configure the options of «preload camera stream«, if we want it to be «visible«, and even add the device to a certain area.

Once we have added the camera to the home automation system, we are going to put it in the main menu to view it at all times.

Put the camera in main view

If you want to put the camera in the main view, you must add a new card, the ideal card for real-time viewing is the «Image overview«.

Once we click on said card, we give it a title that will appear just below, we must also choose the entity of the camera that we have previously registered. We can search for it by the name you have given it, or by the name of the entity. The most important option is «Camera view: live«, so that it always shows us the entire image in real time. Once configured, click on «Keep» and we will have the card ready.

As you can see, we have added real-time viewing of the camera on a Home Assistant card, so it can be seen along with other information.

Once we have added the IP camera via RTSP and have removed the corresponding card from the main menu, we are going to show you how to create a virtual entity to detect the movement of the camera in a very simple way, and without consuming many resources.

Create a virtual entity to detect motion

When we add an IP camera from the EZVIZ or Reolink cameras among others, the official integration of Home Assistant will allow us to add entities with the motion detection of the camera itself, delegating the detection to the cameras themselves. If we add a camera via RSTP this is not possible, but we must “analyze” the image continuously and see if there is an important change or not. This is where the ffmpeg of the home automation system comes into play, to analyze if there are important changes in the image and to be able to tell the virtual entity whether or not there is movement detected.

The first thing we must do is activate the ffmpeg functionality, in the “configuration.yaml” we put:

#Reconocimiento movimiento camara por RTSP
stream:
ffmpeg:

In the following image you can see how it would look:

Now we go to the “binary_sensores.yaml” file where we have all the binary sensors, because here we will have “detected” and “not detected” motion. We must put the following:

- platform: ffmpeg_motion
name: Camara_Sensor_Movimiento
input: -rtsp_transport tcp -i rtsp://URL_completa
changes: 20
reset: 30

In the following image you can see how it would look with the configuration:

This FFMPEG functionality has many additional configuration options, you can go to the official documentation for Home Assistant and see all the available options. We have only used the basic ones, which consist of the name, the video input, the percentage of change in the image for the movement to be detected, and the reset in seconds to return to “not detected” mode after a detection.

Now that we have registered it, we proceed to «Restart Home Assistant» with the integrations, that is, we are going to «Developer tools«, we click on the « buttonRestart» and we choose the second option starting from the top. Once done, we can now use the virtual entity we just created.

If we enter the virtual entity, we can see a complete history of detections and non-detections of the IP camera. Through the option «changes» We can adjust the sensitivity of the detection, since it would also detect movement if there is a sudden change in luminosity.

Furthermore, a very important aspect that we have detected is that it is possible that the state of the virtual entity is “not available«. If at any time Home Assistant loses communication with the IP camera, either due to a small interruption in the Wi-Fi network or a simple restart of the camera, the motion sensor will appear in this state. We are going to indicate an automation to automatically restart the FFMPEG process and not have problems.

alias: ACCION - Reinicio motion sensor
description: ""
trigger:
- platform: state
entity_id:
- binary_sensor.garajecamara_sensor_movimiento
to: unavailable
for:
hours: 0
minutes: 1
seconds: 0
condition: []
action:
- service: ffmpeg.restart
data: {}
mode: single

In the following image you can see the configuration that we have applied in this automation, and it will be really useful so that we always have the motion detection system enabled.

By now, you should already have both the IP camera and motion detection integrated. Of course, there is another more advanced option for motion detection and integration into Home Assistant, such as using Frigate, but this software consumes a lot of computer resources and is only suitable for the most powerful mini PCs or NAS.

Leave a Reply

Your email address will not be published. Required fields are marked *