Lovelace: Multiple entity row

Yes, you are right, I am sorry. It did not work for me, because my style looks like this

  - entity: sun.sun
    type: custom:multiple-entity-row
    name: Küche
    state_header: null
    secondary_info: null
    style: |
      :host .entity {
          color: #bf0056
        }
          div.entity:nth-child(1) state-badge {
            color: red;
        }
          div.entity:nth-child(2) state-badge {
            color: red;
        }
          div.entity:nth-child(3) state-badge {
            color: red;
        }
          div.entity:nth-child(4) state-badge {
            color: red;
        }

How do I add the state-bade thing here?

  1. There is no need to use card-mod to set a static color for secondary entities (i.e. entities on the right side of the row). Use “styles” option with a required style.
  2. Wrong indentation in your code. Check card-mod examples for a correct indentation.

So, first remove useless and wrong code. Then come back to add that “state-badge thing”.

  1. I do not have card-mod in my example, or do I miss something?
  2. Do you mean the space before div.entity…? I corrected it, but if was working like this.

I don’t know what you mean by useless code. I need the div.entity… stuff for further entities. This is a working example:

type: entities
title: null
entities:
  - entity: sun.sun
    icon: hass:none
    type: custom:multiple-entity-row
    name: Wohnzimmer
    state_header: null
    secondary_info: null
    style: |
      :host .entity {
          color: #bf0056
        }
        div.entity:nth-child(1) state-badge {
            color: red;
        }
        div.entity:nth-child(2) state-badge {
            color: red;
        }
        div.entity:nth-child(3) state-badge {
            color: red;
        }
        div.entity:nth-child(4) state-badge {
            color: red;
        }
    entities:
      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
        hide_if: 'off'

The problem is, that I don’t know how to combine the style: | with your state-badge thing, which does not have a | after style:. If I omit the |, I get the error message “can not read a block mapping entry; a multi line key may not be an implicit key”.

Card-mod code starts with “style”.
You should at least read card-mod docs on GitHub.
Indentation problem also remains.
Also, read about a “styles” option for multiple-entity-row.

I see, I thought you meant the exact card_mod: line. I did read the GitHub docs for card-mod, but the wiki there leads to a nice, extensive post from you.

I olny reduced my card to this example with a single color, so it is easier to read. My original card has 10 different colors depending on a temperature sensor. Here is a simple example.

type: entities
title: null
entities:
  - entity: sun.sun
    icon: hass:none
    type: custom:multiple-entity-row
    name: Wohnzimmer
    state_header: null
    secondary_info: null
    style: |
      :host 
        .entity {
          color:   
              {% if is_state('sun.sun', 'above_horizon') %}
                #bf0056
              {% elif is_state('sun.sun', 'below_horizon') %}
                #268bd2
              {% endif %};
        }
        div.entity:nth-child(1) state-badge {
            color: red;
        }
        div.entity:nth-child(2) state-badge {
            color: red;
        }
        div.entity:nth-child(3) state-badge {
            color: red;
        }
        div.entity:nth-child(4) state-badge {
            color: red;
        }
    entities:
      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
        hide_if: 'off'

Screenshot_20220216_115836

And there I still want to get rid of the space before “Wohnzimmer”.

I still don’t know what you mean by “indentation problem”. My code is working for me.

Edit:
Changed the above code to the hopefully correct identation.

First - let’s call the “left” entity as the “main entity” (for which we may display a state on the last right column), all right entities - “secondary entities”.

  1. You got ONE secondary entity - but you specified card-mod styles for FOUR secondary entities.

  2. For secondary entities you may use a “styles” option (no card-mod required) to set a color and some other CSS properties:

    entities:
      - entity: sensor.xxxxxxx
        styles:
          width: 80px
          text-align: left
          color: red

or

        styles:
          --paper-item-icon-color: red

This is a good choice if styles (colors etc) are static. If they are dynamic (depend on some conditions) then you should either place the whole row inside config-template-card (supports JS) or use card-mod (supports jinjia2).

  1. If you need to color the main entity’s state you may use the “styles” option:
  - type: entities
    entities:
      - type: custom:multiple-entity-row
        entity: sensor.cleargrass_1_co2
        entities: &ref_entities
          - entity: sun.sun
          - entity: sun.sun
        name: Colored state
        show_state: true
        state_header: CO2
        styles:
          color: magenta
          --secondary-text-color: cyan
      - type: custom:multiple-entity-row
        entity: sensor.cleargrass_1_co2
        entities: *ref_entities
        name: Colored state
        show_state: true
        styles:
          color: magenta

