A python program to handle recording video feeds from IP cameras that integrates with MQTT for easy automation (Home Assistant for example)
- Edit
example_config.pyto suit your needs- an arbitrary number of cameras can be added
- each camera entry should have a corresponding
outfiledefinition - you should only edit the word immediately before and after the
//for each outfile definition
- Rename
example_config.pytoconfig.py - Create as many folders as cameras in
config.pywhere the folder name is the part immediately before the//in each outfile definition - Install the requirements using
pip install -r requirements.txt - Install ffmpeg
- Run the script using
python camera.py - Start recording by sending the payload
recordto the mqtt topiccameras/nvr/recordandstopto the same topic to stop
In the configuration.yaml file for Home Assistant, add a new platform (assuming your mqtt broker is already set up correctly for Home Assistant) as below:
- platform: mqtt
name: "camera-record"
state_topic: "cameras/nvr"
command_topic: "cameras/nvr/record"
payload_on: "record"
payload_off: "stop"
retain: true
This will add a new toggleable switch which you can use to start and stop recording.