diff --git a/homeassistant/components/sensor/template.py b/homeassistant/components/sensor/template.py index ecd6f092097..eeb764e70a5 100644 --- a/homeassistant/components/sensor/template.py +++ b/homeassistant/components/sensor/template.py @@ -77,7 +77,10 @@ class SensorTemplate(Entity): def _update_callback(_event): """ Called when the target device changes state. """ - self.update_ha_state(True) + # This can be called before the entity is properly + # initialised, so check before updating state, + if self.entity_id: + self.update_ha_state(True) self.hass.bus.listen(EVENT_STATE_CHANGED, _update_callback)