image

Or card-mod:

type: entities
entities:
  - type: custom:multiple-entity-row
    entity: sensor.cleargrass_1_co2
    card_mod:
      style: |
        .state.entity {
          color: magenta;
        }
        .state.entity span {
          color: cyan;
        }
    entities: &ref_entities
      - entity: sun.sun
      - entity: sun.sun
    name: Colored state
    show_state: true
    state_header: CO2
  - type: custom:multiple-entity-row
    entity: sensor.cleargrass_1_co2
    card_mod:
      style: |
        .state.entity {
          color: magenta;
        }
    entities: *ref_entities
    name: Colored state
    show_state: true

image

  1. As for indentation - check other card-mod examples, see the basic rules.

  2. The "hide_if" is meaningless here:

      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
        hide_if: 'off'

since states('sun.sun') is never off.

  1. This code may cause errors:
          color:   
              {% if is_state('sun.sun', 'above_horizon') %}
                #bf0056
              {% elif is_state('sun.sun', 'below_horizon') %}
                #268bd2
              {% endif %};

since you have not provided a “default path” (no “else” is provided).

  1. The minimal code is (“styles” for a state & secondary entity’s icon, “card-mod” to hide the main entity’s icon):
  - type: entities
    entities:
      - type: custom:multiple-entity-row
        card_mod:
          style:
            hui-generic-entity-row:
              $: |
                state-badge {
                  display: none;
                }
        entity: sensor.cleargrass_1_co2
        entities:
          - entity: sun.sun
            name: false
            icon: true
            styles:
              --paper-item-icon-color: red
        name: xxxxxxxxx
        show_state: true
        styles:
          color: magenta

image

Only to complete/add: … or with lovelace-card-templater, which supports jinjia2 as well. But I didn’t try this for styles/ in multiple entities row yet.

Probably yes, never tried it so far)))

Thank you very much for your thorough explanation! :slight_smile: I now understand what you meant by with “card-mod” and without. I simply assumed it would do the same thing.

  1. I wanted to add more entities and simply left it there, sorry.
  2. Yes, that is easier, done.
  3. Will do that.
  4. Same as 1.
  5. Thanks for the hint, added a “else” path.
  6. & 3. I am still struggling to combine a conditional color for the “main entity” and the state-badge { display: none; } thing.

Following your explanation I get this:

type: entities
title: null
entities:
  - entity: sun.sun
    icon: hass:none
    type: custom:multiple-entity-row
    card_mod:
      style:
        hui-generic-entity-row:
          $: |
            state-badge {
              display: none;
            }
    name: Wohnzimmer
    state_header: null
    secondary_info: null
    entities:
      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
        hide_if: below_horizon
        styles:
          '--paper-item-icon-color': '#ff8100'
    styles:
      color: magenta

Screenshot_20220217_160935

But if I add my if-loop from above to the styles part at the end, it does not work. Nor was I able to combine the state-badge { display: none; } part to the .state.entity { color: magenta; } part from you number 3. Is it possible to combine them without the config-template-card?

type: entities
title: null
entities:
  - type: custom:multiple-entity-row
    entity: sun.sun
    #icon: hass:none
    card_mod:
      style:
        hui-generic-entity-row $: |
          state-badge {
            display: none;
          }
        .: |
          .state.entity {
            color: magenta;
          }
          .state.entity span {
            color: cyan;
          }
          div.entity:nth-child(1) state-badge {
            color: red;
          }
          div.entity:nth-child(2) state-badge {
            color: orange;
          }

    name: Wohnzimmer
    state_header: xxxx #null
    secondary_info: null
    entities:
      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
        #hide_if: below_horizon
        #styles:
          #--paper-item-icon-color: '#ff8100'
      - entity: sun.sun
        icon: mdi:weather-sunny
        name: false
    #styles:
      #color: magenta

image

That’s it! Thank you very, very much!

One last question, is there a disadvantage to combine card-mod style with the styles from multiple-entity-card? Because you commented it out. I want only one of the entities to have a specific color, but the position of it is not always the same, so div.entity:nth-child(1) state-badge is not a good way to achieve this, but styles under the entity does work or is there a way to specify div.entity:nth-child(1) state-badge to a specific entity?

