Long Term Statistics for person

Hi everyone,
I would like the long term statistic to keep data on persons (home and away, or ultimatley where they are). Is there any way to do that?
person entities don’t show up on developer tools → statistics.
How do I get this to work?

Cheers!

LTS seems to be only supported for numerical values.
Consider 3rd party plugins to store data for a long period.

Just create a numerical template sensor storing a copy of the person state as a number (with a bogus unit of measure and state class of measurement). I’ve been doing this for quite a while now and it works well enough.

Long term statistics only work for sensors that have a state_class of measurement, total or total_increasing.

1 Like

Ofc, but first these values must be numerical.

Was also thinking about such a workaround…
Did you find a way to back-convert these numerical values to “normal zones” while displaying graphs in your history-explorer-card (which supports LTS)?
I mean a scenario “select a point and see a zone name in a tooltip”.
Another option could be a kind of “color_thresholds” on a graph: you can see a zone by its color.

Yeah I display them in the history explorer, which can simply convert them back to a home/away/arriving/leaving/etc text value displayed as the usual colored timeline by using a simple process function.

One thing to keep in mind though is that long term statistics are only stored once per hour. You will lose time precision in your sensor data in LTS and the recorder will downsample your data. That may or may not be a problem for your use case.

A per-entity retention policy would entirely solve this problem natively. Storing the actual accurate history for something as low frequency as person presence state would take very little space in the DB even for very long time periods.

1 Like

Right.
Travelling between zones may have many changes within an hour.

Also, there could be an issue with “back-converting”.
Assume “home” = 100, “school” = 120, “shop” = 130 etc.
LTS creates a “mean” value; so if a graph shows “125” - then what is this place?
We should probably define numerical values dependently on a distance between a Home and a particular zone.

I was also thinking about LTS for “latitude” & “longitude”.
But currently there is no way to feed 2 LTS series to a Map card (+select a period in the past).

You probably mean a “purge_keep_days” per entity.

Usually you would use thresholds for that, ie. quantization of linear data. Of course that fails if your person state changed multiple times in one hour, then you’ll end up with some meaningless average. But in practice, if you only have two or three states (home,not_home,arriving in my case), that isn’t really much of a problem.

Yes.

Also, for “home / not_home” case we may just use History stats “time spent home a day” which is kept in LTS.
Or create a template sensor with calling a “distance()” function.

I wouldn’t be surprised if enum sensors make it into LTS in the future. Until then, use these work arounds.

1 Like