def closest(hass, *args):
    "Find closest entity.\n\n    Closest to home:\n        closest(states)\n        closest(states.device_tracker)\n        closest('group.children')\n        closest(states.group.children)\n\n    Closest to a point:\n        closest(23.456, 23.456, 'group.children')\n        closest('zone.school', 'group.children')\n        closest(states.zone.school, 'group.children')\n\n    As a filter:\n        states | closest\n        states.device_tracker | closest\n        ['group.children', states.device_tracker] | closest\n        'group.children' | closest(23.456, 23.456)\n        states.device_tracker | closest('zone.school')\n        'group.children' | closest(states.zone.school)\n\n    "
    if (len(args) == 1):
        latitude = hass.config.latitude
        longitude = hass.config.longitude
        entities = args[0]
    elif (len(args) == 2):
        point_state = _resolve_state(hass, args[0])
        if (point_state is None):
            _LOGGER.warning('Closest:Unable to find state %s', args[0])
            return None
        if (not loc_helper.has_location(point_state)):
            _LOGGER.warning('Closest:State does not contain valid location: %s', point_state)
            return None
        latitude = point_state.attributes.get(ATTR_LATITUDE)
        longitude = point_state.attributes.get(ATTR_LONGITUDE)
        entities = args[1]
    else:
        latitude = convert(args[0], float)
        longitude = convert(args[1], float)
        if ((latitude is None) or (longitude is None)):
            _LOGGER.warning('Closest:Received invalid coordinates: %s, %s', args[0], args[1])
            return None
        entities = args[2]
    states = expand(hass, entities)
    return loc_helper.closest(latitude, longitude, states)
Find closest entity.

Closest to home:
    closest(states)
    closest(states.device_tracker)
    closest('group.children')
    closest(states.group.children)

Closest to a point:
    closest(23.456, 23.456, 'group.children')
    closest('zone.school', 'group.children')
    closest(states.zone.school, 'group.children')

As a filter:
    states | closest
    states.device_tracker | closest
    ['group.children', states.device_tracker] | closest
    'group.children' | closest(23.456, 23.456)
    states.device_tracker | closest('zone.school')
    'group.children' | closest(states.zone.school)
def closest(hass, *args):
    "Find closest entity.\n\n    Closest to home:\n        closest(states)\n        closest(states.device_tracker)\n        closest('group.children')\n        closest(states.group.children)\n\n    Closest to a point:\n        closest(23.456, 23.456, 'group.children')\n        closest('zone.school', 'group.children')\n        closest(states.zone.school, 'group.children')\n\n    As a filter:\n        states | closest\n        states.device_tracker | closest\n        ['group.children', states.device_tracker] | closest\n        'group.children' | closest(23.456, 23.456)\n        states.device_tracker | closest('zone.school')\n        'group.children' | closest(states.zone.school)\n\n    "
    if (len(args) == 1):
        latitude = hass.config.latitude
        longitude = hass.config.longitude
        entities = args[0]
    elif (len(args) == 2):
        point_state = _resolve_state(hass, args[0])
        if (point_state is None):
            _LOGGER.warning('Closest:Unable to find state %s', args[0])
            return None
        if (not loc_helper.has_location(point_state)):
            _LOGGER.warning('Closest:State does not contain valid location: %s', point_state)
            return None
        latitude = point_state.attributes.get(ATTR_LATITUDE)
        longitude = point_state.attributes.get(ATTR_LONGITUDE)
        entities = args[1]
    else:
        latitude = convert(args[0], float)
        longitude = convert(args[1], float)
        if ((latitude is None) or (longitude is None)):
            _LOGGER.warning('Closest:Received invalid coordinates: %s, %s', args[0], args[1])
            return None
        entities = args[2]
    states = expand(hass, entities)
    return loc_helper.closest(latitude, longitude, states)