I’ve seen this topic come up quite a bit recently and thought I would give some insights. How can you automatically pop a camera feed into Kodi on motion? And how can you have it disappear after a few seconds?
As it turns out this is pretty simple, and should be doable from your home automation platform of choice. All you need it a way to capture camera motion events and act on them. I’ve also added a virtual switch so I can disable the alerts.
The build list for the project is pretty simple:
- A camera or NVR that can pipe motion alert triggers to a home automation platform (I’m using Blue Iris)
- A home automation platform that can hit the Kodi API (either natively or through a custom script)
- Kodi and this plugin: https://github.com/maikito26/plugin.video.surveillanceroom
So first things first, configure that plugin for whatever camera(s) you want to pop. It says Foscam but works with anything that does RTSP or motion JPEG. Make note of the number of each one as you will need that when you call the camera pop.
Next you need a way to trigger your automation platform on motion. You can leverage a dedicated motion sensor, or use an API call from your NVR. In this case I’m using the API call from Blue Iris into Home Assistant. This can be done simply from Blue Iris like so:
The URL being something like this: ha.example.org/api/states/binarysensor.blue_iris_&CAM?api_password=hunter2
From there all you need to do it is create a trigger on motion. In Home Assistant that looks something like this:
trigger:
- platform: state
entity_id: binarysensor.blue_iris_frontwalk
from: 'off'
to: 'on'
condition:
condition: state
entity_id: input_boolean.enable_video_pop
state: 'on'
action:
service: script.turn_on
entity_id: script.front_walk_camera_pop
From there you just need to call the script. Here is an example you can use written in bash:
#This script pops up a specific cameras on Kodi
#The input is the number of the camera configured in the addon
#Get the camera number passed in
camera=$1
#Pop the preview
curl -u kodi:hunter2 -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","method":"Addons.ExecuteAddon","params":{"wait":false,"addonid":"plugin.video.surveillanceroom","params":{"action":"show_preview","camera_number":"'$camera'","id":"1"}},"id":2}' http://192.168.9.21:8080/jsonrpc
#Wait 15 seconds
sleep 15
#Close preview
curl -u kodi:hunter2 -i -X POST -H "Content-Type: application/json" -d '{"jsonrpc": "2.0", "method": "GUI.SetFullscreen", "params": { "fullscreen": "toggle" }, "id": "1"}' http://192.168.9.21:8080/jsonrpc
And there you go! You can tweak the sleep time if needed. I found 15 seconds to be a pretty good choice though.
Happy Automating!
-Dan