thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

template-entity-row

hacs_badge

Display whatever you want in an entities card row.

For installation instructions see this guide.

Install template-entity-row.js as a module.

resources:
  - url: /local/template-entity-row.js
    type: module

Usage example

Note: This is not a card. It's a row for an entities.

Skärminspelning 2020-01-03 kl  23 03 16 mov

type: entities
title: Default
entities:
  - light.bed_light
  - entity: input_boolean.car_home
  - type: custom:template-entity-row
    icon: mdi:lamp
    name: "The light is {{states('light.bed_light')}} but nobody's"
    state: "{% if is_state('input_boolean.car_home', 'on')%} home {% else %} away {% endif %}"
    secondary: "It's {{states('sensor.time')}}"
    active: "{{ is_state('light.bed_light', 'off') }}"
  - type: custom:template-entity-row
    icon: mdi:car
    name: Hi there
    condition: "{{is_state('input_boolean.car_home', 'on')}}"

Options

All options accept jinja2 templates.

Jinja templates have access to a few special variables. Those are:

In evaluated templates the function _(<key>) (underscore) will localize the <key> to the current language. E.g. _(state.binary_sensor.motion.off) will be replaced with Clear if your language is set to English.

To find the available keys, open your browsers console, type in the following and press Enter:

document.querySelector("home-assistant").hass.resources;

Context variables are supported as well, for instance: _(ui.duration.second, count, 30) (note there are no quotes around count).

Actions

tap_action, hold_action and double_tap_action can be templated if the template evaluates to a valid action configuration in python format. Standard YAML without templates works too.

Eg:

type: custom:template-entity-row
entity: light.bed_light
# Standard yaml configuration - No templates allowed
hold_action:
  action: more-info
# JSON return format
tap_action: |
  {
    "action": "toggle",
    "confirmation": {
      "text": "Do you really want to turn {{ state_attr(config.entity, 'friendly_name') }} {% if is_state(config.entity, 'on') %}off{% else %}on{% endif %}?",
    },
  }
double_tap_action:
  action: toggle

FAQ

Why does this look weird?

Because you're not using it correctly. This is not a card. It's an entity row, and is meant to be used inside the entities card

Why doesn't toggle: true make buttons appear to control my blinds?

Because "toggle" means a toggle. It's the simplest possible way to control an entity, and anything beyond that is not in the scope of this row and will not be added.

Why is my log flooded with template errors?

This may happen if you use the GUI editor to edit a template based value. Since Home Assistant redraws the row every time you make any change to the configuration in the GUI editor, it will try to render the template every time you push a key. Since the template will be invalid for most of the time while you're editing it, you will get a lot of errors. \ There's unfortunately nothing I can easily do about this behavior.


Buy Me A Coffee