diff --git a/homeassistant/components/recorder/models/state.py b/homeassistant/components/recorder/models/state.py index 01a9e3a332b..c443525701a 100644 --- a/homeassistant/components/recorder/models/state.py +++ b/homeassistant/components/recorder/models/state.py @@ -144,8 +144,10 @@ def row_to_compressed_state( } row_last_updated_ts: float = row.last_updated_ts comp_state[COMPRESSED_STATE_LAST_UPDATED] = row_last_updated_ts - if row_last_updated_ts != ( - row_changed_changed_ts := getattr(row, "last_changed_ts", None) + if ( + (row_last_changed_ts := getattr(row, "last_changed_ts", None)) + and row_last_changed_ts + and row_last_updated_ts != row_last_changed_ts ): - comp_state[COMPRESSED_STATE_LAST_CHANGED] = row_changed_changed_ts + comp_state[COMPRESSED_STATE_LAST_CHANGED] = row_last_changed_ts return comp_state