Skip to content

Commit

Permalink
Convert reolink reboot channel to an ipcamera action.
Browse files Browse the repository at this point in the history
Signed-off-by: Simmon Yau <[email protected]>
  • Loading branch information
simmonyau committed Mar 1, 2025
1 parent 987c3dd commit b5da329
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 34 deletions.
11 changes: 10 additions & 1 deletion bundles/org.openhab.binding.ipcamera/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,6 @@ The channels are kept consistent as much as possible from brand to brand to make
| `exitButtonEnabled` | Switch | RW | This channel could be used to disable the exit button to provide additional security at night or when noone is home. |
| `motionDetectionLevel` | Number | RW | Controls camera's built-in motion detection sensitivity. |
| `magneticLockWarning` | Switch | R | This alarm will trigger if the door was opened while the lock is closed, signalling possible intrusion alarm. |
| `reboot` | Switch | W | Reboots camera when turned ON

## Moving PTZ Cameras

Expand Down Expand Up @@ -704,6 +703,16 @@ then
end
```

## How To Reboot Camera
```
rule "Reboot Camera At 12:00 AM"
when
Time cron "0 0 0 ? *"
then
getActions("ipcamera", "ipcamera:reolink:1a40bbe041").reboot()
end
```

## HABpanel

This section is about how to get things working in HABpanel.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,17 @@ public void recordGIF(
public static void recordGIF(ThingActions actions, @Nullable String filename, int secondsToRecord) {
((IpCameraActions) actions).recordGIF(filename, secondsToRecord);
}

@RuleAction(label = "reboot", description = "Reboot camera")
public void reboot() {
logger.debug("Rebooting camera.");
IpCameraHandler localHandler = handler;
if (localHandler != null) {
localHandler.reboot();
}
}

public static void reboot(@Nullable ThingActions actions) {
((IpCameraActions) actions).reboot();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,4 @@ public enum FFmpegFormat {
public static final String CHANNEL_MOTION_DETECTION_LEVEL = "motionDetectionLevel";
public static final String CHANNEL_EXIT_BUTTON_ENABLED = "exitButtonEnabled";
public static final String CHANNEL_MAGNETIC_LOCK_WARNING = "magneticLockWarning";
public static final String CHANNEL_REBOOT = "reboot";
}
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public void channelRead(@Nullable ChannelHandlerContext ctx, @Nullable Object ms
}
break;
case "/api.cgi?cmd=Reboot":
ipCameraHandler.setChannelState(CHANNEL_REBOOT, OnOffType.OFF);
// This handles reboot action response.
if (!content.contains("\"rspCode\" : 200")) {
ipCameraHandler.logger.warn("Reboot failed:\n{}", content);
}
Expand Down Expand Up @@ -585,12 +585,6 @@ public void handleCommand(ChannelUID channelUID, Command command) {
+ ipCameraHandler.cameraConfig.getNvrChannel() + " }}]");
}
break;
case CHANNEL_REBOOT:
if (OnOffType.ON.equals(command)) {
ipCameraHandler.sendHttpPOST("/api.cgi?cmd=Reboot" + ipCameraHandler.reolinkAuth,
"[{\"cmd\":\"Reboot\"}]");
}
break;
}
}

Expand All @@ -599,4 +593,8 @@ public void handleCommand(ChannelUID channelUID, Command command) {
public List<String> getLowPriorityRequests() {
return List.of();
}

public void reboot() {
ipCameraHandler.sendHttpPOST("/api.cgi?cmd=Reboot" + ipCameraHandler.reolinkAuth, "[{\"cmd\":\"Reboot\"}]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1059,6 +1059,17 @@ public void recordGif(String filename, int seconds) {
setChannelState(CHANNEL_RECORDING_GIF, DecimalType.valueOf(new String("" + seconds)));
}

public void reboot() {
switch (thing.getThingTypeUID().getId()) {
case REOLINK_THING:
ReolinkHandler reolinkHandler = new ReolinkHandler(getHandle());
reolinkHandler.reboot();
break;
default:
logger.warn("Reboot is not yet supported for ipcamera type {}", thing.getThingTypeUID().getId());
}
}

private void getReolinkToken() {
sendHttpPOST("/api.cgi?cmd=Login",
"[{\"cmd\":\"Login\", \"param\":{ \"User\":{ \"Version\": \"0\", \"userName\":\""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -522,16 +522,16 @@ thing-type.config.ipcamera.onvif.motionOptions.label = Motion Options
thing-type.config.ipcamera.onvif.motionOptions.description = This gives you direct access to specify your own FFmpeg options to be used for detecting motion.
thing-type.config.ipcamera.onvif.mp4OutOptions.label = MP4 Out Options
thing-type.config.ipcamera.onvif.mp4OutOptions.description = This gives you direct access to specify your own FFmpeg options to be used for recording MP4 files.
thing-type.config.ipcamera.onvif.onvifEventServiceType.label = ONVIF event method:
thing-type.config.ipcamera.onvif.onvifMediaProfile.label = ONVIF Media Profile
thing-type.config.ipcamera.onvif.onvifMediaProfile.description = Cameras can supply more than one stream at different resolutions and formats. 0 selects the main-stream and 1 or above are the sub-streams. Sometimes you need to turn on sub-streams in the cameras setup before they can be used.
thing-type.config.ipcamera.onvif.onvifPort.label = ONVIF Port
thing-type.config.ipcamera.onvif.onvifPort.description = The port your camera uses for ONVIF connections. This is needed for PTZ movement, alarm events and auto discovery of RTSP and snapshot URLs.
thing-type.config.ipcamera.onvif.onvifEventServiceType.label = ONVIF event method
thing-type.config.ipcamera.onvif.onvifEventServiceType.description = ONVIF event method to use. If camera does not report event capabilities, the event method can be forced here.
thing-type.config.ipcamera.onvif.onvifEventServiceType.option.0 = Auto detect (0)
thing-type.config.ipcamera.onvif.onvifEventServiceType.option.1 = Disabled (1)
thing-type.config.ipcamera.onvif.onvifEventServiceType.option.2 = Force PullMessages (2)
thing-type.config.ipcamera.onvif.onvifEventServiceType.option.3 = Force WSBaseSubscription (3)
thing-type.config.ipcamera.onvif.onvifMediaProfile.label = ONVIF Media Profile
thing-type.config.ipcamera.onvif.onvifMediaProfile.description = Cameras can supply more than one stream at different resolutions and formats. 0 selects the main-stream and 1 or above are the sub-streams. Sometimes you need to turn on sub-streams in the cameras setup before they can be used.
thing-type.config.ipcamera.onvif.onvifPort.label = ONVIF Port
thing-type.config.ipcamera.onvif.onvifPort.description = The port your camera uses for ONVIF connections. This is needed for PTZ movement, alarm events and auto discovery of RTSP and snapshot URLs.
thing-type.config.ipcamera.onvif.password.label = Password
thing-type.config.ipcamera.onvif.password.description = Enter the password for your camera. Leave blank if your camera does not use one.
thing-type.config.ipcamera.onvif.pollTime.label = Poll Time
Expand Down Expand Up @@ -592,16 +592,16 @@ thing-type.config.ipcamera.reolink.mp4OutOptions.label = MP4 Out Options
thing-type.config.ipcamera.reolink.mp4OutOptions.description = This gives you direct access to specify your own FFmpeg options to be used for recording MP4 files.
thing-type.config.ipcamera.reolink.nvrChannel.label = NVR Input Channel
thing-type.config.ipcamera.reolink.nvrChannel.description = Set this to 0 if it is a stand alone camera, or to the input channel number of your NVR that the camera is connected to.
thing-type.config.ipcamera.reolink.onvifEventServiceType.label = ONVIF event method:
thing-type.config.ipcamera.reolink.onvifMediaProfile.label = ONVIF Media Profile
thing-type.config.ipcamera.reolink.onvifMediaProfile.description = Cameras can supply more than one stream at different resolutions and formats. 0 selects the main-stream and 1 or above are the sub-streams. Sometimes you need to turn on sub-streams in the cameras setup before they can be used.
thing-type.config.ipcamera.reolink.onvifPort.label = ONVIF Port
thing-type.config.ipcamera.reolink.onvifPort.description = The port your camera uses for ONVIF connections. This is needed for PTZ movement, alarm events and auto discovery of RTSP and snapshot URLs.
thing-type.config.ipcamera.reolink.onvifEventServiceType.label = ONVIF event method
thing-type.config.ipcamera.reolink.onvifEventServiceType.description = ONVIF event method to use. If camera does not report event capabilities, the event method can be forced here.
thing-type.config.ipcamera.reolink.onvifEventServiceType.option.0 = Auto detect (0)
thing-type.config.ipcamera.reolink.onvifEventServiceType.option.1 = Disabled (1)
thing-type.config.ipcamera.reolink.onvifEventServiceType.option.2 = Force PullMessages (2)
thing-type.config.ipcamera.reolink.onvifEventServiceType.option.3 = Force WSBaseSubscription (3)
thing-type.config.ipcamera.reolink.onvifMediaProfile.label = ONVIF Media Profile
thing-type.config.ipcamera.reolink.onvifMediaProfile.description = Cameras can supply more than one stream at different resolutions and formats. 0 selects the main-stream and 1 or above are the sub-streams. Sometimes you need to turn on sub-streams in the cameras setup before they can be used.
thing-type.config.ipcamera.reolink.onvifPort.label = ONVIF Port
thing-type.config.ipcamera.reolink.onvifPort.description = The port your camera uses for ONVIF connections. This is needed for PTZ movement, alarm events and auto discovery of RTSP and snapshot URLs.
thing-type.config.ipcamera.reolink.password.label = Password
thing-type.config.ipcamera.reolink.password.description = Enter the password for your camera. Leave blank if your camera does not use one.
thing-type.config.ipcamera.reolink.pollTime.label = Poll Time
Expand Down Expand Up @@ -777,8 +777,6 @@ channel-type.ipcamera.pirAlarm.label = PIR Alarm
channel-type.ipcamera.pirAlarm.description = PIR motion has been detected.
channel-type.ipcamera.pollImage.label = Poll Image
channel-type.ipcamera.pollImage.description = This can be used to trigger snapshot updates when an external PIR, button or other form of sensor turns this channel ON.
channel-type.ipcamera.reboot.label = Reboot
channel-type.ipcamera.reboot.description = The camera is rebooted when switched ON
channel-type.ipcamera.recordingGif.label = GIF Recording
channel-type.ipcamera.recordingGif.description = Indicates how long the recording will occur for and when the file is created, the channel will change to 0 by itself.
channel-type.ipcamera.recordingMp4.label = MP4 Recording
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2345,11 +2345,10 @@
<channel id="enableEmail" typeId="enableEmail"/>
<channel id="enablePush" typeId="enablePush"/>
<channel id="autoTracking" typeId="autoTracking"/>
<channel id="reboot" typeId="reboot"/>
</channels>

<properties>
<property name="thingTypeVersion">3</property>
<property name="thingTypeVersion">2</property>
</properties>

<config-description>
Expand Down Expand Up @@ -3192,10 +3191,4 @@
<label>Auto Tracking</label>
<description>Turn the automatic mode for tracking ON or OFF.</description>
</channel-type>

<channel-type id="reboot" advanced="true">
<item-type>Switch</item-type>
<label>Reboot</label>
<description>The camera is rebooted when switched ON</description>
</channel-type>
</thing:thing-descriptions>
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,6 @@
<type>ipcamera:autoTracking</type>
</add-channel>
</instruction-set>
<instruction-set targetVersion="3">
<add-channel id="reboot">
<type>ipcamera:reboot</type>
</add-channel>
</instruction-set>
</thing-type>

<thing-type uid="ipcamera:dahua">
Expand Down

0 comments on commit b5da329

Please sign in to comment.