šŸ”¹ Browser_mod - turn your browser into a controllable device, and a media_player

Iā€™ve got some code that might help.

          {% set devices = integration_entities('browser_mod')|select('contains','browser_useragent')|list -%}
          {% set ns= namespace(output = '') -%}
          {% for dev in devices -%}
            {% set out = dev.split('agent')[-2] -%}
            {% if states(out) != 'unavailable' -%}
              {% set ns.output = dev.split(".")[1].split("_browser")[-2] ~'/'~ states(out) ~ states[out].last_updated.strftime('(%d%b%H:%M)') ~ '; ' ~ ns.output -%}
            {% endif -%}
          {% endfor -%}  
          {{ ns.output|truncate }}

Itā€™s not quite doing what you want, but you can adapt it. Iā€™ve been fumbling my way towards logging how much time my HA is getting used and this was one (failed) step to recording the times currently logged-on users changed.

1 Like

Sometimes I have the problem, that my popup is not working properly. In Chrome and in the companion app as well.

It is working again after i fully close the companion app or refresh the cache in the browser.
My code looks like this:

action: fire-dom-event
browser_mod:
  service: browser_mod.popup
  data:
    browser_id: THIS
    title: HaustĆ¼r
    timeout: 5000
    content:
      type: custom:stack-in-card
      mode: horizontal
      cards:
        - type: custom:more-info-card
          entity: lock.zuhause
          title: HaustĆ¼r

The code looks right on the face of it.

But can you be more precise as to what you mean by ā€˜not workingā€™? That the popup doesnā€™t appear at all? How long does it work for after refreshing browser cache for example? If you use the browserā€™s developerā€™s tools, does it show any loading errors?

Maybe try removiing the custom:stack-in-card? Or trying a core card rather than custom:more-info-card? Then we can perhaps establish whether the problem is with the popup action itself, or just the way youā€™re configuring the content.

@DJI Thank you! Iā€™m away for a bit, but looking forward to leveraging this when back in the saddle. Will report back. Cheers.

Like your code a lot and will use it. Thanks. One gotcha is that it spits out all active browsers, not the one weā€™re actually using.

The answer to my original question is actually so simple:

card:
  type: custom:button-card
  template: base
  name: >-
       [[[ return localStorage["browser_mod-browser-id"] ]]]

Not sure how to now use your code inside the javascript, since I donā€™t have access to integration_entitiesā€¦but waitā€¦now I know the browser_id, I should be able to poke at the states('sensor'+browser_id+'_useragent') or something like thatā€¦

This gets you the user name using the same technique. But some bewares: more than one user might be logged on, hence the list output. Big problem is that it canā€™t always find a logged on user; when Iā€™m playing around with template editor it gives a null after a while. Weird.

        using: >
          {% set devices = integration_entities('browser_mod')|select('contains','browser_useragent')|list -%}
          {% set ns= namespace(output = '') -%}
          {% for dev in devices -%}
            {% set out = dev.split('agent')[-2] -%}
            {% if states(out) != 'unavailable' -%}
              {% set ns.output = dev.split(".")[1].split("_browser")[-2] ~'/'~ states(out) ~ states[out].last_updated.strftime('(%d%b%H:%M)') ~ '; ' ~ ns.output -%}
            {% endif -%}
          {% endfor -%}  
          {{ ns.output|truncate }}

What I really want to do is log to a csv file every time a user logs on or out (or times-out). I just canā€™t get any event to reliably trigger from a log on.