I commented the “styles” stuff since the same styling was made by card-mod.
When combining card-mod and “styles” you should apply each method to different elements to avoid conflicts.

This is a case when you should use the “styles”.
Suppose the 1st secondary entity is not displayed since “hide_if” works - then the index of some entity is changed - so only fixed “styles” works.

nth-child(1) means “the 1st child element”.
There are some other methods, in SOME cases they may help to select the needed element. But I would choose “styles” in this case.
Once again, “styles” MAY be used instead on card-mod (which may be used to access ANY element) in some limited scope and only for static CSS properties. In most cases “styles” are quite enough.

All right. I will apply them to different elements. And I think I can not have one entity blinking :grinning_face_with_smiling_eyes:

Thank you for your time and the good explanation. I do understand it now far better and hopefully it helps someone else as well.

How to show a markdown card inside a multiple-entity-card?

i tried this:

- type: markdown
  content: >
    ## Last Flight Info

But i get error:

Schermata 2022-03-04 alle 15.02.27

that wouldn’t be possible at all considering https://github.com/benct/lovelace-multiple-entity-row#examples

this is a multiple-Entity-row card, not a multiple-Card-row card? And, its not a card, but a row element to be used in an entities card…

check the entity configuration option: https://github.com/benct/lovelace-multiple-entity-row#configuration

1 Like

If I have a multiple-entity-row that

  • does not show the main entity
  • all sub-entities have a hide_if condition

is it possible to hide the row itself if all of the sub-entities are hidden?

Example:

entity: sensor.climacell_weed_pollen_index
type: custom:multiple-entity-row
show_state: false
name: false
entities:
  - entity: sensor.climacell_tree_pollen_index
    hide_if: none
  - entity: sensor.climacell_grass_pollen_index
    hide_if: none
  - entity: sensor.climacell_weed_pollen_index
    hide_if: none

I have lots of battery operated sensors and would like to see a red battery icon appear next to its value when the battery is below a certain threshold. I am able to show the actual battery percentage only when its value is below 35 but I don’t know how to replace that with an icon. I am hoping to avoid using templates in configuration.yaml (if that is even a viable solution) as that would require quite a few of them.

Is there a way to replace “Battery xx%” with a red battery empty icon keeping the code within this card?

type: entities
entities:
  - type: custom:slider-entity-row
    entity: light.front_porch_light
    toggle: true
  - entity: binary_sensor.front_porch_motion_sensor
    type: custom:multiple-entity-row
    entities:
      - entity: sensor.front_porch_motion_sensor_battery
        name: Battery
        hide_if:
          above: 35
  - entity: light.driveway_lights
  - entity: switch.garage_light
    icon: mdi:lightbulb
  - type: custom:slider-entity-row
    entity: light.patio_light
    toggle: true
  - entity: binary_sensor.patio_motion_sensor
    type: custom:multiple-entity-row
    entities:
      - entity: sensor.patio_motion_sensor_battery
        name: Battery
        hide_if:
          above: 35
  - entity: light.backyard_light
    icon: hass:track-light

EDIT:

If only I could get this to work… (an alternative would be to change icon and its color based on sensor value)

  - entity: binary_sensor.front_porch_motion_sensor
    type: custom:multiple-entity-row
    entities:
      - icon: mdi:battery-low
        styles:
          --paper-item-icon-color: red
        hide_if:
          entity: sensor.front_porch_motion_sensor_battery
          above: 35

Your options:

  1. Use card-mod.
    Card-mod thread → 1st post → link at the bottom → post for multiple-entity-row
  2. Use config-template-card.
1 Like

Thank you for the tips… but I can’t figure it out :frowning:

I am having trouble figuring out how to change the icon and color based on the battery entity of the motion sensor.

If I could use the code below, I should be able to display the icon only when the battery is below 35% as I’ve read mdi:blank should be what is says… blank.

          {% if states('sensor.front_porch_motion_sensor_battery') | int(0) < 35 %} mdi:battery-alert-variant-outline
          {% else %} mdi:blank
          {% endif %}

EDIT: added mdi: to first icon in case others try to use the code based on post below

  1. Unclear what you are doing. You posted a code with some expression and did not explain where this code is used.
  2. Probably you missed “mdi:” for the 1st icon.