Determine what device or user agent a user is using

Is there anyway to determine what device, browser, or something similar the user is on? I’d ideally like to know whether the user is on a Mac, Windwos, Linux, iOS, or Android device.

That way I can use a template to modify the URL of a Lovelace link to use an app specific URL if on a smartphone or a web based url if on a computer.

Any ideas?

Any ideas for anything? Even if not exact but similar?

Anyone ever figure this out?

I never figured out how to do this.

Browser mod has an attribute for that.

Thanks for the tip. I took a look and it indeed does show the User Agent in the sensor for the browser. However, I can’t figure out how to use that to change what lovelace card is rendered depending on the current user. Is there a way to programmatically determine which browser deviceid is loading the UI?

It might be kind of hacky but you could use a conditional card that only displays if a certain user agent is present. I haven’t tried it but I do use the conditional card to display a placeholder if my security cams are off or a live feed if they’re on and it works quite well.

I had a very similar use case and was already using the custom card “button card”. I don’t know if other Lovelace buttons allow javascript templating, but button card does, so I could rely on the userAgent to figure out if I’m in the mobile app.

tap_action:
  action: url
  url_path: >
    [[[
      const userAgent = navigator.userAgent || navigator.vendor || window.opera;
      const isMobileApp = /HomeAssistant/.test(userAgent);
      const appLink = "unifi-protect://protect/xxxxx";
      const desktopLink = "https://unifi.ui.com/consoles/xxxxx";

      return isMobileApp ? appLink : desktopLink;
    ]]]