Milestone CCTV Integration

Please add an integration for Milestone and Xprotect CCTV.

What do you think?

Thanks

As they seem to be quite open with their apis etc, it gets my vote (you should vote too)

Yeah it is, how do I vote :rofl:

Ahh got it, the vote button

Click the vote button!

1 Like

Milestone Xprotect has allready an RESTapi, going to test this in the comming weeks how its called.
For all out there here is a Video from the 2020 DevCon, how its working.

1 Like

Any progress on this?
I just noticed we can now install xprotect API gateway.
https://doc.milestonesys.com/latest/en-US/standard_features/apigateway/installation/api_gway_verify-api-gateway.htm?tocpath=Add-ons|Milestone%20API%20Gateway|Installation
%7C_____3

We can now query the API gateway from another machine. But yeah the free version is kinda limited, no alarm, no motion detection etc.

Oh this is cool. Hopefully see something come shortly then!

Were you successful with implementing this restAPI?

I have been playing around with this, and am making a little bit of progress. I have installed the free version (up to 8 cameras) of MileStone XProtect. To get REST services, you have to install the API Gateway addon. I currently run ALL of the XProtect services on a single server, running Windows 10 Pro, hosted on an ESXi Virtual Machine named “WIN10VM”.

I am running everything using http format (no SSL yet), just to ensure it will do what I need it to do and to rule out security / certificate related issues. I’m using PostMan to test the REST services.

After installing the API gateway, the url that is used for REST services is “http://win10vm:8080”. I store that URL in a PostMan environment variable called “XProtectManagementServerUrlPrefix”.

Here’s another link to the REST Getting Started guide. It also documents the REST API itself.

The first REST call you have to make is to obtain a bearer token. The token returned is good for 3600 (seconds?), and has to be specified on all subsequent REST calls. I store that in another PostMan environment variable named “XProtectBearerToken”. The token is a fairly large value, so the environment variable is the way to go for passing it to subsequent REST calls. Refreshing the token (after 3600 seconds) is done by calling the first REST call, then refreshing the XProtectBearerToken environment variable.

Here’s an example of creating the bearer token:
POST method, url = {{XProtectManagementServerUrlPrefix}}/idp/connect/token
Request body contains urlencoded parameters: username, password, grant_type, client_id.
The username and password are the credentials to the Xprotect Management Client (basic user).

Once you have a valid bearer token, you can make calls to the other REST API’s. For example, here is how I get a list of camera’s that are defined:

GET method, url = {{XProtectManagementServerUrlPrefix}}/api/rest/v1/cameras
Request header contains the “Authorization” key, with the value being "Bearer " followed by the bearer token.

Hope that’s enough to get you started.

1 Like

I just installed the free version (up to 8 cameras) of XProtect a few days ago, and motion detection is working for me. I’m not sure if it’s a “trial” period or not, but I assume not as the license indicates “Free”. I was able to add a WebHook into XProtect, as well as an HA Automation script to notify me when XProtect has detected motion in a camera.

HA Automation Script:

alias: XProtext Webhook - Notify App When Motion Detected
description: >-
  Send a notification to the Mobile App when the Milestone XProtect surveillance
  system has detected motion in a camera feed, as well as log the event JSON to
  a log file.
trigger:
  - platform: webhook
    allowed_methods:
      - POST
      - PUT
    local_only: true
    webhook_id: XProtectNotifyMotionDetected
    alias: When Webhook XProtectNotifyMotionDetected payload has been received
condition: []
action:
  - service: notify.mobile_app_iphone
    alias: Send a Notification to a Users Mobile App
    data:
      title: Camera Motion Detected
      message: >-
        Surveillance system has detected motion in one or more cameras - "{{
        trigger.json.Event.EventHeader.Source.Name }}"
      data:
        push:
          sound:
            name: default
            critical: 1
            volume: 1
        actions:
          - action: URI
            title: Open Camera Panel
            uri: /dashboard-cameras/0
          - action: URI
            title: Open Alarm Panel
            uri: /dashboard-security/0
  - service: notify.notification_log_file
    data:
      message: XProtect Webhook Payload Data = "{{ trigger.json }}"
mode: single

XProtect WebHook Definition (screenshot):


image

XProtect Rule Definition (screenshot):

And finally, the XProtect JSON Event data received by HA Automation:

Formatted JSON webhook data:
{
  "Event": {
    "EventHeader": {
      "ID": "dfdc469f-27e4-43d1-8114-c99c0b425d71",
      "Timestamp": "2023-06-26T23:58:19.339Z",
      "Type": "System Event",
      "Version": "1.0",
      "Priority": 1,
      "PriorityName": "High",
      "Name": "Motion Detected",
      "Message": "Motion Detected",
      "Source": {
        "Name": "iPadCam01 - Camera",
        "FQID": {
          "ServerId": {
            "Type": "XPCORS",
            "Hostname": "win10vm",
            "Port": 7563,
            "Id": "19f94d50-b5ad-4e90-8b3f-9928bb60f9f2",
            "Scheme": "http"
          },
          "ParentId": "19f94d50-b5ad-4e90-8b3f-9928bb60f9f2",
          "ObjectId": "0c60e7bf-9d57-4047-b623-e76d375a1fe6",
          "FolderType": 0,
          "Kind": "5135ba21-f1dc-4321-806a-6ce2017343c0"
        }
      },
      "MessageId": "0245bafd-91f3-4845-af29-8fc3461fa037"
    }
  },
  "Site": {
    "ServerHostname": "win10vm",
    "AbsoluteUri": "http://win10vm/",
    "ServerType": "XPCO"
  }
}

Hope it helps!

4 Likes

In case anyone is still following this thread …

I have created a new python 3 package to interface with the XProtect REST Service API Gateway product. It’s called MilestoneXProtectRestPython API, and can be found on the PyPi.org site. For now, it’s mostly just GET type of methods to retrieve data about the environment (e.g. defined cameras, microphones, site information, etc) - there are no UPDATE or DELETE features in the API as of yet, even though the underlying XProtect REST API supports them. Have a look and let me know what you think.

Sample Code Example - Get All Defined Cameras:

# package imports.
from milestonexprotectrestpython.xprcollection import XPRCollection
from milestonexprotectrestpython.xprfilteroperator import XPRFilterOperator
from milestonexprotectrestpython.xprlogininfo import XPRLoginInfo
from milestonexprotectrestpython.xprrestservice import XPRRestService

# create XPRRestService instance and set server prefixes for our environment.
xrest:XPRRestService = XPRRestService()
xrest.ApiGatewayUrlPrefix = "https://myapigateway.example.com"
xrest.IsSslVerifyEnabled = False

# authenticate using xprotect basic auth credentials.
loginInfo:XPRLoginInfo = xrest.LoginBasicUser("xpsampleadmin", "MyPassword@1")
print("** Login Details:\n{0}\n".format(loginInfo))

# get camera devices, both enabled and disabled.
cams:XPRCollection = xrest.GetCameras(True)
print("** Cameras (Enabled and Disabled):\n{0}\n".format(cams))

My next step is to start on a Home Assistant integration (or Add-On maybe) to support Milestone XProtect using the above API. I have never written an HA integration before, so it will be interesting to say the least.

Hope it helps!

6 Likes

Hi any progress on this?
Seems like milestone hasnt updated 2023 r3 in a bit so it might make a good basis for integration.

Would be great if we could use its motion detection as trigger (i was wrong turns out the free version supports it)

As much as i love open source like frigate, milestone is still far ahead in terms of UI. So its a +1 for wife factor

1 Like

Hi @cemara.

Unfortunately, no progress on this as I have been pulled in other directions.

You are the first to comment on this thread in 9 months, so the community interest is either not there or no one else is pushing it. If the community interest grows then I will re-visit, but currently have no plans to move forward with this.

Thanks, and wish I had better news.

I would like to see milestone integrated. Being andvanced partner with them and my interest in HA would be good to bring the two together.

Good work thus far. :+1:

1 Like

I would also be extremely interested in this integration.

I can provide test license for verified developer if needed.

1 Like

Also very interested in xProtext + Home Assistant integration!