How to show text-only in Lovelace?

HI, migrating to Lovelace, I would need a way to have a card show only formatted text, and large bits of that. I briefly experimented with the Markdown card, but didn’t get it right yet.
In non-lovelace, I now use the custom card state-card-value_only, have it set in the attributes in python as follows:

left_over_card = '*=========== Orphans ===========\n'\
                 '{}'\
                 '*========== Entity count =========\n'\
                 '!- {} entities to list\n'\
                 '+- {} groups processed\n'\
                 '*=========== Settings ===========\n'\
                 '/- targetting group: {}\n'\
                 '$- ignoring {} items:\n' \
                 '%|-> {}\n'\
                 '$- ignoring {} domains:\n' \
                 '%|-> {}'\
                 .format(left_overs,
                         len(entity_ids),
                         len(groups),
                         target_group,
                         len(ignore_items),
                         ignore_items_unlist,
                         len(ignore_domains),
                         ignore_domains_unlist)

hass.states.set('sensor.orphans_sensor', len(entity_ids), {
    'custom_ui_state_card': 'state-card-value_only',
    'text': left_over_card,
  # 'unit_of_measurement': 'Orphans'
    })

to display like this:

25
How would I do that in Lovelace?

Maybe with markdown?

1 Like

well, yes, that’s what I thought, but didnt get it to work. How do you think that would have to be configured ?

I tried it like this:

- type: markdown
  content: >
    sensor.orphans_sensor

showing:

37

lol.

which is the way it is done in regular (legacy) HA:

  orphans_sensor:
    name: Orphans sensor
    icon: mdi:magnify
    entities:
      - sensor.orphans_sensor

If i do this in lovelace yaml:

  - type: entities
    title: Home summary
    show_header_toggle: true
    entities:
      - sensor.summary
      - sensor.orphans_sensor

will show:

15
but more-info shows the card as it should show in the first place:

07

so the info is there, now how to get it in the frontend.

don’t think this will be possible with the Markdown card since that uses, wel, Markdown formatting…

The custom card I use is a html card using css:

<!--
https://github.com/home-assistant/home-assistant-polymer/blob/master/src/state-summary/state-card-display.html
https://github.com/home-assistant/home-assistant-polymer/blob/master/src/components/entity/state-badge.html
https://github.com/PolymerElements/paper-styles/blob/master/color.html

# (expanded from original with extra color codes and corrected cases bold/italic)
# paper-brown-500: #795548 and google-grey-500: #9e9e9e, blue, darkbrown, deepbrown, purple
# by @Mariusthvdb
-->

