Is it possible to limit or disable storing GeoLocation data in Home Assistant (e.g. sensor.<device>_geocoded_location)?
I don't want to disable geolocation all together, because in the present (right now), I do want to know where a device is located to run zone-based automations.
However, I do not want to retain this data (beyond a certain period of time anyway).
One way, perhaps the simplest way, would be to create a UNIQUE index on the respective column or columns that form the data for which you want only 1 row to exist and then use an
INSERT OR IGNORE. If the UNIQUE constraint (rule) is broken then the INSERT will be IGNOREd.The PRIMARY KEY, which can be a composite (made up of more than 1 column) is implicitly UNIQUE so is a candidate for the index
Perhaps consider the following demonstration, that may well mimic the assumed requirement from your question.
The first insert will insert 4 of the 5 (see comments in the SQL) as per:-
The second insert will not change anything as every row has already been inserted and thus will be in conflict with the UNIQUE PRIAMRY KEY:-
However, the third insert will not insert any rows BUT WILL update all rows (actually delete and insert as that is how REPLACE works):-
As can be seen the new value for the other_column has been changed accordingly.
Note the rowid. This is a normally hidden column that will exist in all normal tables (not in tables defined with the
WITHOUT ROWIDclause). It's value will be generated unless aliased and a value is provided. It will typically be 1 greater than the highest existing rowid.The result clearly shows that the rowid has changed. This is because the REPLACE deletes the row and then inserts another and thus generates another rowid that is 1 greater than highest existing rowid.
e.g.
hence why the rowid was included in the selects. Of course the rowid is frequently ignored (although it can be useful at times)
The above is just an overview of some of the pertinent matters. You may wish to refer to (and links contained in the following) for a more comprehensive explanation :-