Yes, I have restarting often as I have been working on my Home Assistant a bunch the last few days. What you said makes sense, why didnāt I think about that.
Iām still confused after reading that thread. Is it true or a rumour?
The code tries to get back into sync after a restart. So if it purged last night at 9PM and you restart today at 6PM, it should purge in about 3 hoursā time (with a lower limit of 30 minutes).
So I guess the fully correct way to state it is that it can take up to 24 hours.
Hi,
i dont use this because its āglobalā.
āsomeā of my sensordata should be purged the next day some of them should keeped over a longer period.
to add this you need sqlite3 and a external script - running as cronjob on your system.
eg: i have a sensor ānext holidays (next_free)ā or ānext garbage date & type (sensor.fes)ā
Itās nice to knew the actual state but the state from yesterday is just garbage.
Here is a cutout from my script - save it somewhere, make it executable
check if your database is in the same path as on my setup
(/usr/share/hassio/homeassistant/home-assistant_v2.db)
all the āmagicā happens here:
drop everything from sensor.fes older than 1 day:
statement=ā$older_states_than 1 daysā) AND entity_id LIKE ā%sensor.fes%āā
and run the script \edit with sudo./edit
When the output looks good for you - change remove the # in front of the sqlite3 and add them infront of the echo lines.
#!/bin/bash
#var
db=/usr/share/hassio/homeassistant/home-assistant_v2.db
older_events_than="time_fired < datetime('now','-"
older_states_than="created < datetime('now','-"
#stop HA
docker stop homeassistant
#backup db
cp $db ~/home-assistant_v2.db
events() {
echo sqlite3 $db "SELECT * FROM events WHERE $statement;"
#sqlite3 $db "DELETE FROM events WHERE $statement;"
}
states() {
echo sqlite3 $db "SELECT * FROM states WHERE $statement;"
#sqlite3 $db "DELETE FROM states WHERE $statement;"
}
#events
statement="$older_events_than 1 days') AND event_data LIKE '%%next_free%%'"
events
statement="$older_events_than 1 days') AND event_data LIKE '%sensor.fes%'"
events
#states
statement="$older_states_than 1 days') AND entity_id LIKE '%sensor.fes%'"
states
#rebuild db
sqlite3 $db "vacuum;"
#start HA
docker start homeassistant
I dug into the history. It seems that it used to be true, so not a rumor. However, it is no longer true since November 2017 where PR #10279 was merged.
This is true. I notice the created, changed and last opened time stamps on the db file ate all identical to the time I executed the recorder.purge command.
What if some script back-dated the file date of the db file everytime HA starts?
ā¦ or is the purge interval timer a separate entity within HA?
As of version 0.109, the default is for purge to run at 04:12 every morning, whether you have restarted or not.
Recorder - The recorder configuration purge_interval has been deprecated. The recorder database is now purged every night. This can be disabled with the new auto_purge configuration though that is usually not recommended. - (@amelchio - #33646) (recorder docs)
it will autodelete everything older than 1 day. The database size wonāt change with those settings though. To make it run now, you can call the service from dev tools.