Is there a way to notify openHAB just before a phone dies?

This shows you how to implement hmerk’s approach.

If you have reliable entry/exit sensors you can also use a simplified wasp-in-the-box algorithm in your rules and only count yourself as away when your phone’s wifi goes off and a door has opened and closed very soon before. The amount of time will depend on how long it typically takes your phone to disconnect when you leave.

The State Machine Design Pattern could be informative.

2 Likes