Store date/time of last time in a zone

Hey all,

I had an idea for an automation I’d like to create but I don’t know how to go about doing it. The idea is:

Every time I enter specific zones I’ve defined I’d like to get a push notification telling me:

  1. The last time I was in that zone (probably the time when I left the zone.)
  2. How long time has passed since I was there
  3. …and possibly, how long time I spent there last time I was there.

To get 1 and 2, I somehow need to - every time I leave the specific zone(s), update some kind of variable (or sensor?) with a timestamp - like “last_time_left_office” … and then use that value in a magic template for my push notification.

I think my biggest hurdle (for now) is how to best store that value. Do I use an input_text? Do I publish to MQTT? Needless to say, the value has to survive restarts/reboots… If anyone can give me some advice I’d be most grateful. Thanks!

I would create two input_datetimes, one for enter and one for leave.
Then set up an automation to set the datetimes when you state is to or from this zone.

That should be able to get you all the times.

That makes a lot of sense. Thanks!