Skip to content

Instantly share code, notes, and snippets.

@tchellomello
Last active November 24, 2016 04:10
Show Gist options
  • Select an option

  • Save tchellomello/0cc929b9ac425bcfab166323d1db450a to your computer and use it in GitHub Desktop.

Select an option

Save tchellomello/0cc929b9ac425bcfab166323d1db450a to your computer and use it in GitHub Desktop.
V1.0 amcrest camera for Home Assistant
"""
This component provides basic support for Amcrest IP cameras.
For more details about this platform, please refer to the documentation at
https://home-assistant.io/components/camera.amcrest/
"""
import logging
import voluptuous as vol
from amcrest import AmcrestCamera
from homeassistant.components.camera import (Camera, PLATFORM_SCHEMA)
from homeassistant.const import (
CONF_HOST, CONF_NAME, CONF_USERNAME, CONF_PASSWORD, CONF_PORT)
from homeassistant.helpers import config_validation as cv
REQUIREMENTS = ['git+https://github.com/tchellomello/python-amcrest'
'#amcrest==1.0.0']
_LOGGER = logging.getLogger(__name__)
DEFAULT_PORT = 80
DEFAULT_NAME = 'Amcrest Camera'
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({
vol.Required(CONF_HOST): cv.string,
vol.Required(CONF_USERNAME): cv.string,
vol.Required(CONF_PASSWORD): cv.string,
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
vol.Optional(CONF_PORT, default=DEFAULT_PORT): cv.port,
})
def setup_platform(hass, config, add_devices, discovery_info=None):
"""Setup an Amcrest IP Camera."""
add_devices([AmcrestCam(config)])
return True
class AmcrestCam(Camera):
"""An implementation of an Amcrest IP camera."""
def __init__(self, device_info):
"""Initialize an Amcrest camera."""
super(AmcrestCam, self).__init__()
self._name = device_info.get(CONF_NAME)
self._data = AmcrestCamera(device_info.get(CONF_HOST),
device_info.get(CONF_PORT),
device_info.get(CONF_USERNAME),
device_info.get(CONF_PASSWORD))
def camera_image(self):
"""Return a still image reponse from the camera."""
# Send the request to snap a picture and return raw jpg data
response = self._data.camera.snapshot()
return response.data
@property
def name(self):
"""Return the name of this camera."""
return self._name
@tchellomello
Copy link
Author

tchellomello commented Nov 24, 2016

To install the module:

cd ~/.homeassistant
mkdir -p custom_components/camera
cd custom_components/camera
wget https://gist.githubusercontent.com/tchellomello/0cc929b9ac425bcfab166323d1db450a/raw/b402beea2a386fa25867598914ff284852c531fe/amcrest.py
pip3 install git+https://github.com/tchellomello/python-amcrest --upgrade

Configuration:

#configuration.yaml
camera:
  - platform: amcrest
    name: Living Room
    host: 192.168.0.16
    port: 80
    username: admin
    password: 123456

  - platform: amcrest
    name: Patio
    host: 192.168.0.15
    port: 80
    username: admin
    password: 123456

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment