I share my HA instance with two groups of users and I would like to know how many hours a day/week/month each group is using it for. I can’t see how to approach solving this - can anyone point me in the right direction?
There are 3 user names allowed to login to my HA, myself and “group1” plus “group2”.
I use browser_mod to control what each group sees and periodically I go through the entities in browser_mod adding the username to the entity name, so that might be an approach.
I use this code to monitor the number of users (unavoidably it counts the number of browsers used, and each user may access HA via a phone as well as a laptop). It’s really not much good because each time HA is updated it resets states[this].last_changed
{%- set devices = states | map(attribute='entity_id') | map('device_id') | unique | reject('eq',None) | list -%}
{%- set ns = namespace(entities = []) -%}
{%- for device in devices -%}
{%- set ids = device_attr(device, 'identifiers') | list | first | default -%}
{%- if ids[0] == 'browser_mod' -%}
{%- set this = ('sensor.'~ids[1] | slugify~'_browser_user') -%}
{%- set thistime = states[this].last_changed | default(now()-timedelta(days=7)) -%}
{%- if as_timestamp(thistime)>=as_timestamp(now()-timedelta(days=7)) -%}
{%- set ns.entities = ns.entities + [thistime] -%}
{% endif -%}
{%- endif -%}
{%- endfor -%}
{{ ns.entities|count}}
Because I manually add the username to the entity name I’ve got this code. It used to count all browsers but something changed in the 2024.11.1 update and it now only counts me.
browsers_by_entity: "{{integration_entities('browser_mod')|select('contains','browser_user')|reject('contains','browser_useragent')|list|count}}"