home-assistant.github.io/blog/categories/ibeacons/atom.xml
2018-01-26 19:59:18 +00:00

307 lines
20 KiB
XML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title><![CDATA[Category: iBeacons | Home Assistant]]></title>
<link href="https://home-assistant.io/blog/categories/ibeacons/atom.xml" rel="self"/>
<link href="https://home-assistant.io/"/>
<updated>2018-01-26T19:50:06+00:00</updated>
<id>https://home-assistant.io/</id>
<author>
<name><![CDATA[Home Assistant]]></name>
</author>
<generator uri="http://octopress.org/">Octopress</generator>
<entry>
<title type="html"><![CDATA[iBeacons: How to track things that cant track themselves (part II)]]></title>
<link href="https://home-assistant.io/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/"/>
<updated>2016-05-26T11:06:12+00:00</updated>
<id>https://home-assistant.io/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii</id>
<content type="html"><![CDATA[_This post is by Home Assistant contributor [Greg Dowling](https://github.com/pavoni)._
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 Ill talk about how to track things like keys that cant track themselves by using iBeacons.
### <a class='title-link' name='tracking-things-using-ibeacons' href='#tracking-things-using-ibeacons'></a> Tracking things using iBeacons
In the first part I mentioned that iBeacons just send out *Im here* packets, and we used this to trigger an update when your phone came close to a fixed beacon.
But beacons dont 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 *Im 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.
<p class='img'>
<img width='200' src='/images/blog/2016-05-ibeacons/keys_with_beacon.jpg'>
Here are my keys - with a Estimote Nearable iBeacon stuck to them. Ugly but effective!
</p>
<!--more-->
Its 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 dont need to configure HA at all.
<p class='note warning'>OwnTracks currently only supports mobile beacons on iOS.</p>
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.
<p class='img'>
<img width='200' src='/images/blog/2016-04-ibeacons/owntracks_beacon_setup.png'>
</p>
Once youve 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 hasnt 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.
<p class='img'>
<img width='200' src='/images/blog/2016-05-ibeacons/keys_device.png'>
</p>
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
```yaml
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
```yaml
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
```
```yaml
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 dont want the automation to trigger in the gap between the updates
2. Ive found that beacons (especially the low power Estimote Nearables) can get disconnected for a few seconds so its best to wait a minute or so before deciding that youve left your keys behind)
### <a class='title-link' name='using-both-types-of-ibeacons-at-the-same-time' href='#using-both-types-of-ibeacons-at-the-same-time'></a> Using both types of iBeacons at the same time
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.
<p class='img'>
<img width='300' src='http://bluesensenetworks.com/wp-content/uploads/2015/02/BlueBar-Beacon-Long-Range.jpg'>
</p>
Long range / High power beacon
<p class='img'>
<img width='400' src='http://bluesensenetworks.com/wp-content/uploads/2015/02/BlueBar-Beacon-Weatherproof.jpg'>
</p>
Waterproof beacon
### <a class='title-link' name='buying-beacons' href='#buying-beacons'></a> Buying Beacons
This isnt a buyer's guide, but I just wanted to mention the iBeacons Ive been using. I think you should be able to use any iBeacon with HA and OwnTracks. You generally cant buy beacons in your local electronics shop - so I just wanted to briefly mention the two suppliers Ive used so far.
Ive 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 youd 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](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 youre 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 cant change all the parameters on these devices (UUID/Major/Minor are fixed) - and the batteries cant 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!
Ive 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 couldnt work out how to edit their beacons parameters (although the answer was *you cant yet*).
The larger Blue Sense Network beacons seem to be better at maintaining a connection that the Estimotes - although that might be because Im reluctant to turn the power to maximum and reduce the gap between sending packets on the Estimotes where I cant replace the batteries!
### <a class='title-link' name='conclusion' href='#conclusion'></a> Conclusion
As I said in [part 1](/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better), Ive 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 cant 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.
### <a class='title-link' name='notes' href='#notes'></a> Notes
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.
]]></content>
</entry>
<entry>
<title type="html"><![CDATA[iBeacons: Making presence detection work better (part I)]]></title>
<link href="https://home-assistant.io/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better/"/>
<updated>2016-04-30T06:50:09+00:00</updated>
<id>https://home-assistant.io/blog/2016/04/30/ibeacons-part-1-making-presence-detection-work-better</id>
<content type="html"><![CDATA[_This post is by Home Assistant contributor [Greg Dowling](https://github.com/pavoni)._
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 its hard to imagine why they might be useful. In this two part blog Ill 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 thats the case with most people) so that's what Ill discuss in _part 1_. In _part 2_ Ill talk about using iBeacons to track devices that cant track themselves.
### <a class='title-link' name='using-beacons-to-improve-owntracks-location-data' href='#using-beacons-to-improve-owntracks-location-data'></a> Using beacons to improve OwnTracks location data
When you use OwnTracks in standard _major move_ mode (which is kind to your phone battery) it sometimes fails to update when youd 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 didnt 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 recognizes, 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.
<!--more-->
### <a class='title-link' name='getting-started' href='#getting-started'></a> Getting Started
To do this you first need to set up [MQTT] and [OwnTracks] in Home assistant - and make sure that HA can track your phone.
[MQTT]: /components/mqtt/#picking-a-broker
[OwnTracks]: /components/device_tracker.owntracks/
You then have to (A) tell Home Assistant where the beacon is located and (B) tell OwnTracks to recognize the beacon.
#### <a class='title-link' name='a-tell-home-assistant-where-your-beacon-is-located' href='#a-tell-home-assistant-where-your-beacon-is-located'></a> A. Tell Home Assistant where your beacon is located
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**
````yaml
zone:
- name: 'Drive'
latitude: XXX
longitude: YYY
radius: 100
````
The radius isnt used by the beacon code, but it is used by the GPS location sensing code. Ill come back to this a little later. For now just use 50 or 100.
Once youve created the zone - you need to restart HA. The next step is:-
#### <a class='title-link' name='b-tell-owntracks-to-track--your-beacon' href='#b-tell-owntracks-to-track--your-beacon'></a> B. Tell OwnTracks to track your beacon
1. Go to the OwnTracks app on your phone
2. Touch the `Regions` menu at the bottom of the screen
3. Touch the `+` symbol at the top right of the screen
4. Give the beacon a name e.g. `-drive` (start the name with a `-` see below for the reason)
5. Turn Share to `On`
6. Skip the `Circular Region` section
7. Enter the `UUID` 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. Its a long number so its easier to copy if you can!
8. Enter the `Minor` and `Major` numbers for your iBeacon - or leave them at 0 which will match all beacons with that `UUID`
<p class='img'>
<img width='200' border='2' src='/images/blog/2016-04-ibeacons/owntracks_beacon_setup.png'>
</p>
Once youve 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.
<p class='img'>
<img width='200' src='/images/blog/2016-04-ibeacons/owntracks_red_beacon.png'>
</p>
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.
Im also pleased to say I no longer get an _arrive home_ event at 2am that turns the lights on. I hope Ive convinced you that iBeacons are worth trying!
### <a class='title-link' name='mixing-beacons-and-gps-locations' href='#mixing-beacons-and-gps-locations'></a> Mixing Beacons and GPS locations
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 youre in an iBeacon Zone).
However you can also use beacons for situations where GPS doesnt 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 couldnt detect whether shes at home or in the office via GPS because the accuracy wasnt 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 doesnt 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**
````yaml
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 youll 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 doesnt make sense in my open plan house)
### <a class='title-link' name='conclusion' href='#conclusion'></a> Conclusion
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.
### <a class='title-link' name='tips' href='#tips'></a> Tips
You can find out more about configuring the OwnTracks application and beacons [here](http://owntracks.org/booklet/features/beacons/)
There is information about configuring Homeassistant to use beacons [here](https://home-assistant.io/components/device_tracker.owntracks/)
#### <a class='title-link' name='connections-and-disconnecting' href='#connections-and-disconnecting'></a> Connections and disconnecting
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 Ive noticed that you can still lose connections (although it seems to vary by beacon manufacturer and type - Ill 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.
#### <a class='title-link' name='using-multiple-beacons-for-the-same-zone' href='#using-multiple-beacons-for-the-same-zone'></a> Using Multiple beacons for the same Zone
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](/blog/2016/05/26/ibeacons-how-to-track-things-that-cant-track-themselves-part-ii/) where I talk about how to use iBeacons to track any object._
]]></content>
</entry>
</feed>