From 87a9fd825230bdbbd88e3305280cdb4118e9bb0a Mon Sep 17 00:00:00 2001 From: pavoni Date: Fri, 22 Jan 2016 11:30:04 +0000 Subject: [PATCH] Handle race condition on startup. --- homeassistant/components/sensor/template.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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)