Giter Club home page Giter Club logo

openwrt_hass_devicetracker's Introduction

openwrt_hass_devicetracker

Package for a completely event-driven device/user presence tracker for Home Assistant on an OpenWRT/LEDE access point.

Description

Listens on hostapd wifi association events and then initiates appropriate service calls to the configured Home Assistant instance. On AP-STA-CONNECTED or AP-STA-POLL-OK the device is marked as seen with a timeout set by the timeout_conn config option. If an AP-STA-DISCONNECTED event is received, it is marked as seen with a timeout of timeout_disc.

Since restarting your access points removes any scripts connected via hostapd_cli -a, this package includes a daemon which monitors ubus for added APs so restarting/reconfiguring your radios doesn't kill the service.

Building

A docker image is provided for convenience of generating an OpenWRT package without having to set up the build environment. Simply run docker-compose run pkgbuild. If successful, the created package will be located in build/bin/packages/<ARCH>/packages/. If your UID is not 1000, you may need to chmod 777 build/bin.

Installation

Simply opkg install hass-tracker once it is added to the OpenWRT repositories. Until then, download a package from releases and opkg install <downloaded_file>.

Configuration

Once the package is installed, you can modify /etc/config/hass-tracker to your liking and start/enable the service via service hass-tracker start and service hass-tracker enable. If you would like to use HTTPS, simply start your host string with the https:// protocol specifier.

Authentication is done via a long-lived access token that can be generated from the web UI. This token needs to be set in the configuration file in the field token.

Note on missed events

If Home Assistant or the OpenWRT access point is restarted frequently or unreliable in other ways, you should reduce the very long default timeout for connected devices, since a disconnect event may be missed. However, since association events for connected devices can happen as infrequently as every 2-4 hours, you might want to then add a cronjob which synchronizes the state to Home Assistant at least twice as often as your timeout for connected devices timeout_conn. A good value for this might be a timeout of 1 hour and a sync every 30 minutes. The cronjob should look like:

#!/bin/sh

source /lib/functions.sh
config_load hass-tracker

source /usr/lib/hass-tracker/functions.sh
sync_state

This ensures that missed disconnect events do not spuriously keep the device present for more than an hour. This will be implemented by default in a future version or via an OpenWRT DeviceScanner in Home Assistant.

openwrt_hass_devicetracker's People

Contributors

glogiotatidis avatar miawgogo avatar mueslo avatar oxan avatar quthla avatar samjongenelen avatar ties avatar tribut avatar

Watchers

 avatar  avatar

Forkers

jabastien

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.