diff --git a/homeassistant/components/light/hue.py b/homeassistant/components/light/hue.py index 51ff77f2e2d..8fd8a6ef097 100644 --- a/homeassistant/components/light/hue.py +++ b/homeassistant/components/light/hue.py @@ -22,6 +22,7 @@ from homeassistant.components.light import ( 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 @@ -37,6 +38,8 @@ _LOGGER = logging.getLogger(__name__) 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) @@ -53,6 +56,13 @@ PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ 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.""" @@ -166,6 +176,21 @@ def setup_bridge(host, hass, add_devices, filename, allow_unreachable): 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() diff --git a/homeassistant/components/light/services.yaml b/homeassistant/components/light/services.yaml index afcc54d717f..8931a46bb73 100644 --- a/homeassistant/components/light/services.yaml +++ b/homeassistant/components/light/services.yaml @@ -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"