Git Product home page Git Product logo

hapt's Introduction

HAPT

Home Assistant Presence Tracker (HAPT) is an event-driven device presence tracker for Home Assistant on an OpenWRT router or access point.

Description

HAPT listens on association and disassociation events to wireless networks, using the hostapd control interface. It keeps track of which device is connected to which networks. When a device connects to its first network, or disconnects from its last network, a service call to Home Assistant is performed to mark the device as home or away. By tracking active device connections, HAPT ensures that a device switching between different networks (e.g. the 2.4 GHz and 5 GHz bands) is not marked as away.

Usage

Installation

Download a package from the releases page, and install it either by uploading it in LuCi (System > Software) or running opkg install <file> from a shell.

Configuration

Once the package is installed, you must update the configuration in /etc/config/hapt. At minimum the host option should be set to the address of your Home Assistant installation, and the token option to a Home Assistant long-lived access token (these can be generated in the Home Assistant web interface).

The consider_home_connect and consider_home_disconnect settings can be used to configure for how long (in seconds) after the first association and last disassociation event the device should be considered home. Since Home Assistant does not support marking a device as away (on disconnects), this is implemented by marking the device as home for a negligible amount of time, after which Home Assistant will mark the device as away. The default values should be fine here.

With the wifi_interfaces option, it is possible to specify the wireless interfaces that must be monitored. This can be used (for example) to ignore devices on a guest network.

By listing MAC addresses in the track_mac_address option, it is possible to whitelist MAC addresses which are tracked. This prevents uninteresting devices from being synchronized with Home Assistant and cluttering the entity registry.

Running

After modifying the configuration, you must restart the service by service hapt restart. This can also be done from the LuCi interface (System > Startup). HAPT prints log messages to the system log, so that you can verify it is working as expected.

It is possible to synchronize just the currently connected devices with Home Assistant by running hapt from the command line. This can be especially useful to debug the connection with Home Assistant, as this will also print any errors that occur.

Development

You can build a custom package by running the makepkg.sh script, which will run the package build in a Docker container and place the compiled package in the build/bin directory.

Acknowledgments

This project has been inspired by the openwrt_hass_devicetracker package.

hapt's People

Contributors

danielvoogsgerd avatar oxan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

hapt's Issues

Crashes on boot

Sat Mar 28 18:40:19 2020 daemon.err hapt[1112]: Traceback (most recent call last):
Sat Mar 28 18:40:19 2020 daemon.err hapt[1112]:   File "/usr/bin/hapt", line 182, in <module>
Sat Mar 28 18:40:19 2020 daemon.err hapt[1112]:   File "/usr/bin/hapt", line 98, in __init__
Sat Mar 28 18:40:19 2020 daemon.err hapt[1112]:   File "/usr/bin/hapt", line 42, in get_wireless_interfaces
Sat Mar 28 18:40:19 2020 daemon.err hapt[1112]: KeyError: ifname

(commit 8ffe216).

I think this happens because we start before hostapd has brought the interface online, and thus there is no ifname for the configured interface.

does not auto update without start hapt on openwrt

hi,
running latest openwrt,
my config file:

config hapt 'global'
        option host                     'http://ipaddress:8123'
        option token                    'token'
        option consider_home_connect    '86400'
        option consider_home_disconnect '60'
        option device_id_prefix         ''
#       list   wifi_interfaces          'wlan0'
#       list   wifi_interfaces          'wlan1'
#       list   track_mac_address        '00:11:22:33:44:55'
#       list   track_mac_address        '66:77:88:99:aa:bb'

in logread I get

Command failed: Not found
Traceback (most recent call last):
File "/usr/bin/hapt", line 278, in
File "/usr/bin/hapt", line 260, in oneshot
File "/usr/bin/hapt", line 76, in get_connected_clients
File "/usr/bin/hapt", line 62, in ubus_call
ValueError: syntax error in JSON

If a device disconnect, no hapt execution is execute (see it in logread)
status will be fine submitted, if i run hapt via cli

thanks for your help and your tool
br

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.