In Part 1 I talked about using iBeacons to improve presence tracking. In part 2 I’ll talk about how to track things like keys that can’t track themselves by using iBeacons.
In the first part I mentioned that iBeacons just send out I’m here packets, and we used this to trigger an update when your phone came close to a fixed beacon.
But beacons don’t have to be fixed.
Your phone knows roughly where it is located (based on mobile phone masts, Wi-Fi networks or GPS). If your phone sees an I’m here message then it knows the beacon is close.
If your phone can remember (or tell a server) where it was when it last saw the iBeacon - then it knows where the beacon was. So the result of this is that you can track where an iBeacon was - even though the iBeacon doesn’t have any tracking technology itself.
So if you put an iBeacon on your keys or in your car - then you can track them.
Here are my keys - with a Estimote Nearable iBeacon stuck to them. Ugly but effective!
It’s easier to set up OwnTracks and HA to track a mobile beacon than the fixed beacon I discussed in Part 1, because you only need to tell OwnTracks about your iBeacon. You don’t need to configure HA at all.
OwnTracks currently only supports mobile beacons on iOS.
You set up the beacon the same way as we discussed in part 1. The only difference is that instead of calling the region the name of a location (eg -drive) you call it the name of the device you want to track (eg -keys). Remember the leading ‘-’ that makes the connection more reliable.
Once you’ve added the iBeacon - you should be able to see it on the OwnTracks region screen. If your phone can see the packets from that beacon, OwnTracks will turn the relevant Region red.
Because you turned Share on for the region, when OwnTracks sees the beacon it will send HA a message. HA will use this message to add the beacon as a tracked device if it hasn’t seen it before. So you should see a new device appear in HA called device_tracker.beacon_[name] - and its location will be where your phone thought it was when it last saw the beacon.
If your phone moves and sends HA a new location while it is still in range of the beacon - HA will update the location of the beacon. So if go for a drive in your car - you will see both your phone and the device_tracker.beacon_car move together.
If you park your car and go shopping - device_tracker.beacon_car will stop moving.
With the basic tracking working - you can use automation to do things like open your gates if your car comes home
automation: - alias: 'Open gate' trigger: - platform: state entity_id: device_tracker.beacon_car from: 'not_home' to: 'home' condition: - condition: state entity_id: switch.gate state: 'off' action: service: switch.turn_on entity_id: switch.gate
Or warn you if you leave your keys behind
automation: - alias: 'Forgotten keys' trigger: platform: template value_template: '{{states.device_tracker.greg_gregphone.state != states.device_tracker.beacon_keys.state}}' condition: condition: template value_template: '{{ states.device_tracker.greg_gregphone.state != "home" }}' action: service: script.turn_on entity_id: script.send_key_alert - alias: 'Forgotten keys - cancel' trigger: platform: template value_template: '{{states.device_tracker.greg_gregphone.state == states.device_tracker.beacon_keys.state}}' condition: - condition: state entity_id: script.send_key_alert state: 'on' action: service: script.turn_off entity_id: script.send_key_alert
script: send_key_alert: sequence: - delay: minutes: 2 - service: notify.notify data: message: 'You forgot your keys' target: 'device/gregs_iphone'
(The delay is needed for two reasons: -
1. HA updates the beacon and phone locations at slightly different times - so you don’t want the automation to trigger in the gap between the updates
2. I’ve found that beacons (especially the low power Estimote Nearables) can get disconnected for a few seconds so it’s best to wait a minute or so before deciding that you’ve left your keys behind)
Of course you can use both fixed and mobile beacons at the same time. I want my gates to open when I arrive home in the car - so I use an iBeacon in the car so that I can track the car, and a iBeacon on my drive so that a location update is triggered when I arrive. I’ve been experimenting with a high power beacon in a waterproof box on my drive which seems to work well to notice when I get home.
Long range / High power beacon
Waterproof beacon
This isn’t a buyer’s guide, but I just wanted to mention the iBeacons I’ve been using. I think you should be able to use any iBeacon with HA and OwnTracks. You generally can’t buy beacons in your local electronics shop - so I just wanted to briefly mention the two suppliers I’ve used so far.
I’ve bought quite a few iBeacons from a company called Blue Sense Networks. I work in the tech startup sector in the UK so I partly chose them because they are a local start-up who seemed worth supporting. The products, support and software all seem good. I use a number of their beacons - from a simple USB dongle, to a long range beacon. All their products have batteries that can be changed (or no batteries in the case of the externally powered USB device) - and you can configure all the parameters you’d want to using their software. I had one software issue, support got back to me at a weekend(!) - and the issue was resolved with a software release two days later.
All the beacons seem fine - and the long range unit does work over a longer range than my other beacons.
I bought some other beacons from a US/Polish startup called Estimote, who I think are better known. I bought a developer pack of 10 of their nearables which as well as being iBeacons also send out other data (orientation and motion) using their own protocol. This is interesting if you’re developing your own application, but for OwnTracks and HA they are just regular beacons. They are small and self adhesive - so you can stick them to things (like your keys). You can’t change all the parameters on these devices (UUID/Major/Minor are fixed) - and the batteries can’t be replaced. I also killed one of the estimote beacons (I assume the battery died) after I carried it around for a few months and dropped it many times! On the other hand they are well priced, small and waterproof!
I’ve mainly used these as devices to track rather that location beacons. Estimote also sell some slightly larger iBeacons with replaceable batteries. Estimote support responded quickly and were helpful when I couldn’t work out how to edit their beacon’s parameters (although the answer was you can’t yet).
The larger Blue Sense Network beacons seem to be better at maintaining a connection that the Estimotes - although that might be because I’m reluctant to turn the power to maximum and reduce the gap between sending packets on the Estimotes where I can’t replace the batteries!
As I said in part 1, I’ve found iBeacons to be a good way of improving presence detection. I also used them to track devices like my car and my keys that can’t track themselves.
I’m still experimenting, so I hope I can do more with iBeacons. I hope I’ve encouraged you do so the same. If you do please share your experiences.
Please see the notes at the end of Part 1 for documentation information.
]]>In 2013 Apple introduced iBeacons: a class of Bluetooth low energy (LE) devices that broadcast their identifier to nearby devices, including most smartphones. At first glance it’s hard to imagine why they might be useful. In this two part blog I’ll try and explain why they are useful and how you can use them with Home Assistant.
The reason I started using iBeacons was to improve presence detection (and I think that’s the case with most people) so that’s what I’ll discuss in part 1. In part 2 I’ll talk about using iBeacons to track devices that can’t track themselves.
When you use OwnTracks in standard major move mode (which is kind to your phone battery) it sometimes fails to update when you’d like it to. In my case I found that it would often send a location update as I was on my way home, but then not update when I got home. The result would be that Home Assistant would think I was 500M away from home, and take quite a while to notice I was home. It would also mean that the automation that should turn on my lights when I got home didn’t work very well! There were a few times when my phone location updated at 2am and turned the lights on for me. Fortunately my wife is very patient!
Luckily, OwnTracks supports iBeacons so I could use them to make presence detection more reliable. When OwnTracks sees a beacon it recognises, it will send an update. This means that if you put a beacon at your front door - OwnTracks will see it within a few seconds of you arriving home - and send an update saying it has seen this iBeacon.
To do this you first need to set up MQTT and OwnTracks in Home assistant - and make sure that HA can track your phone.
You then have to (A) tell Home Assistant where the beacon is located and (B) tell OwnTracks to recognise the beacon.
You tell HomeAssistant about fixed locations by creating a Zone with the longitude and latitude of your beacon. You should also give the zone a name which you will also use when you set up OwnTracks. An an example this zone specifies the location of my drive way.
Example configuration.yaml
entry
zone: - name: 'Drive' latitude: XXX longitude: YYY radius: 100
The radius isn’t used by the beacon code, but it is used by the GPS location sensing code. I’ll come back to this a little later. For now just use 50 or 100.
Once you’ve created the zone - you need to restart HA. The next step is:-
Regions
menu at the bottom of the screen+
symbol at the top right of the screen-drive
’(start the name with a -
see below for the reason)On
Circular Region
sectionUUID
of your beacon - this may be written on your beacon - or you can copy it from the management app that came with your iBeacon device. It’s a long number – so it’s easier to copy if you can!Minor
and Major
numbers for your iBeacon - or leave them at 0 which will match all beacons with that UUID
Once you’ve added the iBeacon - you should be able to see it on the OwnTracks region screen. If your phone can see the packets from that beacon, OwnTracks will turn the relevant Region red.
When OwnTracks sees the beacon (and turns the region red), it also sends an MQTT packet to HA to say that you have entered that region.
The result of the configuration above would be to set the location of device.phone to Drive
, (and the GPS location to XXX,YYY) when your phone sees the beacon.
So with the steps above you should be able to improve the reliability of tracking your phone - and send timely updates to HA. I did this for my home - and the lights now turn on before I reach the house on foot. If I arrive by car they turn on within a few seconds of arriving, before I can get to the front door.
I’m also pleased to say I no longer get an arrive home event at 2am that turns the lights on. I hope I’ve convinced you that iBeacons are worth trying!
You will probably use beacons to make entry into your existing GPS zones more reliable. By default either a beacon or a GPS location can cause you to enter a zone - and HA has some logic that should make them two work well together (it ignores GPS updates when you’re in an iBeacon Zone).
However you can also use beacons for situations where GPS doesn’t work well.
This might be because the zones are too close together - or even on top of each other!
For example, my wife works next door - and I couldn’t detect whether she’s at home or in the office via GPS because the accuracy wasn’t high enough. However I can do this by using two beacons.
To make this type of presence detection work you need to turn GPS off for a zone in Home Assistant by making them passive
. This is important because otherwise HA will try to decide between two close together zones without enough data. This doesn’t work well.
A passive zone can only be entered via an iBeacon, so a GPS location update will always pick the other zone.
I set up my Home zone to be a standard region, and my office zone to be passive, so the home zone can be entered in the normal way via either GPS or a Beacon.
Example configuration.yaml
entry
zone: - name: 'Office' latitude: XXX longitude: YYY radius: 3 passive: true
You could use this technique to try to detect which room someone is in. This might allow you to notice whether someone is in the living room or the bedroom - even though one is above the other (although beacon packets do pass through walls and floors).
To get this to work you’ll probably need to experiment with the beacon signal strength to try to match the beacon reception area to the location you want to track. Let me know if you get this to work (it doesn’t make sense in my open plan house)
Presence tracking sounds easy - and it’s an important part of Home Automation. Trying it shows how difficult it is to get presence detection right. I’ve found that iBeacons have improved the reliability and timeliness of knowing where I am, and I hope I encouraged you to try them too.
You can find out more about configuring the OwnTracks application and beacons here
There is information about configuring Homeassistant to use beacons here
Owntracks treats a region name with a leading -
as a hint that it shouldn’t disconnect after a single missed packet. This improves the ability to keep a connection to a beacon.
However, even when using this feature I’ve noticed that you can still lose connections (although it seems to vary by beacon manufacturer and type - I’ll talk more about this in part 2). This means that it’s best to take into account that you may see false enter/leave events in HA. You may be able to improve this by changing how often the beacons send packets - and by increasing the signal strength (both will drain your beacon batteries more quickly). You can usually change these parameters in the app supplied by the iBeacon maker. You can also find some high power beacons (which have worked well for me).
In automations you can use a for:
to avoid triggering during a brief disconnect, or use a script with a delay. Stay tuned for part 2 for an example of this.
iBeacons have a UUID
(usually set to the same value for beacons from the same manufacturer), as well as a minor
and major
number. If you set two beacons to have exactly same details then OwnTracks will think multiple beacons are at the same location.
This means you can have more than one beacon around your home - and a connection to any of them will count as home
to OwnTracks and HA. This reduces disconnections.
You can achieve the same effect by using the same the same UUID
but different major
/ minor
numbers - and tell OwnTracks not to worry about the minor
/ major
numbers for a particular region by setting them to 0).
Make sure to also check out part II where I talk about how to use iBeacons to track any object.
]]>