Relay Control & IoT Automation API
Viewtron IP cameras and NVRs include hardware alarm relay outputs that can be triggered via HTTP API calls. This enables IoT automation workflows where AI detection events from the camera drive physical actions in the real world — opening gates, activating lights, triggering external alarm panels, or controlling any device connected to the relay output. All processing runs on local hardware with no cloud dependency.
The API provides two relay control mechanisms: ManualAlarmOut for directly triggering a physical relay output on the camera or NVR, and TriggerVirtualAlarm (NVR v2.0 only) for triggering virtual alarm inputs that can activate NVR recording, push notifications, and relay outputs on specific channels. Both endpoints accept standard HTTP requests with Basic authentication. All Viewtron IP cameras and NVRs are NDAA compliant.
A working real-world example of this API is the ESP8266 relay controller project on GitHub, which uses Viewtron camera traject data for continuous human detection to control an ESP8266-based relay module.
What You Can Build
- Gate access control — combine with license plate recognition to open gates for authorized vehicles
- Lighting automation — activate lights when a person is detected at night, deactivate after a timeout
- Alarm panel integration — trigger wired alarm panel zones from camera AI detection events
- Home automation — connect camera events to smart home relays for HVAC, locks, or irrigation
- Industrial automation — trigger conveyor belts, safety shutoffs, or indicators based on human/vehicle detection
- ESP8266/Arduino control — use microcontrollers as intermediary relay controllers driven by camera webhook events
How It Works
- Camera detects an event — human detection, LPR, line crossing, or other AI detection triggers a webhook POST to your server
- Your server processes the event — verify target type, check authorization lists, evaluate time-based rules
- Send relay command — call
ManualAlarmOuton the camera/NVR to trigger the physical relay output - Or trigger a virtual alarm — call
TriggerVirtualAlarmon the NVR to activate recording and notifications on a specific channel - Reset after timeout — send a follow-up API call to release the relay after the desired duration
Relay Control Endpoints
ManualAlarmOut
Directly triggers or releases a physical alarm relay output.
| Field | Value |
|---|---|
| URL | POST http://<host>[:port]/ManualAlarmOut[/channelId] |
| Products | IPC, NVR |
| Auth | HTTP Basic (admin credentials) |
Trigger relay (activate):
<?xml version="1.0" encoding="UTF-8"?>
<config version="1.0" xmlns="http://www.ipc.com/ver10">
<action>
<status>true</status>
</action>
</config>
Release relay (deactivate):
<?xml version="1.0" encoding="UTF-8"?>
<config version="1.0" xmlns="http://www.ipc.com/ver10">
<action>
<status>false</status>
</action>
</config>
On IPC cameras, the firmware forcibly resets the alarm output when a perimeter alarm cycle ends, even when alarm output mode is set to manual_alarm and triggerAlarmOut is unchecked. This makes ManualAlarmOut unreliable for automation while perimeter detection is active on the same camera. NVR alarm outputs are not affected by this bug.
TriggerVirtualAlarm (NVR v2.0 Only)
Triggers a virtual alarm input on the NVR, which can activate recording, push notifications, and relay outputs on specific channels.
| Field | Value |
|---|---|
| URL | GET http://<host>[:port]/TriggerVirtualAlarm/{virtualAlarmId} |
| Products | NVR only |
| Auth | HTTP Basic (admin credentials) |
Virtual alarm ID calculation: IDs start after physical alarm inputs. If the NVR has 16 physical alarms, virtual alarm 1 = ID 17, virtual alarm 2 = ID 18, etc. Use GetAlarmInInfo to see the full list.
curl -u admin:password "http://192.168.0.147/TriggerVirtualAlarm/17"
Parsing Detection Events and Triggering Relays
- Python SDK
- Node.js SDK
- NVR XML (v2.0)
- IPC XML (v1.x)
The simplest way to receive detection events and trigger relays. The SDK's ViewtronServer handles incoming webhooks while ViewtronCamera sends outbound relay commands:
pip install viewtron
from viewtron import ViewtronServer, ViewtronCamera
import os
import threading
IMG_DIR = "images"
os.makedirs(IMG_DIR, exist_ok=True)
# NVR credentials for relay control
nvr = ViewtronCamera("192.168.0.147", "admin", "password")
RELAY_DURATION = 15
def on_event(event, client_ip):
if event.category != "intrusion":
return
print(f"Person detected from {client_ip} — triggering relay")
print(f" Type: {event.get_alarm_description()}")
overview = event.get_source_image_bytes()
if overview:
with open(f"{IMG_DIR}/{event.get_time_stamp()}-relay-overview.jpg", "wb") as f:
f.write(overview)
# Trigger relay on NVR
nvr.set_alarm_out(True)
threading.Timer(RELAY_DURATION, lambda: nvr.set_alarm_out(False)).start()
server = ViewtronServer(port=5002, on_event=on_event)
server.serve_forever()
See the Python SDK reference for the full list of methods and event classes.
npm install viewtron-sdk
const { ViewtronServer, ViewtronCamera } = require('viewtron-sdk');
const fs = require('fs');
fs.mkdirSync('images', { recursive: true });
const nvr = new ViewtronCamera('192.168.0.147', 'admin', 'password');
const RELAY_DURATION = 15000; // ms
const server = new ViewtronServer({ port: 5002 });
server.on('event', (event, clientIP) => {
if (event.category !== 'intrusion') return;
console.log(`Person detected from ${clientIP} — triggering relay`);
console.log(` Type: ${event.eventType} (${event.targetType})`);
if (event.sourceImageBytes) {
fs.writeFileSync(
`images/${Date.now()}-relay-overview.jpg`,
event.sourceImageBytes
);
}
// Trigger relay on NVR
nvr.setAlarmOut(true);
setTimeout(() => nvr.setAlarmOut(false), RELAY_DURATION);
});
server.start();
The NVR v2.0 regionIntrusion format provides the detection data that triggers relay actions:
<?xml version="1.0" encoding="UTF-8"?>
<config version="2.0.0" xmlns="http://www.ipc.com/ver10">
<messageType>alarmData</messageType>
<deviceInfo>
<deviceName><![CDATA[Front Door]]></deviceName>
<ip><![CDATA[192.168.0.55]]></ip>
<mac><![CDATA[58:5B:69:40:F4:0D]]></mac>
<channelId>1</channelId>
</deviceInfo>
<smartType>regionIntrusion</smartType>
<currentTime>1772056914604000</currentTime>
<eventInfo>
<item>
<eventId>916</eventId>
<targetId>716</targetId>
<boundary>area</boundary>
<pointGroup>
<item><x>1590</x><y>3080</y></item>
<item><x>4715</x><y>3181</y></item>
<item><x>4772</x><y>9217</y></item>
<item><x>416</x><y>9141</y></item>
</pointGroup>
<rect><x1>3096</x1><y1>3715</y1><x2>4005</x2><y2>9861</y2></rect>
</item>
</eventInfo>
<sourceDataInfo>
<sourceBase64Length>400924</sourceBase64Length>
<sourceBase64Data>... (base64 JPEG) ...</sourceBase64Data>
</sourceDataInfo>
<targetListInfo>
<item>
<targetId>716</targetId>
<targetType>person</targetType>
<targetImageData>
<targetBase64Length>78796</targetBase64Length>
<targetBase64Data>... (base64 JPEG) ...</targetBase64Data>
</targetImageData>
</item>
</targetListInfo>
</config>
After parsing this event, your application sends a ManualAlarmOut or TriggerVirtualAlarm request to the NVR.
The IPC v1.x format uses PEA smartType:
<?xml version="1.0" encoding="UTF-8" ?>
<config version="1.7" xmlns="http://www.ipc.com/ver10">
<smartType type="openAlramObj">PEA</smartType>
<deviceName type="string"><![CDATA[FrontDoor]]></deviceName>
<currentTime type="tint64">1774792701902505</currentTime>
<perimeter>
<perInfo type="list" count="1">
<item>
<eventId type="uint32">2357</eventId>
<targetId type="uint32">2157</targetId>
<status type="perStatus">SMART_START</status>
<boundary type="list" count="4">
<item><point><x type="uint32">450</x><y type="uint32">466</y></point></item>
<!-- additional polygon points -->
</boundary>
<rect>
<x1 type="uint32">4403</x1><y1 type="uint32">694</y1>
<x2 type="uint32">5909</x2><y2 type="uint32">8125</y2>
</rect>
</item>
</perInfo>
</perimeter>
<!-- sourceDataInfo and listInfo with base64 images -->
</config>
ESP8266 Relay Controller Project
A complete real-world example using an ESP8266 microcontroller as a relay controller is available in the IP-Camera-API GitHub repository. This project uses Viewtron camera httpPostV2 traject data for continuous human detection to keep a relay active as long as a person is present in the camera's field of view. When the person leaves and traject data stops, the relay deactivates after a configurable timeout.
This approach solves the limitation of perimeterAlarm — which drops to false during the 5-20 second gaps between alarm cycles even if the person is still present — by using continuous traject position data instead.
Relevant API Endpoints
| Endpoint | Purpose | Reference |
|---|---|---|
| ManualAlarmOut | Trigger or release alarm relay output | Alarm Input/Output Config |
| GetAlarmOutConfig | Read alarm output relay configuration | Alarm Input/Output Config |
| TriggerVirtualAlarm | Trigger virtual alarm on NVR (v2.0) | Virtual Alarm |
| GetAlarmStatus | Poll current alarm state | Alarm Status |
| SetHttpPostConfig | Configure webhook destination for detection events | Webhook Config |
Integrations
Viewtron relay control also integrates with automation platforms via published packages:
| Platform | Package | What It Does |
|---|---|---|
| Home Assistant | viewtron-home-assistant | Detection events as native HA sensors — trigger relays via HA automations |
| Node-RED | node-red-contrib-viewtron | Detection events direct to Node-RED flows — build relay logic visually |
Related Applications
- Human Detection & Intrusion — detection events that trigger relay actions
- License Plate Recognition — LPR events for gate access control
- Active Deterrent — siren and strobe control via alarm outputs
- Real-Time Object Tracking — continuous traject data for presence-based relay control
Related Products
- Viewtron AI Security Cameras — IP cameras with alarm relay outputs and AI detection
- Viewtron IP Camera NVRs — NVRs with multiple alarm relay outputs and virtual alarm support
Questions & Development Inquiries
- Email: mike@viewtron.com
- Phone: 561-433-8488
- Forum: NVR Webhook Setup Guide
Mike Haldas is available for questions, consultation, and custom software development for Viewtron API related projects. Email details about your project to mike@viewtron.com.