šŸ”¹ 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.

Hi
I am working on a dashboard that use floor3d-card.
In floor3d-card you can klick on a room that can fire a service like a script.
In that script i have used ā€œbrowser_mod.popupā€ and this works great.
The problem is that this popup on all screens.
And the problem i also that i can not use something like fire-dom-event and deviceid: THIS inside floor3d-card.
So how can i get the browserid i klicked on so popup shows on correct screen.

FYI there is an issue with Browser_mod in HA 2025.1.0 beta.

1 Like

Yes, the popup does not appear at all. I have no time. Sometimes it is working for days, sometimes only for hours after refreshing.

When I use the browsers developer tools there are a lot of errors. But I don’t know where they come from or if they are related to browser_mod.

There are a lot of:
connection.js:315 Uncaught (in promise)
connection.js:315 Uncaught (in promise) {code: ā€˜not_found’, message: ā€˜Subscription not found.’}
home:1 Unchecked runtime.lastError: A listener indicated an asynchronous response by returning true, but the message channel closed before a response was received
card-mod.js:1 Card-mod warning
card-mod.js:1 You are using a custom card which relies on card-mod, and uses an outdated signature for applyToElement.
card-mod.js:1 The outdated signature will be removed at some point in the future. Hopefully the developer of your card will have updated their card by then.
card-mod.js:1 The card used card-mod to apply styles here: <browser-mod-popup class=​"undefined">​#shadow-root (open)​

mushroom.js:298 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ā€˜config’)

Hi everyone,

I’ve been trying to get help with the browser_mod integration for the past three days and have had no luck finding the answer online. I have browser_mod (v2) installed on my Home Assistant and have registered two clients. I can see these devices in the Browser Mod integration panel, and I can send popup messages to the clients (or to one of them) using actions.

However, I’m struggling to figure out how to retrieve the browser_id (or device_id) from the client currently accessing the server in a template. I need this information to apply conditional logic in a picture-elements card, to scale the font size depending on the device accessing the dashboard.

In the states panel, I can see various entities for my registered devices, such as media_player.DEVICE_ID, sensor.DEVICE_ID_browser_dark_mode, sensor.DEVICE_ID_browser_user, and more, but none of them seem to indicate the browser_id of the client in the current session.

According to instructions I’ve found online, this should be possible, but I must be missing something. Is there something else I need to configure, or should I use a script to detect the current user?

If anyone could help, I would really appreciate it.

Thanks in advance!

it still an issue

@cloudbr34k thanks for the reminder, I meant to post this yesterday.

PSA

Upgrading to 2025.1.0 will cause the Browser_mod configuration page to not load when you click the side panel. This means that you can be stuck with whatever settings you had previously. Also if you did not have auto register browsers set to on that when your browser id changes popups will stop working.

The good news is that it’s an easy fix that most people can do themselves by editing 3 lines in 2 files. Simply open custom_components/browser_mod/browser_mod.js and custom_components/browser_mod/browser_mod_panel.js then find getRoutes and replace it with _getRoutes. That’s it, a silly little underscore in 3 places… 1 in browser_mod.js and 2 in browser_mod_panel.js

You can find the issue linked in my previous post, the fix details here, and I created a quick PR for it here. Hopefully this just needs some quick attention from @thomasloven.

2 Likes

Anyone get browser mod to play the audio? I have used some old version HA 2022.7 and all was working. With the newest release 2024.7+ no luck. It looks like this wasn’t a popular function, but anyone have it working with the newest HA release?

EdiT; In my case the issue was with config/network settings. I’m using HA in kubernetes with LoadBalancer and I have to set local network manually in HA config/network… The same issue will be for any containerized deployment with overlay network (network not in a host mode).

Audio works in my setup with 2024.12.5. Look for media player entities.

1 Like

Yeah did thst and hasn’t fixed the issue for me. I am reinstalling BMW, will try again

Update was released a couple of hours ago…

1 Like

That was for card-mod, browser_mod has seen no activity yet.

Hi there! I have spent the past hours trying to animate my popup cards. I dont want them just to appear in the middle of the screen, but rather fill screen, slide in from the right and stop at about 20% from the left. I got it working quite easily using css animations… BUT. There is something wierd about the popup card. First I thought it was the animations, but now I can see the issue even with the most basic example. It ALWAYS work the first time I summon the popup. Then I close it, and summon it again, then there is a quick ā€œflickerā€ in the middle of the screen. It is there even without animations, and it looks way worse with the animation enabled, because then the center of the screen is empty, and the popup card appears and disappears for like 0.1 second before it slides in as it should. I disabled the animations and it is the same.

Has anyone seen this? Is there a way to solve it? Here is the code I use, a most basic example. You have to tap the button a few times before it start acting wierd.

  tap_action:
    action: fire-dom-event
    browser_mod:
      service: browser_mod.popup
      data:
        title: 'My title '
        card_mod:
          style:                              
            ha-dialog$: >                                
              div.mdc-dialog__surface  {                                
                animation: slide-in 2.3s forwards;
              }                           
              @keyframes slide-in { from { transform: translateX(100%); } to { transform: translateX(0); } }

Ups… indeed… my bad, sorry…

It’s here…now for real! (browser mod update, i mean).

1 Like