diff --git a/bundles/org.openhab.binding.ipcamera/README.md b/bundles/org.openhab.binding.ipcamera/README.md index 375c4c4b2c20f..1b844fec5311c 100644 --- a/bundles/org.openhab.binding.ipcamera/README.md +++ b/bundles/org.openhab.binding.ipcamera/README.md @@ -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 @@ -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. diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java index d7e5f30fb8cd1..7b864df29e394 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraActions.java @@ -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(); + } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java index 6a7a5c5310bdd..d428ac80fe5fe 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/IpCameraBindingConstants.java @@ -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"; } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java index 2d40759ca6c48..21a8a6330e83e 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/ReolinkHandler.java @@ -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); } @@ -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; } } @@ -599,4 +593,8 @@ public void handleCommand(ChannelUID channelUID, Command command) { public List getLowPriorityRequests() { return List.of(); } + + public void reboot() { + ipCameraHandler.sendHttpPOST("/api.cgi?cmd=Reboot" + ipCameraHandler.reolinkAuth, "[{\"cmd\":\"Reboot\"}]"); + } } diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java index f80a3e9c4dbae..549df320eb540 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/handler/IpCameraHandler.java @@ -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\":\"" diff --git a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/i18n/ipcamera.properties b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/i18n/ipcamera.properties index 45d69429ab8eb..c7f520ac53406 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/i18n/ipcamera.properties +++ b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/i18n/ipcamera.properties @@ -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 @@ -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 @@ -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 diff --git a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml index eb6302413a31e..1a5551cc5e5b4 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml +++ b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/thing/thing-types.xml @@ -2345,11 +2345,10 @@ - - 3 + 2 @@ -3192,10 +3191,4 @@ Turn the automatic mode for tracking ON or OFF. - - - Switch - - The camera is rebooted when switched ON - diff --git a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/update/instructions.xml b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/update/instructions.xml index 4b7a156a4e9ec..c06880ebe82f4 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/update/instructions.xml +++ b/bundles/org.openhab.binding.ipcamera/src/main/resources/OH-INF/update/instructions.xml @@ -23,11 +23,6 @@ ipcamera:autoTracking - - - ipcamera:reboot - -