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

Added Service: Move to Preset #147

Merged
merged 6 commits into from
Mar 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.0.10

- New Feature: Added a service (Move to Preset) for moving a specified camera to a specified preset

## 1.0.9

- New Feature: Added a service (Trigger Camera) for triggering cameras and camera groups
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Integration with Blue Iris Video Security Software. Creates the following compon
## Component is no longer being maintained
I switched to Shinobi Video, if there is an issue, feel free to report, suggest PR and I will approve it


## How to

#### Requirements
Expand Down Expand Up @@ -164,6 +165,8 @@ If you turn off one of the switches it will behave as follows:
###### Services
Trigger Camera: Provides the ability to manually trigger a camera or camera group

Move to Preset: Provides the ability to move a camera to a specified preset

## Lovelace UI Configuration
[Example of UI layout](https://github.com/elad-bar/ha-blueiris/blob/master/docs/configs/casting/configuration.yaml)

Expand Down
11 changes: 11 additions & 0 deletions custom_components/blueiris/api/blue_iris_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,14 @@ async def trigger_camera(self, camera_short_name):
"camera" : camera_short_name
}
await self.async_verified_post(request_data)

async def move_to_preset(self, camera_short_name, preset):
_LOGGER.info(f"Moving {camera_short_name} to preset {preset}")
preset_value = 100 + preset
request_data = {
"cmd": "ptz",
"session": self.session_id,
"camera" : camera_short_name,
"button" : preset_value
}
await self.async_verified_post(request_data)
17 changes: 16 additions & 1 deletion custom_components/blueiris/camera.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@

import aiohttp
import async_timeout
import voluptuous as vol

from homeassistant.components.camera import SUPPORT_STREAM, Camera
from homeassistant.const import CONF_VERIFY_SSL
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import TemplateError
from homeassistant.helpers import entity_platform
from homeassistant.helpers import config_validation as cv, entity_platform
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .helpers.const import *
Expand All @@ -40,6 +41,13 @@ async def async_setup_entry(hass, config_entry, async_add_devices):
{},
SERVICE_TRIGGER_CAMERA,
)
platform.async_register_entity_service(
SERVICE_MOVE_TO_PRESET,
{
vol.Required('preset'): cv.positive_int,
},
SERVICE_MOVE_TO_PRESET,
)



Expand Down Expand Up @@ -159,3 +167,10 @@ async def trigger_camera(self):
else:
for grouped_camera in self.entity.attributes[BI_CAMERA_ATTR_GROUP_CAMERAS]:
await self.api.trigger_camera(grouped_camera)

async def move_to_preset(self, preset):
if self.entity.attributes[BI_CAMERA_ATTR_GROUP_CAMERAS] == NOT_AVAILABLE:
await self.api.move_to_preset(self.entity.id, preset)
else:
for grouped_camera in self.entity.attributes[BI_CAMERA_ATTR_GROUP_CAMERAS]:
await self.api.move_to_preset(grouped_camera, preset)
1 change: 1 addition & 0 deletions custom_components/blueiris/helpers/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@
DOMAIN_LOGGER = "logger"
SERVICE_SET_LEVEL = "set_level"
SERVICE_TRIGGER_CAMERA = "trigger_camera"
SERVICE_MOVE_TO_PRESET = "move_to_preset"


ATTR_ADMIN_PROFILE = "Profile"
Expand Down
58 changes: 58 additions & 0 deletions custom_components/blueiris/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,61 @@ trigger_camera:
entity:
integration: blueiris
domain: camera

move_to_preset:
name: Move to Preset
description: Moves the selected camera to the specified preset
target:
entity:
integration: blueiris
domain: camera
fields:
preset:
name: Preset
description: Desired preset
required: true
example: "1"
default: "1"
selector:
select:
options:
- "1"
- "2"
- "3"
- "4"
- "5"
- "6"
- "7"
- "8"
- "9"
- "10"
- "11"
- "12"
- "13"
- "14"
- "15"
- "16"
- "17"
- "18"
- "19"
- "20"
- "21"
- "22"
- "23"
- "24"
- "25"
- "26"
- "27"
- "28"
- "29"
- "30"
- "31"
- "32"
- "33"
- "34"
- "35"
- "36"
- "37"
- "38"
- "39"
- "40"