Evolution for history_stats sensor, or "machine learning sensor"

Hey guys,

I’m using a history_stats sensor to count how many wifi beacons I detected during last X minutes to detect presence. This is very useful when for some reason my phone is not connected to my wifi network and that works absolutely fine (wifi beacons are detected with a D1 mini and sent to mqtt)

What if the history_stats sensors goes one big step further?

My goal is to predict my presence (now) based on historical data over the last few same days, same time.

For example (Today is Wednesday, time is 17:00)
In the example below, the sensor should search on the previous 3 Wednesdays between 16:55 and 17:00, and return a percentage based on how many states “home” it has found vs everything else other than “home”.

I could do the same by creating 3 history_stats sensors

sensor:
  - platform: predict (or whatever new name)
    name: My Presence Prediction
    entity_id: sensor.my_presence
    state: 'home'
    days: 3
    duration:
      minutes: 5

Just in case someone was interested, I just discovered the SQL sensor which will allow me to do exactly the same thing by running some fancy SQL queries to get some intelligence in my system.

The goal of this in my use case is to “predict” presence/absence in the next X minutes, based on historical data for the same week day in the past (example, last 3 mondays at time + X minutes.

This will allow me to set my climate integrations to a warmup temperature before I actually get home, and then once I’m home my existing automations will set the heating as usual.

Or the other way round, set the temperature to a lower value when it “thinks” I’ll be away in a few minutes, and then once I’m away my other automations will set the climate to away mode as usual. But this is a bit trickier.

Yeah this is just an experiment, if it work fine, if it doesn’t I will get stick to my existing automations based on away/home state.

But, the suggestion on the “predict” sensor still stands.