def state_changes_during_period(start_time, end_time=None, entity_id=None):
Return states changes during UTC period start_time - end_time.
where = "last_changed=last_updated AND last_changed > ? "
data = [start_time]
if end_time is not None:
where += "AND last_changed < ? "
data.append(end_time)
After Change
def state_changes_during_period(start_time, end_time=None, entity_id=None):
Return states changes during UTC period start_time - end_time.
states = recorder.get_model("States")
query = recorder.query("States").filter(
(states.last_changed == states.last_updated) &
(states.last_changed > start_time))
if end_time is not None:
query = query.filter(states.last_updated < end_time)
if entity_id is not None:
query = query.filter_by(entity_id=entity_id.lower())
states = recorder.execute(
query.order_by(states.entity_id, states.last_updated))
return states_to_json(states, start_time, entity_id)