Skip to content

Super charge Browser defaults with Default action

dcapslock edited this page Jun 13, 2025 · 3 revisions

There have been requests across the years for different actions based on Browser attributes. For example, have a default view based on device width. To assist with allowing for various defaults, the Default action Frontend setting was introduced in Browser Mod version 2.4.0.

A simple example uses an action to navigate to a view, which you could set against a known User or Browser.

action: browser_mod.navigate
data:
  path: /my-dashboard/second-view

But what if you wish to perform something more dynamic for all your Browsers, or for a User who may be on different devices? Below is a broken down example that shows how you can achieve such using Default action and a Home Assistant script.

Browser ID to Device Entities to Desired Sensor

If you wish to have a Default action based on a Browser sensor, you need to get that sensor name dynamically in your script. This can be done by a combination of device_id and device_entities

device_entities(device_id(browser_id)), with browser_id set as a script field will give something like

[
  "sensor.dcd_browser_browser_path",
  "sensor.dcd_browser_browser_visibility",
  "sensor.dcd_browser_browser_useragent",
  "sensor.dcd_browser_browser_user",
  "binary_sensor.dcd_browser_browser_fullykiosk",
  "sensor.dcd_browser_browser_width",
  "sensor.dcd_browser_browser_height",
  "binary_sensor.dcd_browser_browser_dark_mode",
  "binary_sensor.dcd_browser",
  "light.dcd_browser_screen",
  "media_player.dcd_browser",
  "sensor.dcd_browser_browser_battery",
  "binary_sensor.dcd_browser_browser_charging"
]

Note: By default your sensors will have some relationship to your Browser ID. However if you have renamed your device and/or sensors, the relationship will not be as easy to code with string replacements. Hence the method shown above to get the Browser's sensors.

If we wish to use the _browser_width sensor, we can pick that using a select filter. Following on from our example...

device_entities(device_id(browser_id)) | select("contains", "_browser_width") | list | first

will give

sensor.dcd_browser_browser_width

which can then be used in a states() call, or any other template function requiring an entity.

Based on this concept, we can create a script that allows for different default view based on Browser/Device width.

Example Home Assistant Script

sequence:
  - variables:
      device_width: >
        {% set sensor = device_entities(device_id(browser_id)) |
        select("contains", "_browser_width") | list | first %} {% set width =
        states(sensor) | float(1280) %}  {% set breakpoints = 
          [
            { 'width': 768, 'size': 'mobile' },
            { 'width': 1024, 'size': 'tablet' },
            { 'width': 1280, 'size': 'desktop' },
            { 'width': 999999, 'size': 'wide' },
          ]
        %} {{ (breakpoints | selectattr('width', 'gt', width) | list | first
        ).size }}
  - variables:
      navigation_path: |
        {% set paths =
          { 
            'mobile': '/dashboard-test/0',
            'tablet': '/dashboard-test/0',
            'desktop': '/dashboard-test/test-view-2',
            'wide': '/dashboard-test/test-view-2',
          } 
        %}  {{ paths[device_width] }}
  - action: browser_mod.navigate
    data:
      browser_id: |
        {{ browser_id }}
      path: |
        {{ navigation_path }}
fields:
  browser_id:
    selector:
      text: {}
    name: Browser ID
alias: Navigate per Device Width
description: ""

Default action

action: script.navigate_per_device_width
data:
  browser_id: THIS
Clone this wiki locally