Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable/Disable Motion detection for Foscam Cameras #8582

Merged
merged 14 commits into from
Aug 1, 2017
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Added support to enable/disable motion detection for foscam cameras. …
…This support was added in 0.48.1 as a generic service for cameras. Motion detection can be enabled/disabled for foscam cameras with this code-set.
  • Loading branch information
viswa-swami committed Jul 13, 2017
commit 85ec31d43825ab1ae067f232224c05cc22371888
64 changes: 64 additions & 0 deletions homeassistant/components/camera/foscam.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@

CONF_IP = 'ip'

CAMERA_ARMED = "armed"
CAMERA_DISARMED = "disarmed"

DEFAULT_NAME = 'Foscam Camera'
DEFAULT_PORT = 88

Expand Down Expand Up @@ -59,6 +62,7 @@ def __init__(self, device_info):
self._password
)
self._name = device_info.get(CONF_NAME)
self._motion_status = False

_LOGGER.info("Using the following URL for %s: %s",
self._name, uri_template.format('***', '***'))
Expand All @@ -78,3 +82,63 @@ def camera_image(self):
def name(self):
"""Return the name of this camera."""
return self._name

def set_motion_status(self, mode):
"""Post to the camera and enable motion detection."""
if mode == CAMERA_ARMED:
enabled = '1'
else:
enabled = '0'

# Fill the URI with the command to enable motion detection
# Along with that as per foscam spec we have to set
# sensitivity: how much sensitivity camera should detect
# trigger interval: interval between each motion triggers
# schedule: set schedule for days. default is 24x7
# area: sort of like zones. default is all areas visible to cam
uri_template = self._base_url \
+ 'cgi-bin/CGIProxy.fcgi?' \
+ 'cmd=setMotionDetectConfig' \
+ '&Enable={}&usr={}&pwd={}' \
+ '&linkage=0&snapInterval=3' \
+ '&sensitivity=2&triggerInterval=0' \
+ '&schedule0=281474976710655' \
+ '&schedule1=281474976710655' \
+ '&schedule2=281474976710655' \
+ '&schedule3=281474976710655' \
+ '&schedule4=281474976710655' \
+ '&schedule5=281474976710655' \
+ '&schedule6=281474976710655' \
+ '&area0=1024&area1=1023' \
+ '&area2=1024&area3=1023' \
+ '&area4=1024&area5=1023' \
+ '&area6=1024&area7=1023' \
+ '&area8=1024&area9=1023'

self._set_motion_status_url = uri_template.format(
enabled,
self._username,
self._password
)

try:
response = requests.get(self._set_motion_status_url, timeout=10)
except requests.exceptions.ConnectionError:
return None
else:
return response.content

@property
def motion_detection_enabled(self):
"""Is motion detection enabled or disabled."""
return self._motion_status

def enable_motion_detection(self):
"""Enable motion detection in camera."""
self._motion_status = True
self.set_motion_status(CAMERA_ARMED)

def disable_motion_detection(self):
"""Disable motion detection in camera."""
self._motion_status = False
self.set_motion_status(CAMERA_DISARMED)