Skip to content

Commit

Permalink
create light.hue_activate_scene service (home-assistant#4425)
Browse files Browse the repository at this point in the history
* create light.hue_activate_scene service

This creates a light.hue_activate_scene service that takes group_name
and scene_name, and calls phue's bridge.run_scene with those
parameters. This allows calling hue bridge stored scene names by name
during automation.

This only currently works reliably in 1 hue hub configurations (which
is most of them). Phue will be further enhanced to display warnings
when it can't figure out what to do with the parameters passed in to HA.

* Update hue.py
  • Loading branch information
sdague authored and balloob committed Nov 18, 2016
1 parent 1a117d0 commit cd1655f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
25 changes: 25 additions & 0 deletions homeassistant/components/light/hue.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
FLASH_LONG, FLASH_SHORT, SUPPORT_BRIGHTNESS, SUPPORT_COLOR_TEMP,
SUPPORT_EFFECT, SUPPORT_FLASH, SUPPORT_RGB_COLOR, SUPPORT_TRANSITION,
SUPPORT_XY_COLOR, Light, PLATFORM_SCHEMA)
from homeassistant.config import load_yaml_config_file
from homeassistant.const import (CONF_FILENAME, CONF_HOST, DEVICE_DEFAULT_NAME)
from homeassistant.loader import get_component
import homeassistant.helpers.config_validation as cv
Expand All @@ -37,6 +38,8 @@
CONF_ALLOW_UNREACHABLE = 'allow_unreachable'

DEFAULT_ALLOW_UNREACHABLE = False
DOMAIN = "light"
SERVICE_HUE_SCENE = "hue_activate_scene"

MIN_TIME_BETWEEN_SCANS = timedelta(seconds=10)
MIN_TIME_BETWEEN_FORCED_SCANS = timedelta(milliseconds=100)
Expand All @@ -53,6 +56,13 @@
vol.Optional(CONF_FILENAME): cv.string,
})

ATTR_GROUP_NAME = "group_name"
ATTR_SCENE_NAME = "scene_name"
SCENE_SCHEMA = vol.Schema({
vol.Required(ATTR_GROUP_NAME): cv.string,
vol.Required(ATTR_SCENE_NAME): cv.string,
})


def _find_host_from_config(hass, filename=PHUE_CONFIG_FILE):
"""Attempt to detect host based on existing configuration."""
Expand Down Expand Up @@ -166,6 +176,21 @@ def update_lights():
add_devices(new_lights)

_CONFIGURED_BRIDGES[socket.gethostbyname(host)] = True

# create a service for calling run_scene directly on the bridge,
# used to simplify automation rules.
def hue_activate_scene(call):
"""Service to call directly directly into bridge to set scenes."""
group_name = call.data[ATTR_GROUP_NAME]
scene_name = call.data[ATTR_SCENE_NAME]
bridge.run_scene(group_name, scene_name)

descriptions = load_yaml_config_file(
os.path.join(os.path.dirname(__file__), 'services.yaml'))
hass.services.register(DOMAIN, SERVICE_HUE_SCENE, hue_activate_scene,
descriptions.get(SERVICE_HUE_SCENE),
schema=SCENE_SCHEMA)

update_lights()


Expand Down
12 changes: 12 additions & 0 deletions homeassistant/components/light/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,15 @@ toggle:
transition:
description: Duration in seconds it takes to get to next state
example: 60

hue_activate_scene:
description: Activate a hue scene stored in the hue hub

fields:
group_name:
description: Name of hue group/room from the hue app
example: "Living Room"

scene_name:
description: Name of hue scene from the hue app
example: "Energize"

0 comments on commit cd1655f

Please sign in to comment.