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.
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:
- Go to Settings > Automations & scenes.
- Open an existing automation or script, or select Create automation > Create new automation.
- 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.
- In the Then do section, select Add action.
- From the list of actions, search for and select Get Recorder history.
- Set the options you want to use.
- In Response variable, enter a variable name to store the result, for example
entity_history. - Select Save.
Options in the UI
The end of the period to return history for. If omitted, returns all history from the start time onward.
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:
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
The start time for the history query, such as 2025-10-06 11:00:00. Must be in the past.
The end time for the history query. If omitted, returns all history from the start time onward.
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, itsstarttimestamp is clamped tostart_timeso 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: trueis 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_updaterecord 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_statisticsaction 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.
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:
-
Get Recorder statistics: Retrieves long-term statistics for one or more entities.
-
Purge Recorder database: Cleans up old data from the recorder database.
-
Purge Recorder entities: Removes recorded data for specific entities, domains, or patterns.
-
Enable Recorder: Resumes recording events and state changes to the database.
-
Disable Recorder: Stops recording events and state changes to the database.