|
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "iBeacons: How to track things that can’t track themselves (part II)" |
| 4 | +description: A step by step guide how to tracking dumb devices by using iBeacons. |
| 5 | +date: 2016-05-26 12:06:12 +0100 |
| 6 | +date_formatted: "May 26, 2016" |
| 7 | +author: Greg Dowling |
| 8 | +author_twitter: pavoni240 |
| 9 | +comments: true |
| 10 | +categories: iBeacons Device-Tracking OwnTracks |
| 11 | +--- |
| 12 | + |
| 13 | +_This post is by Home Assistant contributor [Greg Dowling](https://github.com/pavoni)._ |
| 14 | + |
| 15 | + |
| 16 | +In [Part 1](/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better) 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. |
| 17 | + |
| 18 | +### {% linkable_title Tracking things using iBeacons %} |
| 19 | +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. |
| 20 | + |
| 21 | +But beacons don’t have to be fixed. |
| 22 | + |
| 23 | +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. |
| 24 | + |
| 25 | +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. |
| 26 | + |
| 27 | +So if you put an iBeacon on your keys or in your car - then you can track them. |
| 28 | + |
| 29 | +<p class='img'> |
| 30 | + <img width='200' src='/images/blog/2016-05-ibeacons/keys_with_beacon.jpg'> |
| 31 | + Here are my keys - with a Estimote Nearable iBeacon stuck to them. Ugly but effective! |
| 32 | +</p> |
| 33 | + |
| 34 | +<!--more--> |
| 35 | + |
| 36 | +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. |
| 37 | + |
| 38 | +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. |
| 39 | + |
| 40 | +<p class='img'> |
| 41 | + <img width='200' src='/images/blog/2016-04-ibeacons/owntracks_beacon_setup.png'> |
| 42 | +</p> |
| 43 | + |
| 44 | +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. |
| 45 | + |
| 46 | +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. |
| 47 | + |
| 48 | +<p class='img'> |
| 49 | + <img width='200' src='/images/blog/2016-05-ibeacons/keys_device.png'> |
| 50 | +</p> |
| 51 | + |
| 52 | +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. |
| 53 | + |
| 54 | +If you park your car and go shopping - *device_tracker.beacon_car* will stop moving. |
| 55 | + |
| 56 | +With the basic tracking working - you can use automation to do things like open your gates if your car comes home |
| 57 | + |
| 58 | +````yaml |
| 59 | +automation: |
| 60 | + - alias: 'Open gate' |
| 61 | + trigger: |
| 62 | + - platform: state |
| 63 | + entity_id: device_tracker.beacon_car |
| 64 | + from: 'not_home' |
| 65 | + to: 'home' |
| 66 | + condition: |
| 67 | + - condition: state |
| 68 | + entity_id: switch.gate |
| 69 | + state: 'off' |
| 70 | + action: |
| 71 | + service: switch.turn_on |
| 72 | + entity_id: switch.gate |
| 73 | +```` |
| 74 | + |
| 75 | +Or warn you if you leave your keys behind |
| 76 | + |
| 77 | +````yaml |
| 78 | +automation: |
| 79 | + - alias: 'Forgotten keys' |
| 80 | + trigger: |
| 81 | + platform: template |
| 82 | + value_template: {% raw %}'{{states.device_tracker.greg_gregphone.state != states.device_tracker.beacon_keys.state}}'{% endraw %} |
| 83 | + condition: |
| 84 | + condition: template |
| 85 | + value_template: {% raw %}'{{ states.device_tracker.greg_gregphone.state != "home" }}'{% endraw %} |
| 86 | + action: |
| 87 | + service: script.turn_on |
| 88 | + entity_id: script.send_key_alert |
| 89 | + |
| 90 | + - alias: 'Forgotten keys - cancel' |
| 91 | + trigger: |
| 92 | + platform: template |
| 93 | + value_template: {% raw %}'{{states.device_tracker.greg_gregphone.state == states.device_tracker.beacon_keys.state}}'{% endraw %} |
| 94 | + condition: |
| 95 | + - condition: state |
| 96 | + entity_id: script.send_key_alert |
| 97 | + state: 'on' |
| 98 | + action: |
| 99 | + service: script.turn_off |
| 100 | + entity_id: script.send_key_alert |
| 101 | +```` |
| 102 | + |
| 103 | +````yaml |
| 104 | +script: |
| 105 | + send_key_alert: |
| 106 | + sequence: |
| 107 | + - delay: |
| 108 | + minutes: 2 |
| 109 | + - service: notify.notify |
| 110 | + data: |
| 111 | + message: 'You forgot your keys' |
| 112 | + target: 'device/gregs_iphone' |
| 113 | +```` |
| 114 | + |
| 115 | + |
| 116 | +(The delay is needed for two reasons: - |
| 117 | +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 |
| 118 | +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) |
| 119 | + |
| 120 | + |
| 121 | +### {% linkable_title Using both types of iBeacons at the same time %} |
| 122 | +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. |
| 123 | + |
| 124 | +<p class='img'> |
| 125 | + <img width='300' src='http://bluesensenetworks.com/wp-content/uploads/2015/02/BlueBar-Beacon-Long-Range.jpg'> |
| 126 | +</p> |
| 127 | +Long range / High power beacon |
| 128 | + |
| 129 | +<p class='img'> |
| 130 | + <img width='400' src='http://bluesensenetworks.com/wp-content/uploads/2015/02/BlueBar-Beacon-Weatherproof.jpg'> |
| 131 | +</p> |
| 132 | +Waterproof beacon |
| 133 | + |
| 134 | + |
| 135 | +### {% linkable_title Buying Beacons %} |
| 136 | +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. |
| 137 | + |
| 138 | +I’ve bought quite a few iBeacons from a company called [Blue Sense Networks](http://bluesensenetworks.com/). 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. |
| 139 | + |
| 140 | +All the beacons seem fine - and the long range unit does work over a longer range than my other beacons. |
| 141 | + |
| 142 | +I bought some other beacons from a US/Polish startup called [Estimote](http://estimote.com/), 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! |
| 143 | + |
| 144 | +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*). |
| 145 | + |
| 146 | +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! |
| 147 | + |
| 148 | +### {% linkable_title Conclusion %} |
| 149 | +As I said in [part 1](/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better), 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. |
| 150 | + |
| 151 | +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. |
| 152 | + |
| 153 | +### {% linkable_title Notes %} |
| 154 | + |
| 155 | +Please see the [notes at the end of Part 1](/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/#tips) for documentation information. |
| 156 | + |
| 157 | + |
0 commit comments