Hi,
through phpadmin, I can connect to the MariaDB database and delete the data of a sensor with this command: DELETE FROM homeassistant.states WHERE ʻentity_id` LIKE ‘% sensor.cputemperature%’ LIMIT 250
Would it be possible to automate this command with HomeAssistant (HASSOS)?
Thanks for the reply,
I already use recorder, but there are some sensors that I would like to keep for a long time, others delete them every day, others leave the last 250 results
Your sample deletes 250 records, not keeps them. Maybe it is just a sample query and not the real one, but this deletes 250 records based on the order they show up in the result set. Since there is no order by, it might be the newest records that get deleted…
Yes,
sorry mine was an example query, the suitable one according to the sensor.
What should I do to delete older data?
It would be fine, indeed it would be better, if you could indicate, for example, the last 3 days
echo "DELETE FROM homeassistant.states WHERE ʻentity_id` LIKE ‘% sensor.cputemperature%’ LIMIT 250" | mysql --defaults-extra-file=filename databasename
conn = sqlite3.connect (DB_PATH)
c = conn.cursor ()
for eid in ENTITY_IDS:
c.execute (“DELETE FROM events WHERE event_data LIKE?”, (’% \ "entity_id ": \ “’ + eid + '”%’,))
c.execute (“DELETE FROM states WHERE entity_id =?”, (eid,))
I should report this shell command:
echo “DELETE FROM homeassistant.states WHERE ʻentity_id` LIKE ‘% sensor.cputemperature%’ LIMIT 250” | mysql --defaults-extra-file = homeassistantMyPass homeassistant