TapHome

Dahua Camera — Motion Sensor

Packet Parser → HTTP
Submitted by
Last updated: 04. 2026
Dahua Camera — Motion Sensor

Dahua Technology manufactures one of the largest ranges of IP surveillance cameras on the market. Every Dahua IPC, PTZ and thermal camera with motion detection exposes an HTTP CGI endpoint that reports the current motion state — TapHome uses this endpoint to turn any Dahua camera into a binary motion sensor that can drive scenes, recordings or notifications.

The template polls a single CGI endpoint every second and maps the response to a reed-contact device: motion active or no motion. No additional hardware, cloud account or RTSP stream is required — TapHome and the camera communicate directly on the local network over plain HTTP.

Configuration

Network

The template talks to the camera on TCP port 80 using unencrypted HTTP. During template import in TapHome, enter the camera’s IP address (a DHCP reservation or static IP is recommended — Dahua cameras do not publish a stable mDNS hostname).

ParameterValue
ProtocolHTTP (port 80)
Poll interval1000 ms
Endpoint/cgi-bin/eventManager.cgi?action=getEventIndexes&code=VideoMotion
AuthenticationNone (see note below)

The template issues unauthenticated HTTP GETs. Newer Dahua firmware requires HTTP Basic or Digest authentication on every CGI call and returns a 401 Unauthorized HTML page when credentials are missing. That HTML body does not contain the string Error:No Events, so the template would flip to permanent “motion active”. You must either allow anonymous access to eventManager.cgi on the camera, or disable HTTP authentication in the camera’s security settings. If your environment requires authenticated access, place a local reverse-proxy in front of the camera that injects the credentials.

The template has UseHttps=False hardcoded and uses port 80. HTTPS-only firmware is not supported. If your camera forces HTTPS, disable it under Setting → Network → HTTPS in the Web UI.

Enabling motion detection on the camera

For getEventIndexes&code=VideoMotion to return an active state, motion detection must be explicitly enabled on the camera. Factory default on many Dahua models is disabled.

  1. Log in to the camera Web UI at http://<camera-ip>/
  2. Navigate to Setting → Event → Video Detection → Motion Detection
  3. Tick Enable and click Save
  4. Set the detection Area — paint the region(s) where motion should be tracked. The whole frame is active by default.
  5. Tune Sensitivity (0–100, higher = easier to trigger) and Threshold (0–100, lower = easier to trigger) using the live waveform. Red = motion detected, green = no motion.
  6. Configure Period (arming schedule) to cover the hours you want TapHome to react to motion (typically 24/7).
  7. Set Anti-dither to 1–5 s if you want a short back-off between consecutive events.

The camera must also have a user account with Operator or higher permissions available (required for reading eventManager.cgi when authentication is enforced).

Device capabilities

Motion state

The template exposes a single reed-contact device that reflects the current motion state of the camera:

  • Motion — the camera currently reports an active VideoMotion event
  • No motion — the camera responds with Error:No Events

The state is derived from a one-second polling script:

1
2
var VideoMotionEvent := SENDHTTPREQUEST("/cgi-bin/eventManager.cgi?action=getEventIndexes&code=VideoMotion");
return(INDEXOF(VideoMotionEvent.Content, "Error:No Events") = -1);

When motion ends, the camera holds the event active for EventHandler.Delay seconds (default 30 s) before reporting Error:No Events. The TapHome sensor therefore stays triggered up to 30 seconds after the last motion, even if the camera’s PIR logic has already released. Lower the Delay value in the camera’s event configuration for a shorter dwell time.

The TapHome sensor uses the standard i18n labels Motion (active) and No motion (idle), consistent with other binary motion sensors in the system.

Compatible models

Any Dahua IP camera that exposes the standard HTTP API v1.40 (or later) with the eventManager.cgi endpoint — this covers the vast majority of IPC-H, IPC-K, IPC-E, PTZ and thermal series released from 2013 onward. The template is agnostic to resolution, codec and lens — it only reads the binary event flag.

Troubleshooting

Sensor is permanently ON (always shows motion)

This is the most common issue and has two typical root causes:

  1. HTTP authentication is enforced on the camera. The template’s unauthenticated request is answered with a 401 Unauthorized HTML page. Because that page does not contain the literal string Error:No Events, the template reads it as “motion active”. Fix: allow anonymous access to eventManager.cgi or disable authentication on the camera.
  2. Very old firmware returns an empty body instead of Error:No Events when idle. An empty string does not contain the sentinel either, so the template reports motion continuously. Fix: update camera firmware to a version that returns the proper idle message.

Open http://<camera-ip>/cgi-bin/eventManager.cgi?action=getEventIndexes&code=VideoMotion in a browser and inspect the raw response. A healthy idle response is a plain-text body containing Error:No Events.

Sensor is permanently OFF (never shows motion)
  1. Motion detection is disabled on the camera — re-check Setting → Event → Video Detection → Motion Detection → Enable
  2. The current time falls outside the configured Period (arming schedule)
  3. The detection Area does not cover the part of the scene where motion occurs
  4. Sensitivity is too low or Threshold is too high — re-tune using the live waveform in the Web UI
  5. The camera is in its Anti-dither back-off window from the previous event
No response / timeout
  1. Verify the camera is reachable: ping <camera-ip> and open http://<camera-ip>/ in a browser
  2. Confirm HTTP on port 80 is enabled under Setting → Network → Port
  3. Confirm HTTPS is disabled (or not forced) under Setting → Network → HTTPS
  4. Check that the TapHome CCU and the camera are on the same subnet / VLAN

Available devices

Dahua Camera Module
Motion Sensor Reed Contact Read-only

Binary motion state derived from the VideoMotion event stream — reports Motion when the camera has an active event, No motion when the endpoint returns 'Error:No Events'

boolean text_contains

Motion Sensor

Read
var VideoMotionEvent := SENDHTTPREQUEST("/cgi-bin/eventManager.cgi?action=getEventIndexes&code=VideoMotion");

return(INDEXOF(VideoMotionEvent.Content, "Error:No Events") = -1);
Possible improvements (10)
  • Realtime motion push (Attach stream) — Long-lived multipart HTTP stream pushing Start/Stop events without polling. Would lower latency and bandwidth, but needs a streaming parser.
  • Smart motion — human detection — AI-filtered event that only triggers on humans; reduces false positives from rain, insects, shadows.
  • Smart motion — vehicle detection — AI-filtered event that only triggers on vehicles (cars, bikes, trucks).
  • Tripwire (line crossing) — Triggers when an object crosses a user-defined line — useful for directional detection.
  • Intrusion (region entry) — Triggers when an object enters or leaves a user-defined polygon region.
  • Camera local alarm input — State of the camera's on-board alarm input terminal (dry contact). Not exposed by this template.
  • Video loss — Useful as a diagnostic — indicates the camera sensor has lost the video signal.
  • Snapshot capture — Returns a JPEG still image — could be wired to an action trigger, but out of scope for a binary sensor template.
  • HTTP authentication — Template issues unauthenticated GETs. User must disable auth on the camera or allow anonymous access to eventManager.cgi — otherwise a 401 HTML body can be misread as permanent motion.
  • HTTPS transport — Template has UseHttps=False hardcoded and uses port 80. HTTPS-only firmware is not supported.

Sources