{"id":170,"date":"2024-03-01T16:33:14","date_gmt":"2024-03-02T00:33:14","guid":{"rendered":"https:\/\/www.liljegrens.org\/?p=170"},"modified":"2024-03-03T11:11:14","modified_gmt":"2024-03-03T19:11:14","slug":"hikvision-strobe-with-blueiris","status":"publish","type":"post","link":"https:\/\/www.liljegrens.org\/?p=170","title":{"rendered":"Hikvision strobe with BlueIris"},"content":{"rendered":"\n<p>Using BlueIris triggers to activate the strobe and audio alarm on Hikvision cameras.<\/p>\n\n\n\n<p>BlueIris is going to invoke a python script which uses ISAPI to activate the strobe and or audio alarm.  It&#8217;s kinda janky in how it works but it does work.  In the camera&#8217;s menu navigate to: Event&gt; Basic Event&gt; Alarm Input.  The magic field is the Alarm Type, we&#8217;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.  <\/p>\n\n\n\n<p>First we need to install python onto our machine which BlueIris runs.  <\/p>\n\n\n\n<p> <a href=\"https:\/\/www.python.org\/downloads\/windows\/\">https:\/\/www.python.org\/downloads\/windows\/<\/a><\/p>\n\n\n\n<p>Make sure to &#8220;Add Python to PATH&#8221; during installation.  Our script uses the Requests library an it is installed with pip at the command line.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install requests<\/code><\/pre>\n\n\n\n<p>The script is fairly basic in functions, it&#8217;s a start.  Security isn&#8217;t too secure either with this method.  Your password is stored and transferred in open text, don&#8217;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<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import requests\nimport json\nimport time\n\n# Camera details\nCAMERA_IP = '192.168.X.X'  # Change to your cameras addy\nUSERNAME = 'admin'\nPASSWORD = 'password'  # Change to your admin password\n\n# Duration in minutes\nDURATION_MINUTES = 1  # Change this value as needed\n\n# Base URL\nBASE_URL = f'http:\/\/{CAMERA_IP}'\n\n# Strobe Light Endpoints and Payloads\nSTROBE_ON_PAYLOAD = {\n    \"WhiteLightAlarm\": {\n        \"channelID\": 1,\n        \"durationTime\": DURATION_MINUTES * 60,\n        \"frequency\": \"medium\",\n        \"TimeRangeList\": &#91;{\"week\": i, \"TimeRange\": &#91;{\"id\": 1, \"beginTime\": \"00:00\", \"endTime\": \"24:00\"}]} for i in range(1, 8)]\n    }\n}\nSTROBE_OFF_PAYLOAD = {\n    \"WhiteLightAlarm\": {\n        \"channelID\": 1,\n        \"durationTime\": DURATION_MINUTES * 60,  # Convert minutes to seconds\n        \"frequency\": \"medium\",\n        \"TimeRangeList\": &#91;{\"week\": i, \"TimeRange\": &#91;]} for i in range(1, 8)]\n    }\n}\nSTROBE_URL = f'{BASE_URL}\/ISAPI\/Event\/triggers\/notifications\/channels\/1\/whiteLightAlarm?format=json'\n\n# Audio Alarm Endpoints\nAUDIO_ON_PAYLOAD = {\n    \"AudioAlarm\": {\n        \"audioID\": 2,\n        \"audioVolume\": 51,\n        \"alarmTimes\": 1,\n        \"TimeRangeList\": &#91;{\"week\": i, \"TimeRange\": &#91;{\"id\": 1, \"beginTime\": \"00:00\", \"endTime\": \"24:00\"}]} for i in range(1, 8)],\n        \"audioClass\": \"alertAudio\",\n        \"alertAudioID\": 2,\n        \"customAudioID\": -1\n    }\n}\nAUDIO_OFF_PAYLOAD = {\n    \"AudioAlarm\": {\n        \"audioID\": 2,\n        \"audioVolume\": 51,\n        \"alarmTimes\": 1,\n        \"TimeRangeList\": &#91;{\"week\": i, \"TimeRange\": &#91;]} for i in range(1, 8)],\n        \"audioClass\": \"alertAudio\",\n        \"alertAudioID\": 2,\n        \"customAudioID\": -1\n    }\n}\nAUDIO_ALARM_URL = f'{BASE_URL}\/ISAPI\/Event\/triggers\/notifications\/AudioAlarm?format=json'\n\n# Headers\nheaders = {'Content-Type': 'application\/json'}\n\ndef send_request(url, payload=None):\n    response = requests.put(url, auth=(USERNAME, PASSWORD), headers=headers, data=json.dumps(payload))\n    if response.status_code == 200:\n        print(f\"Command to {url} successful.\")\n    else:\n        print(f\"Failed to send command to {url}. Status code: {response.status_code}, Response: {response.text}\")\n\ndef activate_alarms():\n    print(\"Activating strobe and audio alarms...\")\n    send_request(STROBE_URL, STROBE_ON_PAYLOAD)  # Turn strobe on\n    send_request(AUDIO_ALARM_URL, AUDIO_ON_PAYLOAD)  # Turn audio alarm on\n\ndef deactivate_alarms():\n    print(\"Deactivating strobe and audio alarms...\")\n    send_request(STROBE_URL, STROBE_OFF_PAYLOAD)  # Turn strobe off\n    send_request(AUDIO_ALARM_URL, AUDIO_OFF_PAYLOAD)  # Turn audio alarm off\n\nif __name__ == '__main__':\n    activate_alarms()  # Activate alarms\n    time.sleep(DURATION_MINUTES * 60)  # Wait for the specified duration\n    deactivate_alarms()  # Deactivate alarms\n\n<\/code><\/pre>\n\n\n\n<p>Last thing to do is configure BlueIris to activate the .py file on an alert of your choice.  <\/p>\n\n\n\n<p>Useful notes<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>curl -X GET \"http:\/\/admin:PassworD@&lt;cameraip>\/ISAPI\/ContentMgmt\/capabilities\"<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using BlueIris triggers to activate the strobe and audio alarm on Hikvision cameras. BlueIris is going to invoke a python<\/p>\n<p><a href=\"https:\/\/www.liljegrens.org\/?p=170\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\">Hikvision strobe with BlueIris<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/posts\/170"}],"collection":[{"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=170"}],"version-history":[{"count":3,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=\/wp\/v2\/posts\/170\/revisions\/179"}],"wp:attachment":[{"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.liljegrens.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}