Is it possible to disable the search for some users?

I made separate dashboards for my kids so they can’t control some stuff. But one of them is smart enough to use the search button on top so she can still use everything.

Is it possible to disable it for some users?

2 Likes

Personally I did not use this yet, but the Kiosk Mode might be an option, eventually with the hide_search config option.
It can be configured with specific user_settings.

May be disabled as described.
To disable for a particular user:

  card-mod-root-yaml: |
    .: |
      {% if user == "ildar" %}
      .header .toolbar .action-items:not(:has(ha-icon-button[slot="actionItems"])):not(:has(.exit-edit-mode)) ha-button-menu mwc-list-item:nth-of-type(1) {
        display: none;
      }
      .header .toolbar .action-items > ha-icon-button[slot="actionItems"]:nth-child(1) {
        display: none;
      }
      {% endif %}
1 Like

Just one question, Do I have to paste this in the raw configuration editor? On top?

This is a custom theme.
Paste it into your existing custom theme file like this:

my_custom_theme:
  # your present variables

  # here add this new code:
  card-mod-theme: my_custom_theme        # i.e. same name
  card-mod-root-yaml: |
    ..... and so on

If you do not have a custom theme yet:

  1. Add a corr. key into “configuration.yaml”:
frontend:
  ... some your probably already present keys

  # and add this:
  themes: !include_dir_merge_named themes
  1. Create a folder “themes” in your “config” directory (same place where configuration.yaml).
  2. Create a “my_custom_theme.yaml” (content is described above) in this folder (name of the file may be not same as the theme name).
  3. Reload themes: Dev tools → Services → call “Reload themes” service.

Next you may add more yaml-files into this “theme” folder for different custom themes.

3 Likes

Thanks a lot, it works as expected.

Hi. I’ve tried following what you wrote but the search icon still appears for the user I want to disable it for.

What I’ve done:

  1. Created a new folder under themes called my_custom_theme
  2. Created a yaml file in that folder, names my_custom_theme_user
  3. Pasted the code that you’ve written above:
my_custom_theme:
    card-mod-theme: my_custom_theme
    card-mod-root-yaml: |
        .: |
        {% if user == "user" %}
        .header .toolbar .action-items:not(:has(ha-icon-button[slot="actionItems"])):not(:has(.exit-edit-mode)) ha-button-menu mwc-list-item:nth-of-type(1) {
        display: none;
        }
        .header .toolbar .action-items > ha-icon-button[slot="actionItems"]:nth-child(1) {
        display: nonse;
        }
        {% endif %}

Any idea as to what may be the issue? (I’m reloading HA and going through incognito mode to avoid any cache issues)

EDIT: Also received the following error:

Start with fixing indentation.
It is different in the code you posted and the screenshot.

All right.

Here’s cut & paste from my yaml:

my_custom_theme:
  card-mod-theme: my_custom_theme        # i.e. same name
  card-mod-root-yaml: |
  .: |
    {% if user == "user" %}
    .header .toolbar .action-items:not(:has(ha-icon-button[slot="actionItems"])):not(:has(.exit-edit-mode)) ha-button-menu mwc-list-item:nth-of-type(1) {
      display: none;
    }
    .header .toolbar .action-items > ha-icon-button[slot="actionItems"]:nth-child(1) {
      display: none;
    }
    {% endif %}

I have other themes working so the frontend include themes part is working.

wrong indentation as I said.

For some reason the indentation gets messed up when I enter into HA. I copy & paste your code yet the second block gets moved back one tab.

Could you post the full snippet so that I can compare with mine?

How can I post your code?)
Suggest to use a NORMAL editor like vscode w/o any syntax-checking extensions.

I mean the snippets you had above, but combined into one.

This is written in studio code server in HA. I’m trying File server addon now (which doesn’t give any errors like studio code server but search button still comes up.

OK, here is a code with fixed indentation ))))

my_custom_theme:
  card-mod-theme: my_custom_theme        # i.e. same name
  card-mod-root-yaml: |
    .: |
      {% if user == "user" %}
      .header .toolbar .action-items:not(:has(ha-icon-button[slot="actionItems"])):not(:has(.exit-edit-mode)) ha-button-menu mwc-list-item:nth-of-type(1) {
        display: none;
      }
      .header .toolbar .action-items > ha-icon-button[slot="actionItems"]:nth-child(1) {
        display: none;
      }
      {% endif %}

Cannot say if it correct or not - I just copied your code, fixed indentation & posted here.

As for internal HA editor. You seem to be using HAOS. Hmmm, this is a thing I installed/removed after a few days as useless & limited. Prefer a normal HA in docker. Just imho.

Thanks a lot for the effort. No error anymore but search button is still present. Yup, I’m running HA on RBPi 4 but will be switching to KVM/Proxmox.

Perhaps this is a stupid question but you write that the file name may be not the same as the theme name. Do you mean that they should have different names, or that they can (without any issue) have different names?

  1. If several files are in same folder - they cannot have same names.
  2. Never tested myself - but imho filenames are not important; in my setup I have filenames same as theme names. But I do recall people have themes like “Acid Sweet Urban” etc stupid, and probably filenames are really not important.

Is it present for all users?

Yep, for all users as well as the specific one that I want to remove it for. I think I’m missing something very obivous.

Then remove jinja templates & check again.

Not sure what you mean exactly. Do you mean remove the entire thing and start from scratch?