Code Monkey home page Code Monkey logo

ad_people_tracker's Introduction

hacs_badge
Buy Me A Coffee

DEPRECATED - Use this setup instead

group

place in configuration.yaml

group
  people:
    entities:
    - person.a
    - person.b

template

place in configuration.yaml

template:
- sensor:
  - unique_id: people_at_home
    name: People at Home
    state: >
      {%- set people = expand('group.people') %}
      {{ people | selectattr('state', 'in', ['home', 'on'] ) | list | count }}
    icon: >
      {%- set icons = ['account-off', 'account', 'account-multiple'] %}
      {%- set people = expand('group.people') %}
      {%- set cnt = people | selectattr('state', 'in', ['home', 'on'] ) | list | count %}
      {%- if cnt >= 0 %}
        mdi:{{ icons[cnt] if cnt in range(icons | count) else 'account-group' }}
      {%- else %}
        mdi:account-alert
      {%- endif %}
    attributes:
      template: people_tracker
      people: > 
        {%- set people = expand('group.people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
        {%- set company = expand('group.people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
        {%- set people = people + company %}
        {{ people }}
      and: >
        {%- set people = expand('group.people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
        {%- set company = expand('group.people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
        {%- set people = people + company %}
        {%- if people | count > 0 %}
          {{- [people[:-1] | join(', '), 'and', people[-1]] | join(' ') if people | count > 1 else people[0] }}
        {%- else %}unknown
        {%- endif %}
      or: >
        {%- set people = expand('group.people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
        {%- set company = expand('group.people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
        {%- set people = people + company %}
        {%- if people | count > 0 %}
          {{- [people[:-1] | join(', '), 'or', people[-1]] | join(' ') if people | count > 1 else people[0] }}
        {%- else %}unknown
        {%- endif %}
      count: >
        {%- set people = expand('group.people') | selectattr('state', 'eq', 'home') | map(attribute='name') | list %}
        {%- set company = expand('group.people') | selectattr('state', 'eq', 'on') | map(attribute='name') | list %}
        {%- set people = people + company %}
        {{ people | count }}

AppDaemon Home Assistant People Tracking Sensor

People Tracking Sesnor app for AppDaemon.

Creates a sensor that tracks the number of people at home. Also creates gramatically correct lists of formated names at home.

The sensor contains the following information:

  • Number of people at home, including guests.
  • A list of people at home, sorted by first name. Guests are always last. e.g. A, B, and guests
  • Removes plural letters from device tracker names. e.g. Petro's iPhone will be reduced to Petro.
  • A gramatically correct string using the conjunction 'and' e.g. A, B, and C
  • A gramatically correct string using the conjunction 'or'. e.g. A, B, or C

Installation

Download the people_tracker directory from inside the apps directory here to your local apps directory, then add the configuration to enable the hacs module.

Example App configuration

Basic

# Monitors all events in INFO log level
people_at_home:
  module: people_tracker
  class: PeopleTracker
  guest_entity_id: input_boolean.guests
  entities:
  - device_tracker.petro
  - person.wife

Advanced

# Creates a sensor for Spanish, using 'y' for 'and' and 'o' for 'or'.
people_at_home:
  module: people_tracker
  class: PeopleTracker
  guest_entity_id: input_boolean.invitados
  entities:
  - device_tracker.petro
  - person.wife
  name: Gente en Casa
  guests_name: invitados
  and: y
  or: o
  log_level: INFO

App Configuration

key optional type default description
module False string people_tracker The module name of the app.
class False string PeopleTracker The name of the Class.
entities False list A list of people or device_tracker entity_ids.
guest_entity_id True string A input_boolean or binary_sensor that determines if guests are home.
name True string People Tracker Name of the created sensor.
guests_name True string guests Name displayed in tracker when guests are home.
and True string and Conjunction used for representing `A, B, and C.
or True string or Conjunction used for representing `A, B, or C.
log_level True 'INFO' | 'DEBUG' 'INFO' Lazy log level, it pushes all logs to a specific level so you don't need to restart appdaemon.

ad_people_tracker's People

Contributors

make-all avatar petro31 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

hydromac

ad_people_tracker's Issues

Setup Description

I came across this and figured I'd give it a try. But the setup description doesn't explain much. I have it installed via HACS but where do I add the config? Should this be in my configuration.yaml, apps.yaml, or somewhere else?

Also, my understanding is that it will pull any device connected to my WiFi that's mobile? Or how is it determining which devices to display?

Plural removal affects entity id and count, not just display

My family has two phones, which have identites device_tracker.galaxy-a20 and device_tracker.galaxy-a20s. When both these devices are home, the count is off by one, and only the former reported as home.

I'd expect plural removal to only affect the name displayed, not for the separate entities to be deduplicated when counting.

Error in initialize()

Getting this error in AppDaemon 4.0.2 - running on RaspberryPi from self built docker image from original AppDaemon:

2020-02-10 14:01:11.322339 WARNING events: ------------------------------------------------------------
2020-02-10 14:01:11.323433 WARNING events: Unexpected error running initialize() for events
2020-02-10 14:01:11.324235 WARNING events: ------------------------------------------------------------
2020-02-10 14:01:11.345404 WARNING events: Traceback (most recent call last):
  File "/usr/local/lib/python3.8/site-packages/appdaemon/app_management.py", line 144, in initialize_app
    await utils.run_in_executor(self, init)
  File "/usr/local/lib/python3.8/site-packages/appdaemon/utils.py", line 282, in run_in_executor
    response = future.result()
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 57, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/conf/apps/people_tracker/people_tracker.py", line 63, in initialize
    self.log(self.get_state(self.guest_entity_id, attribute='all'), level = self._level)
  File "/usr/local/lib/python3.8/site-packages/appdaemon/utils.py", line 195, in inner_sync_wrapper
    f = run_coroutine_threadsafe(self, coro(self, *args, **kwargs))
  File "/usr/local/lib/python3.8/site-packages/appdaemon/utils.py", line 291, in run_coroutine_threadsafe
    result = future.result(self.AD.internal_function_timeout)
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/local/lib/python3.8/concurrent/futures/_base.py", line 388, in __get_result
    raise self._exception
  File "/usr/local/lib/python3.8/site-packages/appdaemon/adapi.py", line 1344, in get_state
    return await self.AD.state.get_state(self.name, namespace, entity_id, attribute, default, copy, **kwargs)
  File "/usr/local/lib/python3.8/site-packages/appdaemon/state.py", line 360, in get_state
    raise ValueError("{}: Querying a specific attribute is only possible for a single entity".format(name))
ValueError: events: Querying a specific attribute is only possible for a single entity

Module won't work

AppDaemon 4 version 0.8.0 will break this module and this module will not work properly anymore.
Hope you will resolve this issue.
Thank you.

Showing other entities as people present

After the latest upgrade to HASS (I'm running 2022.2.2) I started to see a lot of other entities showing as at home. I have WiFi tracking so all my light switches etc are detected. However they are all set to not track in the known_devices file.

I have the guest boolean set to false.

I looked in the logs for AppDameon and find the following errors shown:

2022-02-06 11:45:51.383037 WARNING people_at_home: ------------------------------------------------------------
2022-02-06 11:45:51.383515 WARNING people_at_home: Unexpected error in worker for App people_at_home:
2022-02-06 11:45:51.383971 WARNING people_at_home: Worker Ags: {'id': 'cd3df720e85b4decaa790bdeaa908c39', 'name': 'people_at_home', 'objectid': '23d23f07d82e463ab79b58e8615aa297', 'type': 'state', 'function': <bound method PeopleTracker.track_person of <people_tracker.PeopleTracker object at 0x7fa9167a0b50>>, 'attribute': 'state', 'entity': 'persistent_notification.config_entry_discovery', 'new_state': 'notifying', 'old_state': None, 'pin_app': True, 'pin_thread': 2, 'kwargs': {'entity': 'person.ben_suffolk', '__thread_id': 'thread-2'}}
2022-02-06 11:45:51.384361 WARNING people_at_home: ------------------------------------------------------------
2022-02-06 11:45:51.384724 WARNING people_at_home: Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/appdaemon/threading.py", line 917, in worker
    funcref(
  File "/config/appdaemon/apps/ad_people_tracker/people_tracker.py", line 98, in track_person
    name = self.clean_persons_name(entity)
  File "/config/appdaemon/apps/ad_people_tracker/people_tracker.py", line 92, in clean_persons_name
    name = name.split(' ')[0]
AttributeError: 'NoneType' object has no attribute 'split'

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.