Get Recorder history

Use this action to retrieve recorded state history for one or more entities over a time period. This is handy when an automation or script needs raw historical state transitions, for example to detect sequences, calculate durations, or apply custom logic based on past states.

This action returns its result in a response variable, which you can use in later steps of the same automation or script.

Only users with administrator rights can run this action.

Note

History is retrieved from the recorder database and is subject to your recorder retention period (purge_keep_days, which defaults to 10 days).

Using this action from the user interface

If you prefer building automations and scripts visually, Home Assistant walks you through this action step by step. You pick what to target, tweak a few options, and save. No YAML knowledge required.

To get history from an automation or a script:

  1. Go to Settings > Automations & scenes.
  2. Open an existing automation or script, or select Create automation > Create new automation.
  3. If you’re setting up a new automation, add a trigger in the When section. Scripts don’t need a trigger. They run when something else calls them.
  4. In the Then do section, select Add action.
  5. From the list of actions, search for and select Get Recorder history.
  6. Set the options you want to use.
  7. In Response variable, enter a variable name to store the result, for example entity_history.
  8. Select Save.

Options in the UI

Entities

The entities to return history for.

Start time

The start of the period to return history for.

End time (Optional)

The end of the period to return history for. If omitted, returns all history from the start time onward.

Allow truncation (Optional)

Truncate the returned history instead of raising an error when an entity exceeds the limit of recorded state changes. The limit applies to recorded state changes, not returned segments.

Using this action in YAML

If you work directly in YAML, or you want to know exactly what Home Assistant does under the hood, this section has the technical reference. It lists the field names you use in YAML, their types, and which ones are required. For how an automation or a script is built in YAML, refer to Automations in YAML and Scripts.

In YAML, refer to this action as recorder.get_history. Store the result in a response variable so you can use it in later steps:

ActionAn action makes Home Assistant do something, for example, turn on a light, send a notification, or activate a scene. Automations and scripts run a list of actions. [Learn more]
action: recorder.get_history
data:
  entity_id:
    - input_boolean.away_mode
    - sensor.hvac_action
  start_time: "2025-10-06 11:00:00"
  end_time: "2025-10-06 12:00:00"
response_variable: entity_history

Options in YAML

entity_id list Required

The entity IDs to return history for.

start_time string Required

The start time for the history query, such as 2025-10-06 11:00:00. Must be in the past.

end_time string (Optional)

The end time for the history query. If omitted, returns all history from the start time onward.

allow_truncation boolean (Optional, default: false)

Truncate the returned history instead of raising an error when an entity exceeds the limit of recorded state changes. The limit applies to recorded state changes, not returned segments.

Response data

The action returns a nested history mapping containing only entities and time spans with available recorded history. Each entity contains a list of state segments:

  • start: The start timestamp of the state segment (ISO 8601 UTC).
  • end: The end timestamp of the state segment (ISO 8601 UTC).
  • state: The state value during this segment.

When allow_truncation: true is enabled, the response also includes a truncated list containing the entity IDs of any entities whose recorded history was truncated (or an empty list if none were truncated).

An example of the response looks like this:

history:
  input_boolean.away_mode:
    - start: "2025-10-06T11:00:00+00:00"
      end: "2025-10-06T11:02:30.052671+00:00"
      state: "off"
    - start: "2025-10-06T11:02:30.052671+00:00"
      end: "2025-10-06T12:00:00+00:00"
      state: "on"
  sensor.hvac_action:
    - start: "2025-10-06T11:00:00+00:00"
      end: "2025-10-06T12:00:00+00:00"
      state: "idle"

Good to know

  • Consecutive duplicate states: Consecutive duplicate state values recorded across Home Assistant restarts or frequent sensor reports are merged into a continuous state span.
  • Timestamp clamping: If an entity had a state established before start_time, its start timestamp is clamped to start_time so all returned segments fit cleanly within the requested window.
  • Limit and truncation: Each entity is capped at 1,000 records. To prevent automations from silently acting on partial data, the action raises an error by default if the database query exceeds 1,000 recorded changes. When allow_truncation: true is set, results are truncated at the limit, which may cover only an earlier portion of the requested time window and result in fewer than 1,000 segments after duplicate states are merged.
  • Force updates: Entities that use force_update record a row on every update, even if their state does not change. They reach the limit sooner than their returned history suggests, which can result in a lot fewer than 1,000 returned segments.
  • Attributes: Only state values are returned; state attributes are not included.
  • Statistics vs. state history: To retrieve periodic aggregated statistics (such as min, max, mean, or sum) rather than raw state transitions, use the recorder.get_statistics action instead.

Still stuck?

To test the action on its own, run it in the automation editor with Run action, and check the message that it shows. To see what the action did when the automation ran, open the trace of that run. For details, refer to Testing automations. For common problems and their solutions, refer to Troubleshooting automations.

If that doesn’t help, the Home Assistant community is quick to help: join Discord for real-time chat, post on the community forum with the action you’re calling and what you expected to happen, or share on our subreddit /r/homeassistant.

Tip

AI assistants like ChatGPT or Claude can also explain actions or suggest the right one when you describe what you want in plain language.

Related actions

Explore related actions: