OwnTracks multiple region tracking (i.e. room-tracking using iBeacons)

Although an easy and simple change to commit, let’s run it by the community first.

Case at hand: BLE-tracking (which doesn’t work with the privacy of iOS devices)
So I switched my ESP32s to iBeacons and set up OwnTracks accordingly.

There are a number of posts on how to change your lat/lon and make this work, but I have no issue with OwnTracks and HASS detecting my at home and adding multiple regions. Owntracks does play nice and submits to the bus accordingly:

{"batt":50,"lon":1.23,"acc":65,"p":180.2,"vac":10,"lat":4.56,"inregions":["Home","Beacon1","Beacon2"],"t":"u","conn":"w","tst":1544042004,"alt":20,"_type":"location","tid":"MeMyselfI"}

Therefor I’d propose an easy change to homeassistant/components/device_tracker/owntracks.py:

--- owntracks.py.orig   2018-12-05 21:27:54.691301504 +0100
+++ owntracks.py        2018-12-05 21:20:27.093133772 +0100
@@ -85,6 +85,8 @@
         kwargs['gps_accuracy'] = message['acc']
     if 'batt' in message:
         kwargs['battery'] = message['batt']
+    if 'inregions' in message:
+        kwargs['attributes']['inregions'] = message['inregions']
     if 'vel' in message:
         kwargs['attributes']['velocity'] = message['vel']
     if 'tid' in message:

Making it just as simple to do things like:

{%- if 'Waypoint_name_of_beacon' in states.device_tracker.somedevice.attributes.inregions -%}
Thuis,
{%- endif -%}

Just trying to get room-detection working nicely without abusing things seems to work rather fine (even in a two-story home) so far. Using some sensor templates from here with the if … in construction should provide a nice way forward :slight_smile:

Looking forward to comments.