From dcb04acc6575c18aff654b7ed1e623760ba3a7af Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Wed, 3 Jun 2020 20:08:37 +0200 Subject: [PATCH] Set automation last_triggered earlier (#35671) Co-authored-by: Paulus Schoutsen --- homeassistant/components/automation/__init__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/automation/__init__.py b/homeassistant/components/automation/__init__.py index 9fabe0e2206..8b2c036034b 100644 --- a/homeassistant/components/automation/__init__.py +++ b/homeassistant/components/automation/__init__.py @@ -389,6 +389,8 @@ class AutomationEntity(ToggleEntity, RestoreEntity): trigger_context = Context(parent_id=parent_id) self.async_set_context(trigger_context) + self._last_triggered = utcnow() + self.async_write_ha_state() self.hass.bus.async_fire( EVENT_AUTOMATION_TRIGGERED, {ATTR_NAME: self._name, ATTR_ENTITY_ID: self.entity_id}, @@ -402,9 +404,6 @@ class AutomationEntity(ToggleEntity, RestoreEntity): except Exception: # pylint: disable=broad-except pass - self._last_triggered = utcnow() - self.async_write_ha_state() - async def async_will_remove_from_hass(self): """Remove listeners when removing automation from Home Assistant.""" await super().async_will_remove_from_hass()