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

I have googled around looking for a trick to let openHAB know the difference between a dead phone and a disconnected one. There seem like countless ways to notify your phone if openHAB does something but so far I have found no mention of the reverse. One of the many reasons I’ve adopted openHAB was to centralize user detection and remove the need for the Tasker task I use to use for wifi detection. On occasion if I had too many apps open it could take up to 3 minutes for my phone to clue in that it had connected to my wifi before it turned the lights on.

The PC I’m running openHAB on is a media server and has tones of over head so it pinging my phone works like a dream for presence detection, with the added bonus that I can now add anyone as a guest with presence detection just by adding a line to my items file! Only hiccup is I kill my phone 50% of the time by about 8 or 9pm. Atm this hasn’t caused an issue as my partner is usually home but I do fore see a time I’m home alone and my phone dies which will result in the lights turning off on me after 5min. If I ran to a charger this may be enough time but because I run xposed and a few other root tweaks my phone actually takes almost 5min to boot and if I actually drained it to 0% she needs an extra 5min to get up to 10%-15% otherwise just the boot up will kill it again haha.

So I am looking for any method at all, I’m guessing using something like Tasker on android to have my phone send a text notification to openHAB any time it hits say 5% and is connected to my local wifi. That way I could make a rule that would leave that phones presence value set to ON if openHAB received 5% notification in the last hour before it disconnected. Any idea or method is appreciated my android is rooted so their should be options and I’m only worried about it for my own phone I don’t mind if its to complicated to setup for guests or requires root.

Fingers Crossed someone has an idea I’m a bit surprised this was never thought of to be honest! Thanks either way to any suggestions.

If I understand you right, you mainly need to inform openHAB if battery level reaches a minimal value.
This can easily be achieved with a tasker task, no root needed.

Automate can do that to.
You can define an action @ pre-defined battery level.

The Owntracks app can also report battery levels - so if you are using that for presence detection it is not that hard to extract the batt value from the payload and assign to an openHAB item.


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.


@hmerk perfect i completely forgot tasker could do many tasks on unrooted phones too! @rlkoshak thank you for the link thats really what I was looking for I figured I could use tasker but thought id need an addon I’m pumped I don’t and I really like the http communication method this should all mean minimal over head. I also dont have a door sensor atm in the future I was thinking a smart lock and have considered that style of rule funny I never knew of it as a “wasp in a box” I plan to add it later its just not in my current budget!

I like this method as well. I have even done dashboards in dashing to capture battery in to graphs.