diff --git a/bundles/org.openhab.binding.ipcamera/README.md b/bundles/org.openhab.binding.ipcamera/README.md index e0abbe6d8274e..41a9b31755860 100644 --- a/bundles/org.openhab.binding.ipcamera/README.md +++ b/bundles/org.openhab.binding.ipcamera/README.md @@ -213,73 +213,81 @@ If you do not specify any of these, the binding will use the default which shoul Each camera brand will have different channels depending on how much of the support for an API has been added. The channels are kept consistent as much as possible from brand to brand to make upgrading to a different camera easier. -| Channel | Type | Read/Write | Description | -|-------------------------------|---------|------------|------------------------------------------------------------------------------------------| -| `activateAlarmOutput` | Switch | RW |Toggles a cameras relay output 1. | -| `activateAlarmOutput2` | Switch | RW | Toggles a cameras relay output 2. | -| `animalAlarm` | Switch | RW | Toggles when an animal is in view. | -| `audioAlarm` | Switch | R | When the camera detects noise above a threshold this switch will move to ON. | -| `autoLED` | Switch | RW |When ON this sets a cameras IR LED to automatically turn on or off. | -| `autoTracking` | Switch | RW |Turn the automatic mode for tracking ON or OFF. | -| `autoWhiteLED` | Switch | RW |When ON this sets a cameras visible white LED to automatically turn on or off. | -| `carAlarm` | Switch | RW | When a car is detected the switch will turn ON. | -| `cellMotionAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | -| `doorBell` | Switch | R | Doorbird only, will reflect the status of the doorbell button. | -| `enableAudioAlarm` | Switch | RW |Allows the audio alarm to be turned ON or OFF. | -| `enableEmail` | Switch | RW |Allows the email features to be turned ON or OFF. | -| `enableExternalAlarmInput` | Switch | RW |Hikvision and Instar allow the Alarm input terminals to be disabled by this control. | -| `enableFieldDetectionAlarm`| Switch | RW |Allows the field detection alarm to be turned ON or OFF. Some cameras will call this the Intrusion Alarm. | -| `enableFTP` | Switch | RW |Turn the cameras internal FTP recordings ON or OFF. | -| `enableLED` | Switch | RW |Turn the IR LED ON or OFF. Some cameras have 3 states the LED can be in, so see the `autoLED` channel. | -| `enableLineCrossingAlarm` | Switch | RW |Turns the line crossing alarm for API cameras, ON and OFF. | -| `enableMotionAlarm` | Switch | RW |Turns the motion alarm ON and OFF for API cameras. This will not effect FFmpeg based alarms which have their own control. | -| `enablePirAlarm` | Switch | RW |Turn PIR sensor ON or OFF. | -| `enablePush` | Switch | RW | Allows the push notification features to be turned ON or OFF. | -| `enableRecordings` | Switch | RW |Turn the cameras internal recordings ON or OFF. | -| `externalAlarmInput` | Switch | R | Reflects the status of the alarm input terminals on some cameras. | -| `externalAlarmInput2` | Switch | R | | Reflects the status of the alarm input 2 terminals on some cameras. | -| `externalLight` | Switch | RW |Some cameras have a dedicated relay output for turning lights on and off with. | -| `externalMotion` | Switch | RW |Can be used to inform the camera if it has motion in its view area. Handy if you own a PIR or any other kind of external sensor. If you use the autofps.mjpeg feature, this could increase the frame rate when a door that was closed is opened. Note: It will not be passed onto your camera and will not trigger any recordings. | -| `faceDetected` | Switch | R | When a camera detects a face (API cameras only) this switch will move to ON. | -| `fieldDetectionAlarm` | Switch | R | Reflects the cameras status for the field or intrusion alarm. | -| `ffmpegMotionAlarm` | Switch | R | The status of the FFmpeg based motion alarm. | -| `ffmpegMotionControl` | Dimmer | RW | This control allows FFmpeg to detect movement from a RTSP or HTTP source and inform openHAB. The channel that will move is called `ffmpegMotionAlarm`. | -| `gifHistory` | String | RW |The 50 most recent filenames the binding has used unless reset. | -| `gifHistoryLength` | Number | RW |How many filenames are in the `gifHistory`. | -| `gotoPreset` | String | RW |ONVIF cameras that can move only. Will cause the camera to move to a preset location. | -| `hlsUrl` | String | RW |The URL for the ipcamera.m3u8 file. | -| `humanAlarm` | Switch | RW |When a camera detects a human this switch will turn ON. | -| `imageUrl` | String | RW |The URL for the ipcamera.jpg file. | -| `itemLeft` | Switch | R | | Will turn ON if an API camera detects an item has been left behind. | -| `itemTaken` | Switch | R | Will turn ON if an API camera detects an item has been stolen. | -| `lastMotionType` | String | RW |Cameras with multiple alarm types will update this with which alarm last detected motion, i.e. a lineCrossing, faceDetection or item stolen alarm. You can also use this to create a timestamp of when the last motion was detected by creating a rule when this channel changes. | -| `lastEventData` | String | RW | Detailed information about the last smart alarm that can contain information like which Line number was crossed and in which direction. The channel `lastMotionType` will hold the name of the alarm that this data belongs to. | -| `lineCrossingAlarm` | Switch | R | Will turn on if the API camera detects motion has crossed a line. | -| `mjpegUrl` | String | RW | The URL for the ipcamera.mjpeg stream. | -| `motionAlarm` | Switch | R | The status of the 'video motion' events in ONVIF and API cameras. Also see `cellMotionAlarm` as these can give different results. | -| `mp4History` | String | RW | The 50 most recent filenames the binding has used unless reset. | -| `mp4HistoryLength` | Number | RW | How many filenames are in the `mp4History`. Setting this to 0 will clear the history. | -| `pan` | Dimmer | RW | Works with ONVIF cameras that can be moved. | -| `parkingAlarm` | Switch | R | When an API camera detects a car, this will turn ON. | -| `pirAlarm` | Switch | R | When a camera with PIR ability detects motion, this turns ON. | -| `privacyMode` | Switch | RW | Enable or disable the Privacy Mode of newer Amcrest/Dahua cameras. The camera will move the lens way down and stop the stream. | -| `recordingGif` | Number | R | How many seconds recording to GIF for. 0 when file ready. | -| `recordingMp4` | Number | R | How many seconds recording to MP4 for. 0 when file ready. | -| `rtspUrl` | String | RW | The URL for the cameras auto detected RTSP stream. | -| `sceneChangeAlarm` | Switch | R | When an API camera detects the camera has moved, this turns ON. | -| `startStream` | Switch | RW | Starts the HLS files being created, if it not manually moved it will indicate if the files are being created on demand. | -| `storageAlarm` | Switch | R | When an ONVIF cameras storage is full and/or removed, this turns ON. | -| `tamperAlarm` | Switch | R | When an ONVIF cameras tamper switch is tripped, this turns ON. | -| `textOverlay` | String | RW | Dahua, Instar and Hikvision can overlay any text you enter here over the video stream. | -| `thresholdAudioAlarm` | Dimmer | RW |This channel can be linked to a Switch and a Slider. The value of the slider is the value in dB that is detected as noise/alarm down from digital full scale. Higher values are more sensitive and will trigger the alarm with quieter / less noise. | -| `tilt` | Dimmer | RW |Works with ONVIF cameras that can be moved. | -| `triggerExternalAlarmInput` | Switch | RW | Hikvision cameras can change if the alarm input terminal is ON when high or low. This can be used to manually cause an alarm input event to occur. | -| `tooBlurryAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | -| `tooBrightAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | -| `tooDarkAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | -| `pollImage` | Switch | RW | This control can be used to manually start and stop using your CPU to create snapshots from a RTSP source. If you have a snapshot URL setup in the binding, only then can this control can be used to update the Image channel. | -| `whiteLED` | Dimmer | RW | Turn the visible white LED ON or OFF and if supported dim from 0-100%. | -| `zoom` | Dimmer | RW | Works with ONVIF cameras that can be moved. | +| Channel | Type | Read/Write | Description | +|-----------------------------|--------|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| +| `activateAlarmOutput` | Switch | RW | Toggles a cameras relay output 1. | +| `activateAlarmOutput2` | Switch | RW | Toggles a cameras relay output 2. | +| `animalAlarm` | Switch | RW | Toggles when an animal is in view. | +| `audioAlarm` | Switch | R | When the camera detects noise above a threshold this switch will move to ON. | +| `autoLED` | Switch | RW | When ON this sets a cameras IR LED to automatically turn on or off. | +| `autoTracking` | Switch | RW | Turn the automatic mode for tracking ON or OFF. | +| `autoWhiteLED` | Switch | RW | When ON this sets a cameras visible white LED to automatically turn on or off. | +| `carAlarm` | Switch | RW | When a car is detected the switch will turn ON. | +| `cellMotionAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | +| `doorBell` | Switch | R | Doorbird only, will reflect the status of the doorbell button. | +| `enableAudioAlarm` | Switch | RW | Allows the audio alarm to be turned ON or OFF. | +| `enableEmail` | Switch | RW | Allows the email features to be turned ON or OFF. | +| `enableExternalAlarmInput` | Switch | RW | Hikvision and Instar allow the Alarm input terminals to be disabled by this control. | +| `enableFieldDetectionAlarm` | Switch | RW | Allows the field detection alarm to be turned ON or OFF. Some cameras will call this the Intrusion Alarm. | +| `enableFTP` | Switch | RW | Turn the cameras internal FTP recordings ON or OFF. | +| `enableLED` | Switch | RW | Turn the IR LED ON or OFF. Some cameras have 3 states the LED can be in, so see the `autoLED` channel. | +| `enableLineCrossingAlarm` | Switch | RW | Turns the line crossing alarm for API cameras, ON and OFF. | +| `enableMotionAlarm` | Switch | RW | Turns the motion alarm ON and OFF for API cameras. This will not effect FFmpeg based alarms which have their own control. | +| `enablePirAlarm` | Switch | RW | Turn PIR sensor ON or OFF. | +| `enablePush` | Switch | RW | Allows the push notification features to be turned ON or OFF. | +| `enableRecordings` | Switch | RW | Turn the cameras internal recordings ON or OFF. | +| `externalAlarmInput` | Switch | R | Reflects the status of the alarm input terminals on some cameras. | +| `externalAlarmInput2` | Switch | R | Reflects the status of the alarm input 2 terminals on some cameras. | +| `externalLight` | Switch | RW | Some cameras have a dedicated relay output for turning lights on and off with. | +| `externalMotion` | Switch | RW | Can be used to inform the camera if it has motion in its view area. Handy if you own a PIR or any other kind of external sensor. If you use the autofps.mjpeg feature, this could increase the frame rate when a door that was closed is opened. Note: It will not be passed onto your camera and will not trigger any recordings. | +| `faceDetected` | Switch | R | When a camera detects a face (API cameras only) this switch will move to ON. | +| `fieldDetectionAlarm` | Switch | R | Reflects the cameras status for the field or intrusion alarm. | +| `ffmpegMotionAlarm` | Switch | R | The status of the FFmpeg based motion alarm. | +| `ffmpegMotionControl` | Dimmer | RW | This control allows FFmpeg to detect movement from a RTSP or HTTP source and inform openHAB. The channel that will move is called `ffmpegMotionAlarm`. | +| `gifHistory` | String | RW | The 50 most recent filenames the binding has used unless reset. | +| `gifHistoryLength` | Number | RW | How many filenames are in the `gifHistory`. | +| `gotoPreset` | String | RW | ONVIF cameras that can move only. Will cause the camera to move to a preset location. | +| `hlsUrl` | String | RW | The URL for the ipcamera.m3u8 file. | +| `humanAlarm` | Switch | RW | When a camera detects a human this switch will turn ON. | +| `imageUrl` | String | RW | The URL for the ipcamera.jpg file. | +| `itemLeft` | Switch | R | Will turn ON if an API camera detects an item has been left behind. | +| `itemTaken` | Switch | R | Will turn ON if an API camera detects an item has been stolen. | +| `lastMotionType` | String | RW | Cameras with multiple alarm types will update this with which alarm last detected motion, i.e. a lineCrossing, faceDetection or item stolen alarm. You can also use this to create a timestamp of when the last motion was detected by creating a rule when this channel changes. | +| `lastEventData` | String | RW | Detailed information about the last smart alarm that can contain information like which Line number was crossed and in which direction. The channel `lastMotionType` will hold the name of the alarm that this data belongs to. | +| `lineCrossingAlarm` | Switch | R | Will turn on if the API camera detects motion has crossed a line. | +| `mjpegUrl` | String | RW | The URL for the ipcamera.mjpeg stream. | +| `motionAlarm` | Switch | R | The status of the 'video motion' events in ONVIF and API cameras. Also see `cellMotionAlarm` as these can give different results. | +| `mp4History` | String | RW | The 50 most recent filenames the binding has used unless reset. | +| `mp4HistoryLength` | Number | RW | How many filenames are in the `mp4History`. Setting this to 0 will clear the history. | +| `pan` | Dimmer | RW | Works with ONVIF cameras that can be moved. | +| `parkingAlarm` | Switch | R | When an API camera detects a car, this will turn ON. | +| `pirAlarm` | Switch | R | When a camera with PIR ability detects motion, this turns ON. | +| `privacyMode` | Switch | RW | Enable or disable the Privacy Mode of newer Amcrest/Dahua cameras. The camera will move the lens way down and stop the stream. | +| `recordingGif` | Number | R | How many seconds recording to GIF for. 0 when file ready. | +| `recordingMp4` | Number | R | How many seconds recording to MP4 for. 0 when file ready. | +| `rtspUrl` | String | RW | The URL for the cameras auto detected RTSP stream. | +| `sceneChangeAlarm` | Switch | R | When an API camera detects the camera has moved, this turns ON. | +| `startStream` | Switch | RW | Starts the HLS files being created, if it not manually moved it will indicate if the files are being created on demand. | +| `storageAlarm` | Switch | R | When an ONVIF cameras storage is full and/or removed, this turns ON. | +| `tamperAlarm` | Switch | R | When an ONVIF cameras tamper switch is tripped, this turns ON. | +| `textOverlay` | String | RW | Dahua, Instar and Hikvision can overlay any text you enter here over the video stream. | +| `thresholdAudioAlarm` | Dimmer | RW | This channel can be linked to a Switch and a Slider. The value of the slider is the value in dB that is detected as noise/alarm down from digital full scale. Higher values are more sensitive and will trigger the alarm with quieter / less noise. | +| `tilt` | Dimmer | RW | Works with ONVIF cameras that can be moved. | +| `triggerExternalAlarmInput` | Switch | RW | Hikvision cameras can change if the alarm input terminal is ON when high or low. This can be used to manually cause an alarm input event to occur. | +| `tooBlurryAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | +| `tooBrightAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | +| `tooDarkAlarm` | Switch | R | ONVIF cameras only will reflect the status of the ONVIF event of the same name. | +| `pollImage` | Switch | RW | This control can be used to manually start and stop using your CPU to create snapshots from a RTSP source. If you have a snapshot URL setup in the binding, only then can this control can be used to update the Image channel. | +| `whiteLED` | Dimmer | RW | Turn the visible white LED ON or OFF and if supported dim from 0-100%. | +| `zoom` | Dimmer | RW | Works with ONVIF cameras that can be moved. | +| `acceptedCardNumber` | String | R | This channel shows the last accepted access card number that opened the door. The channel doesn't show rejected/unauthorized cards. | +| `unacceptedCardNumber` | String | R | This channel shows the last unaccepted access card number that was read. | +| `doorUnlock` | Switch | RW | This channel could reflect door lock state and at the same time send commands to door lock. Note that under some conditions doorphone doesn't send "lock off" message, so it's better to add expiration timer to corresponding item. | +| `doorContact` | Contact | R | Reflects door open/closed contact state. | +| `exitButton` | Switch | R | Reflects exit button state. This could be used to check for exit button's long clicks/double clicks, so the button could control other gates connected to openHAB, or outdoor lights. | +| `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. | ## Moving PTZ Cameras @@ -378,6 +386,7 @@ There are a number of ways to use snapshots with this binding. - Use the cameras URL so it passes from the camera directly to your end device. ie a tablet. This is always the best option if it works. + - Request a snapshot with the URL `http://openhabIP:8080/ipcamera/{cameraUID}/ipcamera.jpg`. The IP is for your openHAB server not the camera. If you find the snapshot is old, you can set the `gifPreroll` to a number above 0 and this forces the camera to keep updating the stored JPG in RAM. @@ -589,7 +598,6 @@ Webview url="http://192.168.6.4:8080/static/html/file.html" height=5 - ``` ## How to Cast a Camera diff --git a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java index 37d4c889227fa..a6d3a7b23829c 100644 --- a/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java +++ b/bundles/org.openhab.binding.ipcamera/src/main/java/org/openhab/binding/ipcamera/internal/DahuaHandler.java @@ -12,7 +12,41 @@ */ package org.openhab.binding.ipcamera.internal; -import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.*; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ACCEPTED_CARD_NUMBER; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ACTIVATE_ALARM_OUTPUT; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ACTIVATE_ALARM_OUTPUT2; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_AUTO_LED; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_AUTO_WHITE_LED; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_CAR_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_DOOR_CONTACT; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_DOOR_UNLOCK; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ENABLE_AUDIO_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ENABLE_LED; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ENABLE_LINE_CROSSING_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ENABLE_MOTION_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ENABLE_PRIVACY_MODE; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_EXIT_BUTTON; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_EXIT_BUTTON_ENABLED; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_EXTERNAL_ALARM_INPUT; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_EXTERNAL_ALARM_INPUT2; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_FACE_DETECTED; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_FIELD_DETECTION_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_HUMAN_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ITEM_LEFT; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_ITEM_TAKEN; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_LAST_EVENT_DATA; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_LINE_CROSSING_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_MAGNETIC_LOCK_WARNING; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_MOTION_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_MOTION_DETECTION_LEVEL; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_PARKING_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_SCENE_CHANGE_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_TEXT_OVERLAY; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_THRESHOLD_AUDIO_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_TOO_BLURRY_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_TOO_DARK_ALARM; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_UNACCEPTED_CARD_NUMBER; +import static org.openhab.binding.ipcamera.internal.IpCameraBindingConstants.CHANNEL_WHITE_LED; import java.util.List; import java.util.regex.Pattern; @@ -23,6 +57,7 @@ import org.openhab.binding.ipcamera.internal.onvif.OnvifConnection.RequestType; import org.openhab.core.library.types.DecimalType; import org.openhab.core.library.types.OnOffType; +import org.openhab.core.library.types.OpenClosedType; import org.openhab.core.library.types.PercentType; import org.openhab.core.library.types.StringType; import org.openhab.core.thing.ChannelUID; @@ -172,18 +207,87 @@ private void processEvent(String content) { ipCameraHandler.setChannelState(CHANNEL_TOO_BLURRY_ALARM, OnOffType.OFF); } break; + case "AccessControl": + if ("Pulse".equals(action)) { + if (content.contains("\"Method\" : 1")) { + if (content.contains("\"ErrorCode\" : 0")) { + startIndex = content.indexOf("CardNo", startIndex) + 11; + if (startIndex > 0) { + endIndex = content.indexOf(",", startIndex) - 1; + String cardNo = content.substring(startIndex, endIndex); + ipCameraHandler.setChannelState(CHANNEL_ACCEPTED_CARD_NUMBER, new StringType(cardNo)); + ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.ON); + } + } + } else if (content.contains("\"Method\" : 5")) { + ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.ON); + ipCameraHandler.logger.debug("Door opened from button"); + } else if (content.contains("\"Method\" : 4")) { + ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.ON); + ipCameraHandler.logger.debug("Door opened remotely"); + } + } else { + ipCameraHandler.logger.debug("Unrecognised Access control Dahua event, content={}", content); + } + break; + case "DoorCard": + if ("Pulse".equals(action)) { + if (content.contains("\"Number\"")) { + startIndex = content.indexOf("Number", startIndex) + 11; + if (startIndex > 0) { + endIndex = content.indexOf(",", startIndex) - 1; + String cardNo = content.substring(startIndex, endIndex); + ipCameraHandler.setChannelState(CHANNEL_UNACCEPTED_CARD_NUMBER, new StringType(cardNo)); + } + } + } else { + ipCameraHandler.logger.debug("Unrecognised Access control Dahua event, content={}", content); + } + break; + case "ProfileAlarmTransmit": + if ("Start".equals(action)) { + if (content.contains("DoorMagnetism")) { + ipCameraHandler.setChannelState(CHANNEL_MAGNETIC_LOCK_WARNING, OnOffType.ON); + } + } else if ("Stop".equals(action)) { + if (content.contains("DoorMagnetism")) { + ipCameraHandler.setChannelState(CHANNEL_MAGNETIC_LOCK_WARNING, OnOffType.OFF); + } + } else { + ipCameraHandler.logger.debug("Unrecognised Alarm Dahua event, content={}", content); + } + break; + case "DoorStatus": + if ("Pulse".equals(action)) { + if (content.contains("\"Relay\" : true")) { + ipCameraHandler.setChannelState(CHANNEL_DOOR_UNLOCK, OnOffType.OFF); + } else if (content.contains("\"Status\" : \"Close\"")) { + ipCameraHandler.setChannelState(CHANNEL_DOOR_CONTACT, OpenClosedType.CLOSED); + } else if (content.contains("\"Status\" : \"Open\"")) { + ipCameraHandler.setChannelState(CHANNEL_DOOR_CONTACT, OpenClosedType.OPEN); + } else { + ipCameraHandler.logger.debug("Unrecognised Door status Dahua event, content={}", content); + } + } + break; case "AlarmLocal": if ("Start".equals(action)) { if (content.contains("index=0")) { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT, OnOffType.ON); + } else if (content.contains("index=3")) { + ipCameraHandler.setChannelState(CHANNEL_EXIT_BUTTON, OnOffType.ON); } else { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT2, OnOffType.ON); + ipCameraHandler.logger.trace("External alarm Dahua event, content={}", content); } } else if ("Stop".equals(action)) { if (content.contains("index=0")) { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT, OnOffType.OFF); + } else if (content.contains("index=3")) { + ipCameraHandler.setChannelState(CHANNEL_EXIT_BUTTON, OnOffType.OFF); } else { ipCameraHandler.setChannelState(CHANNEL_EXTERNAL_ALARM_INPUT2, OnOffType.OFF); + ipCameraHandler.logger.trace("External alarm Dahua event, content={}", content); } } break; @@ -209,6 +313,7 @@ private void processEvent(String content) { case "LeFunctionStatusSync": case "RecordDelete": case "InterVideoAccess": + case "SIPRegisterResult": break; default: ipCameraHandler.logger.debug("Unrecognised Dahua event, Code={}, action={}", code, action); @@ -223,6 +328,12 @@ private void processSettings(String content) { ipCameraHandler.setChannelState(CHANNEL_ENABLE_MOTION_ALARM, OnOffType.OFF); } + // Handle MotionDetectLevel alarm + if (content.contains("table.MotionDetect[0].Level=")) { + String value = ipCameraHandler.returnValueFromString(content, "table.MotionDetect[0].Level="); + ipCameraHandler.setChannelState(CHANNEL_MOTION_DETECTION_LEVEL, DecimalType.valueOf(value)); + } + // determine if the audio alarm is turned on or off. if (content.contains("table.AudioDetect[" + nvrChannelAdjusted + "].MutationDetect=true")) { ipCameraHandler.setChannelState(CHANNEL_ENABLE_AUDIO_ALARM, OnOffType.ON); @@ -249,6 +360,13 @@ private void processSettings(String content) { } else if (content.contains("table.LeLensMask[" + nvrChannelAdjusted + "].Enable=false")) { ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF); } + + // determine if exit button is enabled + if (content.contains("table.AccessControlGeneral.ButtonExitEnable=true")) { + ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.ON); + } else if (content.contains("table.AccessControlGeneral.ButtonExitEnable=false")) { + ipCameraHandler.setChannelState(CHANNEL_ENABLE_PRIVACY_MODE, OnOffType.OFF); + } } // This handles the incoming http replies back from the camera. @@ -303,6 +421,14 @@ public void handleCommand(ChannelUID channelUID, Command command) { ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=Lighting_V2[" + nvrChannelAdjusted + "][0][1].Mode"); return; + case CHANNEL_MOTION_DETECTION_LEVEL: + ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=MotionDetect[" + + nvrChannelAdjusted + "]"); + return; + case CHANNEL_EXIT_BUTTON_ENABLED: + ipCameraHandler + .sendHttpGET("/cgi-bin/configManager.cgi?action=getConfig&name=AccessControlGeneral"); + return; } return; } // end of "REFRESH" @@ -369,14 +495,14 @@ public void handleCommand(ChannelUID channelUID, Command command) { } return; case CHANNEL_THRESHOLD_AUDIO_ALARM: - int threshold = Math.round(Float.valueOf(command.toString())); - - if (threshold == 0) { - ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AudioDetect[" - + nvrChannelAdjusted + "].MutationThreold=1"); - } else { - ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AudioDetect[" - + nvrChannelAdjusted + "].MutationThreold=" + threshold); + if (command instanceof PercentType percentCommand) { + if (PercentType.ZERO.equals(command)) { + ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AudioDetect[" + + nvrChannelAdjusted + "].MutationThreold=1"); + } else { + ipCameraHandler.sendHttpGET("/cgi-bin/configManager.cgi?action=setConfig&AudioDetect[" + + nvrChannelAdjusted + "].MutationThreold=" + percentCommand.intValue()); + } } return; case CHANNEL_ENABLE_AUDIO_ALARM: @@ -406,6 +532,19 @@ public void handleCommand(ChannelUID channelUID, Command command) { + nvrChannelAdjusted + "].Enable=false"); } return; + case CHANNEL_MOTION_DETECTION_LEVEL: + if (command instanceof DecimalType decimalCommand) { + if (DecimalType.ZERO.equals(command)) { + ipCameraHandler.sendHttpGET( + "/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=false&MotionDetect[0].Level=" + + decimalCommand.intValue()); + } else { + ipCameraHandler.sendHttpGET( + "/cgi-bin/configManager.cgi?action=setConfig&MotionDetect[0].Enable=true&MotionDetect[0].EventHandler.Dejitter=1&MotionDetect[0].Level=" + + decimalCommand.intValue()); + } + } + return; case CHANNEL_ACTIVATE_ALARM_OUTPUT: if (OnOffType.ON.equals(command)) { ipCameraHandler.sendHttpGET( @@ -431,6 +570,21 @@ public void handleCommand(ChannelUID channelUID, Command command) { + nvrChannelAdjusted + "].Enable=true"); } return; + case CHANNEL_DOOR_UNLOCK: + if (OnOffType.ON.equals(command)) { + ipCameraHandler + .sendHttpGET("/cgi-bin/accessControl.cgi?action=openDoor&channel=1&UserID=101&Type=Remote"); + } + return; + case CHANNEL_EXIT_BUTTON_ENABLED: + if (OnOffType.ON.equals(command)) { + ipCameraHandler.sendHttpGET( + "/cgi-bin/configManager.cgi?action=setConfig&AccessControlGeneral.ButtonExitEnable=true"); + } else if (OnOffType.OFF.equals(command)) { + ipCameraHandler.sendHttpGET( + "/cgi-bin/configManager.cgi?action=setConfig&AccessControlGeneral.ButtonExitEnable=false"); + } + return; } } 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 b6183d68ceb76..6023bd76dd508 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 @@ -150,4 +150,12 @@ public enum FFmpegFormat { public static final String CHANNEL_ENABLE_PUSH = "enablePush"; public static final String CHANNEL_ENABLE_RECORDINGS = "enableRecordings"; public static final String CHANNEL_AUTO_TRACKING = "autoTracking"; + public static final String CHANNEL_ACCEPTED_CARD_NUMBER = "acceptedCardNumber"; + public static final String CHANNEL_UNACCEPTED_CARD_NUMBER = "unacceptedCardNumber"; + public static final String CHANNEL_DOOR_UNLOCK = "doorUnlock"; + public static final String CHANNEL_DOOR_CONTACT = "doorContact"; + public static final String CHANNEL_EXIT_BUTTON = "exitButton"; + 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"; } 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 b6178ff5d053e..48589cf26f89b 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 @@ -619,6 +619,8 @@ thing-type.config.ipcamera.reolink.username.description = Enter the User name us # channel types +channel-type.ipcamera.acceptedCardNumber.label = Accepted Card Number +channel-type.ipcamera.acceptedCardNumber.description = Displays last accepted card number. channel-type.ipcamera.activateAlarmOutput.label = Alarm Output 1 ON/OFF channel-type.ipcamera.activateAlarmOutput.description = You can use the cameras output to trigger a device like a burglar alarm. channel-type.ipcamera.activateAlarmOutput2.label = Alarm Output 2 ON/OFF @@ -639,6 +641,10 @@ channel-type.ipcamera.cellMotionAlarm.label = Cell Motion Alarm channel-type.ipcamera.cellMotionAlarm.description = Cell based motion has been detected. channel-type.ipcamera.doorBell.label = Door Bell channel-type.ipcamera.doorBell.description = The button has been pushed. +channel-type.ipcamera.doorContact.label = Door Contact +channel-type.ipcamera.doorContact.description = Door contact representing if the door is opened/closed. +channel-type.ipcamera.doorUnlock.label = Door Unlock +channel-type.ipcamera.doorUnlock.description = Lock/unlock. channel-type.ipcamera.enableAudioAlarm.label = Enable Audio Alarm channel-type.ipcamera.enableAudioAlarm.description = By using this feature you can stop the camera from sending e-mails when you are having a party. channel-type.ipcamera.enableEmail.label = Enable Email @@ -663,6 +669,10 @@ channel-type.ipcamera.enablePush.label = Enable Push channel-type.ipcamera.enablePush.description = Turn the push notification features of the camera on or off channel-type.ipcamera.enableRecordings.label = Enable Recordings channel-type.ipcamera.enableRecordings.description = Enable/Disable the cameras internal recordings +channel-type.ipcamera.exitButton.label = Exit Button +channel-type.ipcamera.exitButton.description = Exit button pressed/released. +channel-type.ipcamera.exitButtonEnabled.label = Disable/Enable Exit Button +channel-type.ipcamera.exitButtonEnabled.description = Use to enable/disable exit button. channel-type.ipcamera.externalAlarmInput.label = Alarm Input 1 channel-type.ipcamera.externalAlarmInput.description = Some cameras have alarm input wires which can be used to connect to door bells or external PIR sensors. channel-type.ipcamera.externalAlarmInput2.label = Alarm Input 2 @@ -728,10 +738,21 @@ channel-type.ipcamera.lastMotionType.label = Last Motion Type channel-type.ipcamera.lastMotionType.description = A string that contains the type of motion alarm that was last triggered. channel-type.ipcamera.lineCrossingAlarm.label = Line Crossing Alarm channel-type.ipcamera.lineCrossingAlarm.description = Motion has been detected. +channel-type.ipcamera.magneticLockWarning.label = Magnetic Lock Fail Warning +channel-type.ipcamera.magneticLockWarning.description = Will switch to ON if the door will be opened while locked. channel-type.ipcamera.mjpegUrl.label = MJPEG URL channel-type.ipcamera.mjpegUrl.description = A link you can use in openHAB/HABpanel to fetch a MJPEG video feed from the camera. channel-type.ipcamera.motionAlarm.label = Motion Alarm channel-type.ipcamera.motionAlarm.description = Motion has been detected. +channel-type.ipcamera.motionDetectionLevel.label = Motion Detection Level +channel-type.ipcamera.motionDetectionLevel.description = Change how sensitive the camera's motion detection is to movement. +channel-type.ipcamera.motionDetectionLevel.state.option.0 = Detection Off +channel-type.ipcamera.motionDetectionLevel.state.option.1 = Lowest sensitivity +channel-type.ipcamera.motionDetectionLevel.state.option.2 = Low sensitivity +channel-type.ipcamera.motionDetectionLevel.state.option.3 = Middle sensitivity +channel-type.ipcamera.motionDetectionLevel.state.option.4 = High sensitivity +channel-type.ipcamera.motionDetectionLevel.state.option.5 = Higher sensitivity +channel-type.ipcamera.motionDetectionLevel.state.option.6 = Highest sensitivity channel-type.ipcamera.mp4History.label = MP4 History channel-type.ipcamera.mp4History.description = A history of the last mp4 recordings created in a CSV formatted string. channel-type.ipcamera.mp4HistoryLength.label = MP4 History Length @@ -772,6 +793,8 @@ channel-type.ipcamera.tooDarkAlarm.label = Too Dark Alarm channel-type.ipcamera.tooDarkAlarm.description = Image is too dark. channel-type.ipcamera.triggerExternalAlarmInput.label = Alarm In 1 TRIGGER high ON/low OFF channel-type.ipcamera.triggerExternalAlarmInput.description = Change the External Alarm Input to trigger on high or low states. +channel-type.ipcamera.unacceptedCardNumber.label = Unaccepted Card Number +channel-type.ipcamera.unacceptedCardNumber.description = Displays last unaccepted card number. channel-type.ipcamera.whiteLED.label = White LED channel-type.ipcamera.whiteLED.description = Turn the visible white LED ON and OFF and if supported 0-100% dimming. channel-type.ipcamera.zoom.label = Zoom 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 c4c0acc6966de..a908738bb76e2 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 @@ -887,6 +887,7 @@ + @@ -922,10 +923,17 @@ + + + + + + + - 1 + 2 @@ -3041,6 +3049,78 @@ Enter some text you wish to overlay on top of the cameras snapshot and video streams. + + String + + Displays last accepted card number. + + + + + String + + Displays last unaccepted card number. + + + + + Switch + + Lock/unlock. + Lock + + + + Contact + + Door contact representing if the door is opened/closed. + Door + + + + + Switch + + Exit button pressed/released. + Switch + + + + + Switch + + Use to enable/disable exit button. + Switch + + + + + Switch + + Will switch to ON if the door will be opened while locked. + Alarm + + + + + Number + + Change how sensitive the camera's motion detection is to + movement. + Motion + + + + + + + + + + + + + String 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 c4d2f4e4f7c53..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 @@ -34,6 +34,32 @@ ipcamera:autoWhiteLED + + + ipcamera:acceptedCardNumber + + + ipcamera:unacceptedCardNumber + + + ipcamera:doorUnlock + + + ipcamera:doorContact + + + ipcamera:exitButton + + + ipcamera:exitButtonEnabled + + + ipcamera:motionDetectionLevel + + + ipcamera:magneticLockWarning + +