A Home Assistant custom component to import historical sensor data from one entity into another.
Built for migrating sensor data between integrations — for example, when replacing an Ecowitt integration with a different one and you want the new sensors to carry the old sensors' history.
- Sidebar panel with a simple UI: select source/destination pairs, click Import
- Imports both states and long-term statistics (hourly aggregates for energy dashboard / long-term graphs)
- Atomic transactions: either all states are imported or none are — no partial imports that leave gaps
- Idempotent: safe to re-run; a successful import shifts the cutoff so nothing is re-imported, and a failed import is fully rolled back
- Entity filter to quickly find sensors by keyword
- Also available as a service (
merge_sensor_history.import_history) for use in automations or Developer Tools - HACS compatible
- Reads all historical states from the source entity via the recorder API
- Queries the destination entity's oldest existing entry (inside the same DB transaction)
- Imports only source states that are strictly older than that oldest entry — this prevents any overlap or duplication
- Imports long-term statistics (hourly mean/min/max/sum) via the official
async_import_statisticsAPI, which is inherently deduplicated by the database schema - Commits everything in a single transaction — if anything fails, the entire import is rolled back and you can safely retry
| Data | Source | Granularity | Retention |
|---|---|---|---|
| States | states table |
Every state change | Limited by recorder purge (default ~10 days) |
| Statistics | statistics table |
Hourly aggregates | Kept indefinitely |
HA does not regenerate statistics from states retroactively. Both are imported separately to ensure complete history coverage — including long-term statistics from periods whose raw states have already been purged.
- Open HACS in your Home Assistant instance
- Click the three dots in the top right corner, select Custom repositories
- Add
https://github.com/mayerwin/HA-Merge-Sensor-Historyas an Integration - Search for "Merge Sensor History" and install it
- Restart Home Assistant
- Copy the
custom_components/merge_sensor_historyfolder into your Home Assistantconfig/custom_components/directory - Restart Home Assistant
- Go to Settings > Devices & Services > Add Integration
- Search for Merge Sensor History
- Click Submit — this enables the integration and adds the sidebar panel
- Click Merge History in the sidebar
- Select a source entity (the old sensor with historical data)
- Select a destination entity (the new sensor you want the history imported into)
- Use + Add Pair to queue multiple imports at once
- Use the filter field to narrow down entities by keyword (e.g.,
ecowitt,temperature) - Click Import History
- Review the results — each pair shows how many states and statistics were imported
You can also call the service directly from Developer Tools or automations:
service: merge_sensor_history.import_history
data:
source_entity_id: sensor.ecowitt_outdoor_temperature
destination_entity_id: sensor.outdoor_temperature- Back up your database before importing. The integration writes directly to the recorder database.
- Only data still in the recorder can be imported. States are purged by default after ~10 days. Long-term statistics (hourly) are kept indefinitely.
- After importing, the new history will appear in the History panel. You may need to refresh the page or wait for the next recorder cycle.
- The import is a one-time operation, not a continuous sync. Run it once after setting up your new sensors.
- Home Assistant 2024.1.0 or newer
- The source entity must still have history in the recorder database
Use this integration at your own risk. Always create a full backup of your Home Assistant instance (including the database) before using this tool.
This integration manipulates internal Home Assistant recorder data (states and statistics tables) using internal APIs that are not part of Home Assistant's public API surface. These internals may change without notice in future Home Assistant releases, which could cause this integration to malfunction or produce unexpected results. The authors are not responsible for any data loss, corruption, or other issues arising from its use.
MIT — see LICENSE