I’m trying to trigger an automation when any of a set of entities within the browser_mod integration changes. I’ve tried a few techniques and had no success. The integration creates a new set of entities for each browser instance that successfully logs into HA, each looking like sensor.(browser instance tag)_functionalname. So my HA has a number of sensor.xxxxxx_browser_visibility and I want an automation to trigger whenever any of them switch to or from ‘visible’.
I hoped that I could do this with an event trigger using logbook_entry and a template like this:
alias: test
description: test for logbook trigger
triggers:
- trigger: event
event_type: logbook_entry
conditions:
- condition: template
value_template: "{{ 'Browser visibility' in trigger.event.name }}"
actions:
- action: notify.notify
metadata: {}
data:
message: browser_mod logbook
mode: single
It never triggers despite trying various options in the template (e.g. ‘browser_visibility’ and trigger.event.data.message). The logbook is definitely seeing events that match, e.g.
DJI-XPS15-Chrome Browser visibility changed to visible
09:28:21 - 3 seconds ago
The documentation appears to say that logbook_entries are events Events - Home Assistant. However I can’t find any successful examples or its use in a trigger posted in the community (some non-working ones eg Logbook entry as a trigger for automation - #7 by Hellis81).
So I tried a different approach by creating a template sensor. My approach was to keep a count of the visible browsers like this:
template:
- sensor:
- name: browser_users_visible
state: >
{{ integration_entities('browser_mod')|select('contains','browser_visibility')|expand|map(attribute='state')|select('eq','visible')|list|count }}
attributes:
who: >
{{ integration_entities('browser_mod')|select('contains','browser_user')|reject('contains','agent')|expand|map(attribute='state')|reject('in','unavailable')|list|join(';') }}
Testing this out in developer tools indicates it is monitoring all the sensor.xxxxx_browser_visibility entities but making this the trigger of an automation only works occasionally (and I can’t see a pattern in its failure). I suspect there is a problem with the output from integration_entities('browser_mod')
which I’ve used elsewhere with inconsistent results.
alias: UsersLog
description: Logs any change of browser_users
triggers:
- entity_id:
- sensor.browser_users_visible
trigger: state
to:
conditions: []
actions:
- target:
entity_id: notify.logusers
data:
message: >-
{{as_timestamp(now(),0)|timestamp_custom('%Y-%m-%dT%H:%M:%S',true,none)~','~states('sensor.browser_users')}},
{{ states('sensor.browser_users_visible') }},
action: notify.send_message
mode: queued
initial_state: "on"
max: 10
I’d be extremely grateful if anyone could spare a few minutes to tell me where I might be going wrong, or point me in a different direction. This is a step towards monitoring how much time my HA is being used for.