diff --git a/homeassistant/components/device_sun_light_trigger.py b/homeassistant/components/device_sun_light_trigger.py index 1158b051445..5c7d6fd63d7 100644 --- a/homeassistant/components/device_sun_light_trigger.py +++ b/homeassistant/components/device_sun_light_trigger.py @@ -86,7 +86,7 @@ def setup(bus, statemachine, light_group=None): def handle_device_state_change(category, old_state, new_state): """ Function to handle tracked device state changes. """ - lights_are_on = light.is_on(statemachine) + lights_are_on = group.is_on(statemachine, light_group) light_needed = not (lights_are_on or sun.is_up(statemachine)) diff --git a/homeassistant/components/group.py b/homeassistant/components/group.py index ff1ef2ed1bd..fc2b0fd4148 100644 --- a/homeassistant/components/group.py +++ b/homeassistant/components/group.py @@ -30,6 +30,23 @@ def _get_group_type(state): return None +def is_on(statemachine, group): + """ Returns if the group state is in its ON-state. """ + state = statemachine.get_state(group) + + if state: + group_type = _get_group_type(state['state']) + + if group_type: + group_on = _GROUP_TYPES[group_type][0] + + return state['state'] == group_on + else: + return False + else: + return False + + def get_categories(statemachine, group_name): """ Get the categories that make up this group. """ state = statemachine.get_state(STATE_CATEGORY_FORMAT.format(group_name))