From 171086229aa07990cfb13a8095ce0d3fc6813d74 Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Sun, 21 May 2017 07:41:33 -0700 Subject: [PATCH] Guard against new and removed state change events (#7687) --- homeassistant/components/automation/state.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/automation/state.py b/homeassistant/components/automation/state.py index 185d44808c3..fbd1570a1e0 100644 --- a/homeassistant/components/automation/state.py +++ b/homeassistant/components/automation/state.py @@ -45,6 +45,7 @@ def async_trigger(hass, config, action): time_delta = config.get(CONF_FOR) async_remove_state_for_cancel = None async_remove_state_for_listener = None + match_all = (from_state == MATCH_ALL and to_state == MATCH_ALL) @callback def clear_listener(): @@ -77,8 +78,8 @@ def async_trigger(hass, config, action): }) # Ignore changes to state attributes if from/to is in use - match_all = (from_state == MATCH_ALL and to_state == MATCH_ALL) - if not match_all and from_s.last_changed == to_s.last_changed: + if (not match_all and from_s is not None and to_s is not None and + from_s.last_changed == to_s.last_changed): return if time_delta is None: