[Presence] New concept: not polling but publish from mobile


#1

Like other users, I have experienced very bad presence detetion systems, and finally I was getting a really reliable method that is rather different to all device tracker presence components in HA.

Almost every device tracker in HA are based in polling at fixed scan interval, usually from HA point of view, and all of them has very poor reliable with false positives and negatives. You can see the introduction [Presence] Reliable, Multi-User, Distributed BT Occupancy/Presence Detection of andrewjfreyer method about.

I have prospecting for another point of view: The intelligence of presence is in the mobile (supposed all family components has their own mobile), that publish the presence to HA, only when there are changes, and with the minimum battery ussage.

In my opinion, presence (primary at home) is a primary element for all automation system, and if it fails, all over around dont work as expected.

Currently I am working in a really reliable system that uses Android (sorry about IOS) app called http://automagic4android.com/en/

If you dont know about it, its like other "tasker" apps: like a home assistant automation system inside Android. People with ACD (Automate Compulsive Dissorder :wink: like me could find this an amazing world for automation…

I would like to share my flows, as they can be imported/exported as xml files.

The use is as follows:

You define your zones as wifi, or cell, or both. With wifi, you can use level (RSSI) to accurate distance. With cell (gsm) define big zones or proximity to a zone state to increase scan frequency.

When wifi scan detect a defined wifi with a level => you enter in a zone

If the actual_zone is different from last_published_zone => publish new zone, and if all ok, update last_published_zone

Publish a zone is http post to api/services/device_tracker/see (we can publish battery, user activity, etc….). When define cells (gsm) for a zone, acts like a “approximation” to a zone, so force the wifi scan to i.e. 10 seconds… so “entering in home” with gsm cells and rssi wifi level can be almost EXACT (I could open the garage door when I arrive because it is working really fine).

When connected to wifi, stop the scan, and when disconnect, start again.

The battery usage is really unperceptible, and reliability is maximum. You can define as many zones as you want. You don’t need to have wifi on.

The only failure is when have the mobile shutdown entering and outgoing from zones.

CONS:

  • Only Android supported.
  • Automagic4android is payed app (2$). There are old free version with 4 limit flows.

From here there are an open world of possibilities:

  • zones defined in HA and downloaded from android app.

  • An android app that works like the this scripts in Automagic

  • Bluetooth scan from mobile, i.e. when connect to BT car => user state is “driving”. Even more accurate possition inside home, or in work (on site).

  • Publish USER ACTIVITY android state (when you are ONFOOT, RUNNING, DRIVING, IN_BED, etc).

  • Recently I have discover TERMUX and TERMUX API, and probably could be easy to script same functionality (you can run python in termux in android!!!).


#2

So this involves opening HA to the internet?


#3

I’m doing something similar with Automate and a MQTT Publisher Plugin for Tasker (which Automate can use too). When doing nothing fancy the free version of Automate can do this. And somehow I’m more comfortable with exposing MQTT than exposing HASS.


#4

Yes.
Really, I am exposing ONLY this api (api/services/device_tracker/see).


#5

I have been working with 3 alternatives (Automate, Tasker and Automagic) and for me, Automate was not working fine. All of them support tasker plugin so MQTT can be ussed.

But I am prospecting TERMUX. Seems that has been reported to work even mosquitto broker over termux!!!


#6

Sounds great and something i am looking for. I installed the app and would appreciate if you can share your flows. Thanks


#7

My configuration is working fine, but I am trying to make it more friendly user, robust, scalable, etc.

Now i am defining a json file with globbla parameters (host, passwd, intervals, publish battery, location, intervals, etc.) and obvously zones definition:
Will be a list of dictionaries defining: wifi list (ssid, bssid and rssi), cells list, bluetooth device list, location interval, …

(A wifi zone can contain another wifi zone, so order definition is important)

Maybe this week I can upload a first version of flows, and json config examples.


#8

i am currently running home assistant on android via termux. It works great and installs easy in a virtual enviroment . but so far cant get bluetooth tracking to work . and this is home assistant not hassio so no add ons , config file is a litle tuff to set up for editing as well . just fyi if planning on triing the android route haven’t given up yet but not sure bluetooth is going to work that way because cant seem to install pybluez or bluetooth. there is tons of info here,


i cant attest to mosquitto but have node red running as well on android.