This post is part of a series, other related posts are:
- 28 Oct 2016 - A custom presence locator in Home Assistant: This post will show how to configure a custom presence locator in Home Assistant using GPSLogger and a personal server.
- 05 Oct 2016 - Configuring presence locator in Home Assistant: This post will show how to configure presence locator in Home Assistant using Owntracks and a personal server.
- 04 Oct 2016 - Exposing Home Assistant in a secure-way: Before putting Home Assistant accessible from Internet, the entire OS must be hardened and secured to avoid unpleasant problems.
- 03 Oct 2016 - Installing Home Assistant on a Raspberry Pi 3: This post will show how to install Home Assistant on a Raspberry Pi 3, secure it and expose it on Internet.
This post will show how to configure presence locator in Home Assistant using Owntracks and a personal server.
Installing HBMQTT is very easy and requires a single command:
# pip install hbmqtt
The following configuration enable two different HBMQTT instances:
listeners: default: type: tcp my-tcp-1: bind: 127.0.0.1:1882 my-tcp-2: bind: 0.0.0.0:1883 ssl: on certfile: /etc/ssl/certs/apache-default.crt keyfile: /etc/ssl/private/apache-default.key auth: allow-anonymous: false password-file: /etc/hbmqtt/mqttaccess
The first instance is dedicated to Home Assistant without authentication and it’s not accessible from outside. The second instance is available to the external world via https and using a password file.
Check also my updated HBMQTT configuration file.
Add also at least one user:
# mkpasswd -m sha-512
Add a user and the above hash to
/etc/hbmqtt/mqttaccess file in the following form:
Do not leave empty lines at the end.
Create a startup script as following:
# /firstname.lastname@example.org [Unit] Description=HBMQTT for Home Assistant After=network.target [Service] Type=simple User=root ExecStart=/usr/local/bin/hbmqtt -c /etc/hbmqtt/hbmqtt.yaml SendSIGKILL=yes RestartForceExitStatus=100 [Install] WantedByemail@example.com
Check also my updated HBMQTT startup script.
Then enable HBMQTT at boot and start it:
# systemctl daemon-reload # systemctl enable hbmqtt # systemctl start hbmqtt
Debugging HBMQTT script
Check if HBMQTT is running:
# systemctl -l status hbmqtt
There is a bug in the current version with SSL. If you see the following error, you need to update:
Sep 29 11:00:50 darkgate hbmqtt: AttributeError: 'module' object has no attribute 'open'
[2016-09-29 12:14:57,402] :: ERROR - Broker startup failed: 'bool' object has no attribute 'upper' Traceback (most recent call last): File "/usr/local/lib/python3.4/dist-packages/hbmqtt/broker.py", line 240, in start if 'ssl' in listener and listener['ssl'].upper() == 'ON': AttributeError: 'bool' object has no attribute 'upper'
I suggest to update the
# wget -q -O- https://raw.githubusercontent.com/beerfactory/hbmqtt/develop/hbmqtt/broker.py > /usr/local/lib/python3.4/dist-packages/hbmqtt/broker.py
Configuring Owntracks on Android
Install Owntracks from Google Play Store, and configure in in the following way:
- Host: your FQDN registered on FreeDNS (i.e.
- Use WebSockets: no
- Host: your FQDN registered on FreeDNS (i.e.
- Authentication: yes
- Username: your configured username on HBMQTT (using
- Password: your configured password on HBMQTT (using
- Device ID: your name (i.e.
- Tracker id: your initials (i.e.
- TLS: yes
- CA certificate: import
apache-default.crtused by HBMQTT
- Client certificate: empty
- Clean Session: yes
- Automatic location reporting: yes
- Include extended data in location report: yes
- Notifications: yes
- Last reported location: yes
- Events: yes
- Remote commands: yes
- Locator foreground accuracy:
- Locator background accuracy:
- Locator background displacement:
- Locator background interval:
- Encryption key: empty
- Autostart: yes
Configuring Home Assistant
Home Assistant must be attached to HBMQTT server. Edit
device_tracker: platform: owntracks max_gps_accuracy: 50
Then some zones must be configured. Each zone describe a location which users can enters in or leave:
zone: name: Home latitude: 12.3456789 longitude: 23.4567890 radius: 200 icon: mdi:home zone 2: name: Work latitude: 45.6789012 longitude: 67.8901234 radius: 200 icon: mdi:city zone 3: name: School latitude: 89.0123456 longitude: 90.1234567 radius: 200 icon: mdi:school zone 4: name: Library latitude: 12.3456789 longitude: 23.4567890 radius: 200 icon: mdi:library
Save and restart Home Assistant.
When each mobile user connects to HBMQTT reporting the location, Home Assistant will add each user to the
known_devices.yaml file, creating it if necessary.
Automation using presence
known_devices.yaml contains all discovered devices by Home Assistant. They are not formally “users”, but “devices”. Devices can be grouped to identify users, but it’s out of scope for now.
Here an example of
andrea_andrea: name: Andrea mac: picture: track: yes hide_if_away: no
The above device can be used to automate things. In the following example, when “Andrea” enters “home” a notification via Pushover is sent:
alias: Notify when Andrea enters home trigger: platform: zone entity_id: device_tracker.andrea_andrea zone: zone.home event: enter action: - service: notify.andrea_mobile data: title: "Andrea is at home" message: "Andrea is arrived at home."
notify.yaml file define the Pushover service:
- platform: pushover name: andrea_mobile api_key: your_api_key user_key: your_email_key