Just cannot get !secret to work

Is it me???

The following just won’t work.

Card:

type: entity
entity: sensor.76_temperature
name: !secret name

secrets.yaml:


name: "TESTING"

What am I doing wrong?

I started by trying to use card_mod secret but that didn’t work, so I simplified with the above and still can’t get it to work.


card_mod:  !secret color

With secrets.yaml:

color:
  style: |
    :host {
        --paper-item-icon-color:
            {% set state = states(config.entity)|int(-5) %}
            {% if state == 'unknown'%} gray
            {% elif state < -20 %} black
            {% elif state < -15 %} navy
            {% elif state < -10 %} darkblue
            {% elif state < -5 %} mediumblue
            {% elif state < 0 %} blue
            {% elif state < 5 %} dodgerblue
            {% elif state < 10 %} lightblue
            {% elif state < 15 %} turquoise
            {% elif state < 20 %} green
            {% elif state < 25 %} darkgreen
            {% elif state < 30 %} orange
            {% elif state < 35 %} crimson
            {% else %} firebrick
            {% endif %};
    }

The first example and the secrets.yaml look fine to me.

Is secrets.yaml located in /config (alongside the likes of home-assistant_v2.db)?

Have you tried enclosing name in a single quote?

type: entity
entity: sensor.76_temperature
name: !secret 'name'

I believe it is:

Just tried both single and double quotes. Still no luck:

I’m not sure you can do any of the text_color or temp_color2 type things in the secrets.yaml file. It’s not a subroutine thing.

Only name: TESTING will work and the other entries might even stopping that from working.

Can you remove text_color or temp_color2 and see if name: works then?

edit: You can try this for card_mod: though

card_mod:  !include color

color.yaml

style: |
  :host {
      --paper-item-icon-color:
          {% set state = states(config.entity)|int(-5) %}
          {% if state == 'unknown'%} gray
          {% elif state < -20 %} black
          {% elif state < -15 %} navy
          {% elif state < -10 %} darkblue
          {% elif state < -5 %} mediumblue
          {% elif state < 0 %} blue
          {% elif state < 5 %} dodgerblue
          {% elif state < 10 %} lightblue
          {% elif state < 15 %} turquoise
          {% elif state < 20 %} green
          {% elif state < 25 %} darkgreen
          {% elif state < 30 %} orange
          {% elif state < 35 %} crimson
          {% else %} firebrick
          {% endif %};
  }

You may be correct on this. Information from “Storing Secrets” indicates;

The configuration.yaml file is a plain-text file, thus it is readable by anyone who has access to the file. The file contains passwords and API tokens which need to be redacted if you want to share your configuration. By using !secret you can remove any private information from your configuration files. This separation can also help you to keep easier track of your passwords and API keys, as they are all stored at one place and no longer spread across the configuration.yaml file or even multiple YAML files if you split up your configuration.

@josephny - I think the key here is storage of passwords and API tokens. There’s no mention of storing anything else. I think, as @jchh mentions, !include may be the correct approach.

1 Like

!secrets and !include only work in yaml mode for the frontend.

1 Like

Tom: Could you please point me to how to be in “yaml mode?”

I thought by the following was yaml mode:

If you are editing via the UI you are using storage mode. YAML mode is done entirely from a text editor.

See: https://www.home-assistant.io/dashboards/dashboards/#using-yaml-for-the-default-dashboard

Thank you.

I’m a little leary of switching to yaml mode, as it looks like it quite substantially changes how dashboards are created and modified.

All of this came about because I wanted to repeat card_mod code on an entities card with 20+ temperature entities. Ugh.

The other option is to use card-mod themes.

Then you can apply complex styling just by doing:

card_mod:
  class: top-level-card

Themes.yaml:

#################################################################
## Day
#################################################################

day:
  ### Main Interface Colors ###
  primary-color: etc...

## Card Mod Day
###############

  card-mod-theme: day
  card-mod-card: |

    h1.card-header {
      font-size: 20px;
      font-weight: 300;
      letter-spacing: 0px;
    }

    ha-card.top-level-card {
      border: solid 1px var(--primary-text-color);
      background: linear-gradient(rgba(147, 171, 202, 1), rgba(255, 255, 255, 0.6) 56px, rgba(255, 255, 255, 0.6) 100%); 
    }

    ha-card.top-level-card h1.card-header {
      padding-top: 0px !important;
      padding-bottom: 28px !important;

See here for more: 🔹 Card-mod - Super-charge your themes!

1 Like