Home Assistant and device tracking

WARNING: Never place zip files in a publicly accessible folder.

It’s no secret I use Home Assistant (Hass for short) for my smart home project. One thing I have been trying to nail down is better awareness when family members are home. I do this would a number of things like checking to see if a smartphone or smartwatch is connected to Wifi, if the living room TV is on, or if lights get turned on/off.

The best kind of location awareness would be location-based tracking on devices I always keep on me, such as my smartphone and smartwatch.

When I first started the idea of how to track our smartphones I came across OwnTracks through the Hass documentation. While I did use it for about a week it was missing PUSH notifications. After much more searching and testing of various apps, I was sold on Zanzito for Android. The main selling point was I could purchase a single license and share it with family members using the Google Family Library and not have to pay for additional licenses.

A side note though, the only thing I have found to not work 100% correctly is the GPS location tracking. When I’m in my living room my phones GPS will jump me from my home to the middle of my town and back; for bleeping sakes I’m not the Flash. Because of this, I have not figured out a reliable way of using the Zones component for a true “at home” sensor or using. I use a combination of devices and groups for each person in an attempt to figure out if someone is home. I will keep working on this post with updates as I tweak my smart home.

Zanzito Setup

First, install Zanzito on your Andriod device from the Play Store. After installing, make sure you setup Device Name and MQTT Connection in the application settings to your Hass server. The Hass code below has “my_android_phone” that would need to be replaced according to what you entered into Zanzito.

Home Assistant Config

Setup the Device tracker component:

  - platform: mqtt_json
      drews_phone_mqtt: zanzito/my_android_phone/location

This is the script I’m using to send PUSH notifications to my phone. Make sure Push notifications is turned on within Zanzito on your device. You can even turn on “Read notifications if you want your phone to read outloud the messages. Setup the Script component.

        alias: Send notification to Zanzito
            service: mqtt.publish
            topic: 'zanzito/{{ dest_id }}/notification'
            payload: '{{ message }}'
            qos: 2
            retain: 0

Setup the Sensor component to get additional information from the devices:

    - platform: mqtt
        name: Android Phone Battery
        state_topic: "zanzito/my_android_phone/battery_level"
        qos: 0
        unit_of_measurement: "%"

    - platform: mqtt
        state_topic: "zanzito/my_android_phone/device_info"
        name: "Android Phone Charging"
        expire_after: 60
        value_template: >
            {% if value_json.charge_type == 'AC' %}
            {% else %}
            {% endif %}

    - platform: mqtt
        state_topic: "zanzito/my_android_phone/device_info"
        name: "Android Phone Screen On"
        expire_after: 60
        value_template: >
            {% if value_json.screen_on %}
            {% else %}
            {% endif %}

Setup the Automation component for PUSH notification.

    - alias: Login Failure

        - platform: template
        value_template: "{{ states('persistent_notification.httplogin') != 'authentication' }}"

        - service: script.mqtt_send_notification
            dest_id: 'my_andriod_phone'
            message: 'There was a failed login attempt by someone.'

You can also include a Google Map within the Hass dashboard to see where the device is using the Camera component:

    - platform: generic
        name: Android Phone Location
        still_image_url: https://maps.googleapis.com/maps/api/staticmap?center={{ states.device_tracker.my_android_phone.attributes.latitude }},{{ states.device_tracker.my_android_phone.attributes.longitude }}&zoom=17&size=500x500&maptype=roadmap&markers=color:blue%7Clabel:S%7C{{ states.device_tracker.my_android_phone.attributes.latitude }},{{ states.device_tracker.my_android_phone.attributes.longitude }}
        limit_refetch_to_url_change: true

If you find any of this useful, can improve on this, or have questions please leave a comment.



E-mail : *
1 comment
  • Drew
    October 30, 2018 at 8:47 pm

    Nice walk through, I too am using Zanzito in my HA setup, along with the FIND3 server.


Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.