@rustyd0g/scrypted-daynightswitcher
v1.0.7
Published
Per-camera sunrise/sunset day/night profile switcher.
Maintainers
Readme
Day/Night Switcher (Scrypted Plugin)
Automatically switch each camera to your preferred Day or Night profile at sunrise and sunset. Works with cameras that expose HTTP endpoints (Hikvision, Dahua, Amcrest, EmpireTech, etc.).
- Per-camera control with global defaults
- Offsets around sunrise/sunset (e.g. switch 10 min after sunset)
- Manual run buttons (Switch to Day/Night now)
- Retries & backoff for reliability
- Digest / Basic / None authentication
- Schedule preview with local time and time zone
Quick Start
- Disable your camera’s built-in day/night schedule (set it to Manual/Fixed/Full Time).
- In the plugin’s Global settings, enter your Latitude/Longitude (On desktop: right-click anywhere on Google Maps → coordinates appear at the top. On mobile: long-press to drop a pin, then swipe up to copy).
- For each camera, open Day/Night Switcher settings, configure the Day/Night URLs + Method, and enable switching.
How it works
- Each day, the plugin calculates sunrise and sunset times based on your latitude and longitude, applying any configured offsets.
- At those scheduled times, it sends the configured HTTP request using the URL and method you entered.
- Requests can include authentication (Digest, Basic, or None), headers, and an optional body. Retries with increasing delays are supported for reliability.
- The plugin automatically refreshes the schedule every day and displays the next planned switch times in your local time zone.
Installation
- Install the plugin in Scrypted.
- In Global settings, configure Latitude and Longitude (and optionally Time zone).
- For each camera, configure Day/Night actions and enable switching.
Camera-side setup (critical)
Before configuring the plugin, prevent the camera’s own schedule or auto logic from conflicting with your commands:
- Disable automatic day/night switching in the camera’s web UI. Look for Profile Schedule, Day/Night Mode, Scene Mode, etc., and set to Manual/Fixed/Full Time.
- Prepare the profiles/scenes you want the plugin to trigger (e.g. a “Day” profile and a “Night” profile).
- Apply & reboot if required by your camera’s UI.
You’ll also need the correct HTTP endpoints for your model/firmware:
- Check the manufacturer’s API docs or community forums.
- Useful search terms:
<brand> <model> http api,ISAPI,configManager.cgi,cgi day night,profile switch. - Test first with curl or Postman; once working, copy the URL/Method/Headers/Body into the plugin.
Global settings
Latitude / Longitude — decimal degrees (e.g.
51.507351, -0.127758).Time zone (optional) — standard time zone ID (e.g.
Europe/London). It does not affect when the switch happens (that’s always based on sunrise/sunset at your latitude/longitude).Use 24-hour time — UI display preference.
Sync phase on startup — immediately corrects the camera if its current mode doesn’t match the expected phase.
Sunrise / Sunset offset (mins, default) — defaults for all cameras (can be overridden per camera).
Reliability defaults:
- HTTP total attempts — total tries including the first attempt (
1disables retries). - Retry base delay (ms) — waits longer between retries (with added jitter).
- Log HTTP responses — log status and response body (chunked, capped).
- HTTP total attempts — total tries including the first attempt (
Per-camera settings
Enable Day/Night switching — master on/off.
Override location & time — per-camera lat/lon/time if needed.
Override sunrise/sunset offsets — per-camera offsets (mins; positive = after, negative = before).
Authentication:
- Auth Type —
digest,basic, ornone. - Username / Password — used by the plugin (don’t embed credentials in URLs).
- Auth Type —
Day / Night actions:
- URL — camera endpoint to trigger the mode.
- Method —
GET,POST,PUT,PATCH, orDELETE. - Content-Type — only when sending a Body.
- Extra Headers (JSON) — e.g.
{"Accept":"application/xml"}. - Body — optional request body for POST/PUT/PATCH/DELETE.
Reliability & Logging (per camera) — override global retries/backoff/logging.
Tools (General tab):
- Schedule preview — shows next switch times and configuration summary.
- Switch to Day/Night now — fire actions immediately (useful for testing).
Scheduling details
- The plugin maintains two scheduled events: Sunrise → Day and Sunset → Night.
- These times are updated daily at midnight (with offsets applied).
- After each event runs, the schedule is refreshed to ensure accuracy.
- A guard timer re-checks periodically (every 6 hours by default) to catch long sleeps or restarts.
Configuration examples (tested models)
⚠️ Important: The following examples are confirmed on specific models/firmware. Other cameras may offer different options or use different endpoints.
Hikvision (ISAPI profile switching)
✅ Confirmed on:
- DS-2CD2347G2H-LIU (Firmware V5.7.19 build 241207)
- DS-2CD2387G2H-LIU (Firmware V5.7.19 build 241207)
What it does: Switches the camera into one of its Scene Modes (for example: custom1, custom2, basic, or low illumination).
Before you use the plugin: In the Hikvision web UI → Configuration → Image → Display Settings → Scene Mode:
- Configure
custom1with your preferred Day settings. - Configure
custom2with your preferred Night settings.
Day Action (UI fields):
URL:
http://CAMERA_IP/ISAPI/Image/channels/1/mountingScenarioMethod:
PUTContent-Type:
application/xmlBody:
<MountingScenario><mode>custom1</mode></MountingScenario>
Night Action (UI fields):
URL:
http://CAMERA_IP/ISAPI/Image/channels/1/mountingScenarioMethod:
PUTContent-Type:
application/xmlBody:
<MountingScenario><mode>custom2</mode></MountingScenario>
Dahua / Amcrest / EmpireTech
✅ Confirmed on:
- IPC-HDW5442TM-AS (Firmware V2.840.0000000.30.R, Build Date: 2025-02-27)
What it does: Toggles the Day/Night mode setting to Day (0) or Night (1), applying the profile you’ve configured for each.
Before you use the plugin: In the Dahua web UI → Setup → Camera → Conditions → Day/Night, confirm you can manually set Day and Night profiles (and disable auto).
Day Action (UI fields):
URL:
http://CAMERA_IP/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=0Method:
GET
Night Action (UI fields):
URL:
http://CAMERA_IP/cgi-bin/configManager.cgi?action=setConfig&VideoInMode[0].Config[0]=1Method:
GET
Verification & troubleshooting
Initial verification
- Click Switch to Day/Night now and confirm the camera changes.
- Check the camera UI — image/IR/profile should reflect the new mode.
- Review logs — enable Log HTTP responses.
- Preview schedule — confirm displayed times look correct.
Common issues
- 401 (Unauthorized) — wrong credentials or auth type.
- 404 (Not Found) — wrong endpoint; check spelling/brackets.
- 200 but no change — auto schedule still active, or parameter mismatch.
- Network reachability — ensure Scrypted can reach the camera.
Debugging steps
- Replicate with curl/Postman.
- Check camera logs (if available).
- Search forums/docs for your model + firmware.
- Review manufacturer API notes for changes.