<dom-module id="state-card-value_only">
  <template>

    <style is="custom-style" include="iron-flex iron-flex-alignment"></style>
    <style>
      .bold {
        @apply(--paper-font-body1);
        color: var(--primary-text-color);
        font-weight: bold;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .italic {
        @apply(--paper-font-body1);
        color: var(--primary-text-color);
        font-style: italic;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .red {
        @apply(--paper-font-body1);
        color: var(--google-red-500);
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .green {
        @apply(--paper-font-body1);
        color: var(--google-green-500);
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .yellow {
        @apply(--paper-font-body1);
        color: var(--google-yellow-500);
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .grey {
        @apply(--paper-font-body1);
        color: #9e9e9e;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .brown {
        @apply(--paper-font-body1);
        color: #795548;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .blue {
        @apply(--paper-font-body1);
        color: var(--google-blue-500);
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .darkbrown {
        @apply(--paper-font-body1);
        color: #500000;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .deepbrown {
        @apply(--paper-font-body1);
        color: #2d0000;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .purple {
        @apply(--paper-font-body1);
        color: #2d214b;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
      .normal {
        @apply(--paper-font-body1);
        color: #4b4b4b;
        margin-left: 8px;
        text-align: left;
        line-height: 20px;
      }
    </style>

    <template is="dom-repeat" items="[[computeStateDisplay(stateObj)]]">
      <div class$="[[computeClass(item)]]">[[computeItem(item)]]</div>
    </template>

  </template>
</dom-module>

<script>
Polymer({
  is: 'state-card-value_only',

  properties: {
    hass: {
      type: Object,
    },

    stateObj: {
      type: Object,
    },
  },

  computeStateDisplay: function (stateObj) {
    var text = stateObj.attributes.text;

    if (text == null) { text = stateObj.state };
    return text.split("\n");
  },

  computeItem: function (item) {
      var value = item.trim();

      switch(value.substring(0,1)) {
      case "*":
      case "/":
      case "!":
      case "+":
      case "=":
      case "%":
      case "$":
      case "#":
      case "@":
      case "^":
      case "&":
          return value.substring(1);
      default:
          return value;
      }
  },

  computeClass: function (item) {
      switch(item.trim().substring(0,1)) {
      case "*": return "bold";
      case "/": return "italic";
      case "!": return "red";
      case "+": return "green";
      case "=": return "yellow";
      case "%": return "grey";
      case "$": return "brown";
      case "#": return "blue";
      case "@": return "darkbrown";
      case "^": return "deepbrown";
      case "&": return "purple";
      default:  return "normal";
      }
  },

});
</script>

maybe this whole card could be rewritten to a Lovelace card?

you just handed it text. You didn’t specify it was anything special.

With the markdown cards, does any jinja templating work?

{{sensor.orphans_sensor}}

No it doesnt… was a great idea :wink:

00

Sounds like a good addition to the markdown cards to me.

You should be able to use that custom card in lovelace directly. You just have to follow the process of adding a custom card.

ok, thanks like this then:

resources:
  - url: /local/custom_ui/lovelace/tracker-card.js?v=0.1.5
    type: js
  - url: /local/custom_ui/lovelace/tiles-card.js?v=0.1
    type: js
  - url: /local/custom_ui/state-card-value_only.html
    type: css?

what would be the type?
this is in the file:

<dom-module id="state-card-value_only">
  <template>

    <style is="custom-style" include="iron-flex iron-flex-alignment"></style>
    <style>

testing like this:

  - type: custom:state-card-value_only
    title: Home summary
    entities:
      - sensor.summary

gives:

51

there’s also this error:

2018-11-28 16:30:40 ERROR (MainThread) [frontend.js.latest.201810264] https://mydomain.duckdns.org:8124/local/custom_ui/state-card-value_only.html:4:0 SyntaxError: Unexpected identifier 'https'. Attempted to redeclare the label 'https'.

i use this one for such purposes:

1 Like

It wouldn’t be an html file, it should be a .js. You could also just use the card that @bnhhass linked

I just did:

no matter which format I use in ui-lovelace.yaml,

like:

  - type: custom:useful-markdown-card
    content: >
       {{states.sensor.summary}}

this happens in its various forms:

32

  - type: custom:useful-markdown-card
    content: >
       [[states.sensor.summary]]

gives:

33

this is regular HA:

Frontend:

54

That card might not have access to .summery. That seams like a self added attribute on the state object? Try using an attribute or state and see what happens.

but it is a html file…like any other custom-card for HA was before Lovelace…

Yes but the html files have js inside them. It probably has to have heavy refactoring done. Lovelace handles things differently. A simple drag and drop probably won’t work. I should have been more explicit.

I’m sorry for misleading you but it’s been a very long time since I used CustomUI.

FYI I followed the code and it should be able to access those objects. I’m not sure why it can’t find summary.

i think it should be [[ sensor.summary.state ]], or [[ sensor.summary.attributes.xxxxx ]] to reference an attribute called xxxxx.

1 Like

well, it doesn’t work. Tried all these formats.

My python script creates this sensor.summary, and sensor.orphans_sensor, which have a text file as attribute indeed, and is customized via the custom-card and hence can be over 255 characters.

In regular HA this is then displayed in a card.

you think it might be [[states.sensor.orphans_sensor.attributes.text]] ?

check this:
54

the parser is complaining about the https links in the comments of the html file…who would have thought that

it doesnt like #'s either:

how to comment out in these files?

in the template editor, does {{ states.sensor.orphans_sensor.attributes }} have an entry for “text” ?
if so, the syntax in the useful-markdown-card content would be [[ sensor.orphans_sensor.attributes.text ]].

Regarding the parsing errors, are these coming from the state-card_value-only that you tried to reference in lovelace.yaml? i think that file will only work with the custom_ui and the original front-end.

yes, that is:

yes it is the html file, but I need that for my regular HA frontend, which still shows nicely because of it;-)

you can keep the state-card_value-only, just don’t reference it in the lovelace.yaml… it’s in the wrong format and language for lovelace.

so, it seems you can replicate your original card content with the useful-markdown-card inside lovelace, just a little different syntax in the configuration.