Skip to content

Commit

Permalink
Add support for HACS (#20)
Browse files Browse the repository at this point in the history
Add support for the Home Assistant Community Store.
  • Loading branch information
marthoc authored Mar 11, 2020
1 parent a7d1176 commit 6e96cf4
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 12 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,5 @@ dmypy.json
.pyre/

.idea/

.DS_Store
31 changes: 19 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Kuna Smart Home Security Custom Integration for Home Assistant

[![hacs_badge](https://img.shields.io/badge/HACS-Custom-orange.svg)](https://github.com/custom-components/hacs)

[Home Assistant](https://home-assistant.io/) custom integration supporting [Kuna](www.getkuna.com) cameras.

**Home Assistant 0.96.0 or higher is required**.
Expand All @@ -13,16 +15,24 @@ For each camera in a Kuna account, the following devices will be created:
**IoT Class:** _Cloud Polling_

## Installation (Home Assistant >= 0.96.0)
This custom integration must be installed for it to be loaded by Home Assistant.
This custom integration must be installed for it to be loaded by Home Assistant.

1. Create a `custom_components` directory in your Home Assistant configuration directory ('config' share if using [hass.io](https://home-assistant.io/hassio/) with the [Samba](https://home-assistant.io/addons/samba/) add-on or `~/.home-assistant/` for Linux installations).
1. Get the latest release from GitHub by cd'ing into the custom_components directory and cloning this repo (example below for Hass.io):
```
cd /config/custom_components
git clone https://github.com/marthoc/kuna
```
**The recommended installation method is via [HACS](https://hacs.xyz).**

### Installation via HACS

1. Add "marthoc/kuna" as a custom repository in HACS under "Settings".
2. Search for "Kuna Smart Home Security" under "Integrations" in HACS.
3. Click "Install".
4. Proceed with Configuration.

Now, proceed with configuration.
### Manual Installation

1. Create a `custom_components` directory in your Home Assistant configuration directory ('config' share if using [hass.io](https://home-assistant.io/hassio/) with the [Samba](https://home-assistant.io/addons/samba/) add-on or `~/.home-assistant/` for Linux installations).
2. Create a `kuna` directory in your `custom_components` directory.
3. Grab the latest release from the GitHub "Releases" page.
4. Copy all files (including the hidden `.translations` directory) from custom_components/kuna in the release to your config/custom_components/kuna directory.
5. Restart Home Assistant and proceed with Configuration.

## Configuration

Expand All @@ -40,10 +50,9 @@ The following options can be configured when setting up the integration:
| stream_interval | Optional | 5 | The frequency, in seconds, that the camera's frontend streaming view will refresh its image. |
| update_interval | Optional | 15 | The frequency, in seconds, that the component polls the Kuna server for updates. |


## Updating

To update the custom component, cd into the `custom_components/kuna` directory and `git pull`.
Update via HACS or by grabbing the latest release and overwriting the contents of your config/custom_components/kuna directory with the contents of custom_components/kuna in the release.

## Downloading Recordings

Expand Down Expand Up @@ -76,7 +85,6 @@ For each recording available in the Kuna API, this component fires a Home Assist
- **duration**: the length of the recording in seconds
- **url**: the web address at which an mp4 file of the recording is available for download


You can use these parameters to build an automation using the event trigger and templates. To download all recordings, set up the following automation:

```yaml
Expand All @@ -95,7 +103,6 @@ You can use these parameters to build an automation using the event trigger and

If you want to limit downloads to only a specific camera, add the `serial_number` parameter under 'event_data' in the trigger.


## Caveats

This integration has only been tested with a Maximus Smart Light. Testing and feedback by users with other (and multiple!) Kuna devices would be much appreciated!
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 7 additions & 0 deletions hacs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "Kuna Smart Home Security",
"domains": ["binary_sensor", "camera", "switch"],
"homeassistant": "0.96.0",
"iot_class": "Cloud Polling"
}

79 changes: 79 additions & 0 deletions info.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Kuna Smart Home Security Custom Integration for Home Assistant

[Home Assistant](https://home-assistant.io/) custom integration supporting [Kuna](www.getkuna.com) cameras.

For each camera in a Kuna account, the following devices will be created:

- Binary Sensor with device class 'motion', and default name "[Camera Name] Motion".
- Camera with default name "[Camera Name] Camera".
- Switch with default name "[Camera Name] Switch", which controls the camera's light bulb.

## Configuration

After installing via HACS, to enable the integration, add it from the Configuration - Integrations menu in Home Assistant. Click "+", then "Kuna Smart Home Security".

_(Note: previous versions of this component were configured in configuration.yaml; now, all configuration is via the Integration menu.)_

The following options can be configured when setting up the integration:

| Parameter | Optional/Required | Default | Description |
|------------------|-------------------|---------|-------------|
| email | Required | N/A | The email address used to log into the Kuna app. |
| password | Required | N/A | The password used to log into the Kuna app. |
| recording_interval | Optional | 7200 | The frequency, in seconds, that the component checks for new recordings for each camera. |
| stream_interval | Optional | 5 | The frequency, in seconds, that the camera's frontend streaming view will refresh its image. |
| update_interval | Optional | 15 | The frequency, in seconds, that the component polls the Kuna server for updates. |

## Downloading Recordings

On Home Assistant start, and every `recording_interval` seconds thereafter, this component checks the Kuna API for new recordings for each camera in the Kuna account, and fires a Home Assistant event for each recording found. These events can be used in an automation to trigger a download of the video with the `downloader` Home Assistant component. The default `recording_interval`, 7200 seconds (2 hours) corresponds to the length of time that recordings remain in the Kuna system _without_ a premium subscription.

To automatically download new recordings, you must first set up the `downloader` Home Assistant component and then set up an automation.

### Configuring the Downloader Component

Add the following to your configuration.yaml:

```yaml
downloader:
download_dir: downloads
```
You must ensure that the directory exists before restarting Home Assistant. Given the above example, you would need to ensure that there is a "downloads" subdirectory in your Home Assistant configuration directory, and that the Home Assistant user has write permission to that directory.
Refer to this page for further information on the `downloader` component: https://www.home-assistant.io/components/downloader/

### Automatically Downloading Recordings via Automation

For each recording available in the Kuna API, this component fires a Home Assistant event with the following parameters:

- **event_type**: "kuna_event"
- **event_data**:
- **category**: "recording"
- **serial_number**: the serial number of the camera that generated the recording
- **label**: a Kuna-assigned string that represents the timestamp of the recording in local time (e.g. "2019_03_18__16_20_06-0400")
- **timestamp**: a Kuna-assigned string that represents the timestamp of the recording in UTC (e.g. "2019-03-18T20:20:06.986645Z")
- **duration**: the length of the recording in seconds
- **url**: the web address at which an mp4 file of the recording is available for download


You can use these parameters to build an automation using the event trigger and templates. To download all recordings, set up the following automation:

```yaml
- alias: Download Kuna recordings
trigger:
platform: event
event_type: kuna_event
event_data:
category: recording
action:
service: downloader.download_file
data_template:
url: '{{ trigger.event.data.url }}'
filename: '{{ trigger.event.data.label }}.mp4'
```

If you want to limit downloads to only a specific camera, add the `serial_number` parameter under 'event_data' in the trigger.

## Caveats

This custom integration retrieves data from the same private API used by the Kuna mobile app, as Kuna does not offer a public API. Be gentle to the API and use at your own risk!

0 comments on commit 6e96cf4

Please sign in to comment.