Hikvision strobe with BlueIris

Using BlueIris triggers to activate the strobe and audio alarm on Hikvision cameras.

BlueIris is going to invoke a python script which uses ISAPI to activate the strobe and or audio alarm. It’s kinda janky in how it works but it does work. In the camera’s menu navigate to: Event> Basic Event> Alarm Input. The magic field is the Alarm Type, we’re going to set this to NC and the camera is going to go into an alarm state as the actual physical contacts are open. In the Linkage Method tab clear all but Flashing Alarm and Audio Warning. Next, go to the Flashing Alarm Light Output and Audible Alarm Output and clear the schedules. The Strobe and the Audio Alarm will now stop. The script basically fills the schedule to start the strobe and audio, waits 1 minuet and clears the schedule to shut off the strobe and audio.

First we need to install python onto our machine which BlueIris runs.

https://www.python.org/downloads/windows/

Make sure to “Add Python to PATH” during installation. Our script uses the Requests library an it is installed with pip at the command line.

pip install requests

The script is fairly basic in functions, it’s a start. Security isn’t too secure either with this method. Your password is stored and transferred in open text, don’t use this over the internet. Open a text editor and copy the script and save to a familiar location with .py as the file extension after you make the necessary changes. ie C://BlueIris/StrobeAudio.py

import requests
import json
import time

# Camera details
CAMERA_IP = '192.168.X.X'  # Change to your cameras addy
USERNAME = 'admin'
PASSWORD = 'password'  # Change to your admin password

# Duration in minutes
DURATION_MINUTES = 1  # Change this value as needed

# Base URL
BASE_URL = f'http://{CAMERA_IP}'

# Strobe Light Endpoints and Payloads
STROBE_ON_PAYLOAD = {
    "WhiteLightAlarm": {
        "channelID": 1,
        "durationTime": DURATION_MINUTES * 60,
        "frequency": "medium",
        "TimeRangeList": [{"week": i, "TimeRange": [{"id": 1, "beginTime": "00:00", "endTime": "24:00"}]} for i in range(1, 8)]
    }
}
STROBE_OFF_PAYLOAD = {
    "WhiteLightAlarm": {
        "channelID": 1,
        "durationTime": DURATION_MINUTES * 60,  # Convert minutes to seconds
        "frequency": "medium",
        "TimeRangeList": [{"week": i, "TimeRange": []} for i in range(1, 8)]
    }
}
STROBE_URL = f'{BASE_URL}/ISAPI/Event/triggers/notifications/channels/1/whiteLightAlarm?format=json'

# Audio Alarm Endpoints
AUDIO_ON_PAYLOAD = {
    "AudioAlarm": {
        "audioID": 2,
        "audioVolume": 51,
        "alarmTimes": 1,
        "TimeRangeList": [{"week": i, "TimeRange": [{"id": 1, "beginTime": "00:00", "endTime": "24:00"}]} for i in range(1, 8)],
        "audioClass": "alertAudio",
        "alertAudioID": 2,
        "customAudioID": -1
    }
}
AUDIO_OFF_PAYLOAD = {
    "AudioAlarm": {
        "audioID": 2,
        "audioVolume": 51,
        "alarmTimes": 1,
        "TimeRangeList": [{"week": i, "TimeRange": []} for i in range(1, 8)],
        "audioClass": "alertAudio",
        "alertAudioID": 2,
        "customAudioID": -1
    }
}
AUDIO_ALARM_URL = f'{BASE_URL}/ISAPI/Event/triggers/notifications/AudioAlarm?format=json'

# Headers
headers = {'Content-Type': 'application/json'}

def send_request(url, payload=None):
    response = requests.put(url, auth=(USERNAME, PASSWORD), headers=headers, data=json.dumps(payload))
    if response.status_code == 200:
        print(f"Command to {url} successful.")
    else:
        print(f"Failed to send command to {url}. Status code: {response.status_code}, Response: {response.text}")

def activate_alarms():
    print("Activating strobe and audio alarms...")
    send_request(STROBE_URL, STROBE_ON_PAYLOAD)  # Turn strobe on
    send_request(AUDIO_ALARM_URL, AUDIO_ON_PAYLOAD)  # Turn audio alarm on

def deactivate_alarms():
    print("Deactivating strobe and audio alarms...")
    send_request(STROBE_URL, STROBE_OFF_PAYLOAD)  # Turn strobe off
    send_request(AUDIO_ALARM_URL, AUDIO_OFF_PAYLOAD)  # Turn audio alarm off

if __name__ == '__main__':
    activate_alarms()  # Activate alarms
    time.sleep(DURATION_MINUTES * 60)  # Wait for the specified duration
    deactivate_alarms()  # Deactivate alarms

Last thing to do is configure BlueIris to activate the .py file on an alert of your choice.

Useful notes

curl -X GET "http://admin:PassworD@<cameraip>/ISAPI/ContentMgmt/capabilities"

Leave a Reply