diff --git a/homeassistant/util/template.py b/homeassistant/util/template.py
index 25d65855ef6e2f5676b52366e94ac3212a887549..7b00fb6dcc1d1cb7a8c063dd5ae0e456c8f21cc6 100644
--- a/homeassistant/util/template.py
+++ b/homeassistant/util/template.py
@@ -156,12 +156,12 @@ class LocationMethods(object):
             states = list(entities)
         else:
             if isinstance(entities, State):
-                entity_id = entities.entity_id
+                gr_entity_id = entities.entity_id
             else:
-                entity_id = str(entities)
+                gr_entity_id = str(entities)
 
             states = [self._hass.states.get(entity_id) for entity_id
-                      in group.expand_entity_ids(self._hass, [entity_id])]
+                      in group.expand_entity_ids(self._hass, [gr_entity_id])]
 
         return loc_helper.closest(latitude, longitude, states)
 
diff --git a/tests/util/test_template.py b/tests/util/test_template.py
index 426d90bd4d9f97a07278e0512f4c58c0c0419224..7a0b990a04a91aaa6e3b33131d92d59acbf2af1d 100644
--- a/tests/util/test_template.py
+++ b/tests/util/test_template.py
@@ -292,7 +292,6 @@ class TestUtilTemplate(unittest.TestCase):
                 self.hass,
                 '{{ distance("123", states.test_object_2) }}'))
 
-
     def test_closest_function_home_vs_domain(self):
         self.hass.states.set('test_domain.object', 'happy', {
             'latitude': self.hass.config.latitude + 0.1,