Code Monkey home page Code Monkey logo

secondaryinfo-entity-row's Introduction

secondaryinfo-entity-row

Custom entity row for Home Assistant, providing additional types of data to be displayed in the secondary info sections of the Lovelace Entities card.

Prerequisites

  • Home Assistant >= 0.88 (last tested against 2021.4.4)
  • Thomas Lovén’s card-tools.js >= 2.0 (tested against 11)

Installation Instructions

This card is available as a plugin in the default community store of HACS

1) Install the latest Card Tools via HACS (Prerequisite)

Search for the card-tools plugin in HACS and install. This is available in the default HACS community store.

2) Install Secondary Info Entity Row via HACS

Search for the secondaryinfo-entity-row plugin in HACS and install.

3) Update the Lovelace configuration to use the plugins

resources:
  url: /hacsfiles/card-tools.js
  type: module
  url: /hacsfiles/secondaryinfo-entity-row.js
  type: module

Options

The standard Lovelace configuration for entities remains valid, with the exception of secondary_info.

New way - Home Assistant rendering

To utilize card-tools Jinja2 API, secondary_info should be a string value with at least one Jinja2 tag (either starting with {{ or {%). In addition, every user that should be able to see secondary_info content, must be an admin. This constraint comes from card-tools.

Old way - Custom template language

For card-tools old templating support, secondary_info should be a string value, enclosed in double-quotes, which supports the parseTemplate syntax defined in card-tools.js. Per the documentation:

Two things are important:

- Template must start with [[<space> and end with <space>]]
- This is not in any way the same kind of template as used in the Home Assistant configuration

The templates are parsed by reading one step at a time from the `hass.states` object.
Thus, the first part must be an entity with domain and id, e.g. `light.bed_light`, `media_player.bedroom` etc.
Next is one of:

- entity_id
- state
- attributes.<attribute>
- last_changed
- last_updated

Also see details of the new conditional syntax at useful-markdown-card:

if

Syntax: [[ if(<condition>, <then>, <else>) ]] Simply put, if <condition> is satisfied, the template will be replaced with <then>, otherwise it will be replaced with <else>.

Both <then> and <else> can in turn be <template> expressions, and <else> can even be another if(!).

Conditions are in the form <left> <comparison> <right> where <left> and <right> are <template>, strings or numeric values.

<comparison> is one of ==, !=, <, >, <= or >=.

Examples

type: entities
title: Custom Secondary Info
entities:
- entity: sun.sun
  name: Entity ID with wrapped in tag
  type: "custom:secondaryinfo-entity-row"
  secondary_info: "<b style='color:red'>[[ sun.sun.entity_id ]]</b>"
  
- entity: sun.sun
  name: Absolute time for last-changed
  type: "custom:secondaryinfo-entity-row"
  secondary_info: "[[ sun.sun.last_changed ]]"
  
- entity: sun.sun
  name: Static text
  type: "custom:secondaryinfo-entity-row"
  secondary_info: "This is the entity row for the Sun"

- entity: sun.sun
  name: Entity attribute
  type: "custom:secondaryinfo-entity-row"
  secondary_info: "Next Dawn: [[ sun.sun.attributes.next_dawn ]]"
  
- entity: sun.sun
  name: Templated entity object
  type: "custom:secondaryinfo-entity-row"
  secondary_info:  "Next Dawn: [[ {entity}.attributes.next_dawn ]]"
  
- entity: sun.sun
  name: Conditional template
  type: "custom:secondaryinfo-entity-row"
  secondary_info: '[[ if(sun.sun.attributes.elevation < 0, "Below", "Above") ]] the horizon'
  
- entity: sun.sun
  name: Jinja2 template
  type: "custom:secondaryinfo-entity-row"
  secondary_info: "Next Dawn: {{ state_attr('sun.sun', 'next_dawn') }}"

example

Changelog

0.5

  • Jinja2 templates support from card-tools

0.4.1

  • Updated HACS support files and documentation

0.4

  • Compatible with latest card-tools
  • Updated README with HACS install info

0.3.1

  • Replaced deprecated card-tools functions
  • Added example image to GitHub

0.3

  • The configured entity object can now be referenced as {entity} inside a template. This enables compatibility with dynamic entity list generators such as auto-entities.
  • Requires card-tools 0.4, which introduces conditional statements in the template. See useful-markdown-card.
  • Examples updated

0.2

  • Compatibility with Home Assistant 0.88

0.1.1

  • Add custom_cards.json for custom_updater integration

0.1

  • New release based on card-tools

secondaryinfo-entity-row's People

Contributors

alryaz avatar iantrich avatar lociii avatar mariusthvdb avatar mizterb avatar thomasloven avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

secondaryinfo-entity-row's Issues

Referencing current item Problem

Hi. I have a card for my packages (using 17track)

      - card:
          type: custom:auto-entities
          show_empty: false
          card:
            type: entities
            title: PACKAGES
            show_header_toggle: false
          filter:
            include:
              - entity_id: 'sensor.*track_package_*'
                options:
                  secondary_info: "<span style='color:grey'>[[ {entity}.attributes.info_text ]]</span>" 
        style:
          background-blend-mode: multiply
          background-color: 'rgba(180,180,180,0.5)'
          # background-image: url("/local/images/grey_theme/salon.png")
          background-position: 250px -50%
          background-repeat: no-repeat
          background-size: 70% auto
          border-radius: 10px
          font-weight: 600
          color: 'rgba(100,100,100,1)'
          box-shadow: >-
            -5px 5px 13px -7px #999999, 5px 5px 13px -7px #999999, 0px 2px 0px
            0px rgba(90,90,90,0.5), 0px 0px 1px 1px rgba(0,0,0,0.1)
        type: 'custom:card-modder'  

But secondary_info: "<span style='color:grey'>[[ {entity}.attributes.info_text ]]</span>" doesn't show nothing in second row
изображение

Please help to solve this.
Thanks.

Code help

Not an issue, but I am struggling with the syntax.
How do I use a sensor state into an if-result like:

secondary_info: '[[ if(sun.sun.attributes.elevation < 0, "Below", "Above") ]] the horizon'  #This works fine

secondary_info: '[[ if (binary_sensor.energy_mode_cost == "on",  "Cost {{ states('sensor.nordpool_kwh_home') }} Kr/kWh ", "") ]]' #ERROR

Please advise.

State Color not working

Notice all my entities using secondaryinfo does not have state color. Even the state color set to true

jinja2 example not working?

I seem be having issues using jinja2 from the latest 5.0 release. yml is copied directly out of the readme:

      - entity: sun.sun
        name: Jinja2 template
        type: "custom:secondaryinfo-entity-row"
        secondary_info: "Next Dawn: {{ state_attr('sun.sun', 'next_dawn') }}"

image

Thoughts on what may be going on?

Using weblink in secondary info

It would be great to be able to reference a weblink entity and therefore create a link off of that in the secondary info area.

e.g:

- entity: sensor.next7days_farmhouse
  icon: mdi:hotel
  name: 'Farmhouse'
  type: custom:secondaryinfo-entity-row
  secondary_info: "[[ weblink.bookings_farmhouse ]]"

HACS support

The custom updater has been deprecated in favor of HACS. Can this be updated to use the new HACS format?

Button entities state vs action

I have a issue with button.

Without:

image

With this card:

image

I also noticed a error in Edge:

image

that correspond to:

let secondaryInfoDiv = this._wrappedElement.shadowRoot.querySelector("hui-generic-entity-row").shadowRoot.querySelector(".secondary");

My environment:

Home Assistant

version core-2022.4.5
installation_type Home Assistant Container
dev false
hassio false
docker true
secondaryinfo-entity-card 5.0
card-tools 9

Can you please review the code ?
Thx in advance,

Simone

Refresh page > "Unknown type encountered"-error

Hi,

I'm on the latest version of HA, and most of the times where i'm using the "Refresh" option in Lovelave, the secondaryinfo-entity-row-entities is returning Unknown type encountered: toggle-errors.

It also showing up from time to time, if the app is just reloading the page, and so. And it's here, i found it to be the biggest problem, cause my girlfriend are complaining about it, too :-D

Unknown type encountered: toggle.

entity: switch.sonoff4
type: toggle
secondary_info: 'Lyd fra [[ if(switch.nodemcu4678858 == on, "Chromecast Audio", "Stationær") ]]'

Unknown type encountered: text.

entity: binary_sensor.0x00158d0001d672e5_occupancy
name: Bevægelse
icon: 'mdi:run'
type: text
secondary_info: 'Stationær er [[ if(sensor.stationaer == "Online", "tændt", "slukket") ]]'

image

The secondaryinto-entity-row is within an vertical-stack with multiple cards.

And it's reporting the following, in my console:

TypeError: e.parentElement is nullhui-stack-card.ts:97:4
    _rebuildCard hui-stack-card.ts:97
    _createCardElement hui-stack-card.ts:85
    r fire_event.ts:76
    a create-element-base.ts:92

If i use the tree dots, and update my lovelave-interface again, the errors are gone:
image

If it do it again, there's a big change, for the errors to show up, agian.

So i'm not sure if this is related to some tmp-values, a timing issue, some caching related, or... well... something else :( :)

Support for state_with_unit

I'd like to use an entity state with its unit of measurement so it reads a bit nicer. Would it be possible to support for example a "state_with_unit" attribute to combine both the state and its unit attribute?

Secondary info does not appear immediately

This seems to coincide with the home assistant 0.110 update (currently on 0.110.4).
It takes a few ticks to _updateElement for the information to update.

Screen Recording 2020-05-31 at 12 27 27 mov

Error details:

secondaryinfo-entity-row.js:39 Uncaught (in promise) TypeError: Cannot read property 'shadowRoot' of null
    at HTMLElement._updateElement (secondaryinfo-entity-row.js:39)

Screenshot 2020-05-31 at 12 10 30

Extremely slow on mobile if templates are used

If templates are included, the lovelace frontend becomes slow and almost impossible to use.
I tried this on 3 different Android devices, and a couple of different browsers. On a Desktop everything is OK.

I included 5 templates on a view (last triggered, state of a socket etc.), .
Other views work OK since to secondary info is present.

- entity: automation.fridge_door_alarm
    type: "custom:secondaryinfo-entity-row"
    secondary_info: 'Door is: [[ if(binary_sensor.door_window_sensor_158d0000f125f7 == "off", "Closed", "Open") ]]'

- entity: automation.store_work_hours_googledrive
   type: "custom:secondaryinfo-entity-row"
    secondary_info: "Trigger: [[ automation.store_work_hours_googledrive.attributes.last_triggered ]]"

- entity: group.office_lights
   type: "custom:secondaryinfo-entity-row"
   secondary_info: "Trigger: <b style='color:red'>[[ input_number.office ]]</b> lux (slider). Now: <b style='color:red'>[[ sensor.illumination_158d0001e07ed4 ]]</b> lux. PC: <b style='color:red'>[[ sensor.pc_power ]]</b> W"              

cardTools.litElement(), cardTools.litHtml(), cardTools.hass() are deprecated

I have this warnings in console:

One or more of your lovelace plugins are using the functions cardTools.litElement(), cardTools.litHtml() or cardTools.hass(). Those are replaced with better alternatives and will be removed a some point in the future.
deprecationWarning @ card-tools.js:14
litElement @ card-tools.js:25
customElements.whenDefined.then @ secondaryinfo-entity-row.js:3
Promise.then (async)
(anonymous) @ secondaryinfo-entity-row.js:1

image

reference {entity} inside conditional?

It appears we're not able to reference {entity} inside of a conditional. Would we be able to enhance this card to support this? For example, this doesn't work:

secondary_info: '[[ if({entity}.attributes.years_at_next_anniversary == "undefined", "", {entity}.attributes.years_at_next_anniversary) ]]'

timestamp calculations possible?

Hi,

I tried to set the color of the secondary info line based on the age of a certain timestamp.

      <b style='color:[[ if(as_timestamp({entity}.attributes.receivedTS) -
      as_timestamp(now()) < 14400, "green", "red") ]]'>[[

This results in red text because the "as_timestamp" method is not evaluated and therefore the result is not a number.

Is it possible to use the as_timestamp function or someting similar somehow?

Config is not supported by the UI editor

Hello i'm on hass.io 0.95.4 configured with HACS and this plugin.
While configuring some basic entities cards, i'm getting this error in the card setup window:

Your config is not supported by the UI editor:
Expected a value of type {entity,name,icon} | entity-id for entities.0.secondary_info but received "[[ sun.sun.last_changed ]]".
Falling back to YAML editor.

Also, even if the secondary infos are displayed, the GUI becomes very sluggish until i comment the secondary-info section.

Please don't take in account for the secondary-info attributes actually used: it is only a testing one, just to give the idea ;-)

Attached the configs i'm using

Any hints?

TIA

en9tities_yaml

[lovelaceUI_yaml.txt](https://github.com/custom-cards/secondaryinfo-entity-row/files/3400545/lovelaceUI_yaml.txt) [card.txt](https://github.com/custom-cards/secondaryinfo-entity-row/files/3400546/card.txt)

time zone

Great card! Many thanks!! I have a question, which timezone is being used? I use GMT+1 (local time) but the time being displayed GMT+0:00 (so one hour too early). I changed my ubuntu TZ into:

image

But still no result.. What to do?

0.116 Breaking Changes

Beginning HA 0.116 all custom Lovelace cards (at least those that I use), including this one, no longer work.

The 0.116 release notes included a link to a blog post explaining the (breaking) changes.

I do not consider this as a bug per se, but was wondering what the developer's plans are regarding this matter. I ask in light of the recent announcement that the developer of Custom Header has decided to stop working on the project.

Thanks tot the dev for your work.

Formatting last_changed

It would be great to have the ability to format the secondary_info attributes (cutting of parts of the string etc.).

Jinja2 templates will spam network requests.

When using the jinja2 template, this card will request the template endpoint multiple times every second.

  - entity: light.entrance_outdoor    
    type: "custom:secondaryinfo-entity-row"
    secondary_info: "{{ 1 + 1 }}"

image

Guess this is because _updateElement will trigger as soon as something changes in the hass object, which for a larger setup could be many hundred times per second.

still get "can't find card-tools" despite everything I've tried

Ok maybe I'm dense, but I can't get this to work, it always says "can't find card tools:

things I've tried

using card-tools 0.4 and 0.4.1
using "raw editor" in lovelace ui, as well as editing /configdir/ui-lovelace.yaml

config_dir/ui-lovelace.yaml:

resources:
  - url: /local/custom-lovelace/weather-card/weather-card.js
    type: module
  - url: /local/card-tools.js
    type: js
  - url: /local/secondaryinfo-entity-row.js
    type: module

UI:
image

www directory:

/home-assistant/config/www$ ls -la
total 694
drwxr-xr-x  5 1001 1001     13 Jul 10 21:50 .
drwxr-xr-x 10 1001 1001     48 Jul 10 21:54 ..
-rw-r--r--  1 root 1001  11852 Jul 10 21:50 card-tools.js
drwxr-xr-x  3 root 1001      3 Feb  9 15:03 custom-lovelace
drwxr-xr-x  2 root 1001      4 Feb  9 14:40 custom_ui
-rw-r--r--  1 root 1001     54 Aug 30  2018 googlee25d310138468eb5.html
-rw-r--r--  1 root 1001 175658 Aug 19  2018 lifx.png
-rw-r--r--  1 1001 1001  26007 May 28  2018 model-s.jpg
drwxr-xr-x  2 root 1001      7 Feb  9 19:09 nest-icons
-rw-r--r--  1 1001 1001  34802 Oct 28  2016 nest.jpg
-rw-r--r--  1 root 1001  21011 Aug 13  2018 nest.png
-rw-r--r--  1 root 1001 326811 Dec 22  2016 nestprotectg2.png
-rw-r--r--  1 root 1001   2146 Jul 10 21:34 secondaryinfo-entity-row.js

Despite this, everything still says "can't find card tools":
image

What am I missing?

Change color according to numeric state

Is it possible to change color according to numeric state like in the case of a battery voltage? If above 3.2 volt green, between 2.9 and 3.2 yellow. Below 2.9 red.

Also will it be possible to round a state attribute value in this card?

Third row and word wrap

I'm using this to help show some upcoming calendar entries for sporting events.

The name of the event (opponent) is too long and end up showing ... at the end.
In addition to that I want to show the location (broadcast) as well which ends up cutting off even more.

So with that I have a couple of questions.

  • Is it possible to add a third row?
  • Is it possible to have word wrap?
  • Is it possible to display something under the right side item (date_sortable)?

image
image

Problem with HA 0.105.0b0

Since the latest beta (0.105.0b0) from HA, the issue of this card has not worked.

  • type entities
      title: WZ
      entities:
        - entity: switch.shelly_shplg_s_040f0f
           name: Shelly Plug S socket WZ outside
           type: "custom: secondaryinfo-entity-row"
           secondary_info: "192.168.178.69"

results in the following error message:

Unknown type encountered: custom:secondaryinfo-entity-row

entity: switch.shelly_shplg_s_040f0f
name: Shelly Plug S socket WZ outside
type: "custom: secondaryinfo-entity-row"
secondary_info: "192.168.178.69"

Jinja2 template

Hello
What I have to do in order useing of Jinja2 template?
Old syntax is working.

image

I'm admin (owner) of my HA.

TypeError: null is not an object

getting this error in Safari:

Unhandled Promise Rejection: TypeError: null is not an object (evaluating 'this._wrappedElement.shadowRoot.querySelector')

and Chrome:

Uncaught (in promise) TypeError: Cannot read property 'querySelector' of null
    at HTMLElement._updateElement (secondaryinfo-entity-row.js?v=0.4:38)

on a perfectly correctly performing config:

      - type: custom:secondaryinfo-entity-row
        entity: input_number.home_theater_lux
        secondary_info: >
          Mean living: [[ sensor.mean_living_lux.state ]] lx
      - entity: binary_sensor.home_theater_lux_input
        secondary_info: last-changed

Schermafbeelding 2021-01-04 om 17 33 42

there are no none objects in this config, as the image proves. Dont know if this started recently tbh, my setup is

HA OS 2020.12.2
secondaryinfo-entity-row: 0.4

thought it might have been the .state suffix in the template, so took that out.

      - type: custom:secondaryinfo-entity-row
        entity: input_number.home_theater_lux
        secondary_info: >
          Mean living: [[ sensor.mean_living_lux ]] lx

oddly enough, the frontend remains correct, and the error stays.... using this on multiple entities in the config.

can't find card-tools (which shouldn't be necessary)

while Thomas Loven explicitly says this here

Just for the record - the only good reason to have card-tools installed is because another card tells you to.
None of my cards do, and if you find one that does, you should really let the maintainer know that there are better ways to get that functionality nowadays.
I'll gladly help with the transition.

please contact Thomas and try to fix this?

Schermafbeelding 2020-08-06 om 23 38 29

Home Assistant Cast - not working

This element is not working with home assistant cast. Works fine in a browser and in the mobile app.

Says Custom element doesn't exist: secondaryinfo-entity-row

Syntax error

Hi

I`m getting error when trying to pull battery level on Wyze binary sensor using this script.

Can you spont an error?
Capt233232ure

entities:

  • entity: binary_sensor.wyzesense_778bb687
    name: Front Door
    secondary_info: '[[ binary_sensor.wyzesense_778bb687.battery_level ]]'
    type: 'custom:secondaryinfo-entity-row'
    title: Wyze Battery
    type: entities

Templating inside secondary info?

any way to templating in it ie

secondary_info: "[[ {{sensor.cmd_nicehash_usdbtc.state|float * sensor.cmd_nicehash_wallet.state|float} }]]"

[Help] Cannot parse entity name with config.entity

Seems I cannot use the object config.entity from custom:auto-entities in custom:secondaryinfo-entity-row.
While it works fine for ":host"

Any hint ?

The goal is to extract a part of the entity name and show it as secondary row (due to ESPhome not handling attributes...).

Simone

type: custom:auto-entities
card:
  type: entities
  title: Stato batterie CR-2032
  show_header_toggle: false
  state_color: true
filter:
  include:
    - entity_id: '*xiaomi*battery*'
      options:
        style: |
          :host {
            --paper-item-icon-color: 
             {% if states(config.entity) | int(0) >= 90 %}
                  green
             {% elif states(config.entity) | int(0) >= 15 %}
                  yellow
             {% else %}
                  red
             {% endif %}; 
          }
        type: custom:secondaryinfo-entity-row
        secondary_info: "{{ config.entity[22:-14] }}"
sort:
  method: state
  reverse: true
  numeric: true

jinja templating support

Have you considered supporting jinja templates? I'm just trying to get a friendly timespan of the last changed value which I can do easily in jinja

Custom element doesnt exist

Tried using it, getting error, so to diagnose I used the exact same text as in GitHub and I still get an error. Installed from HACS did a couple of restarts

type: entities
title: Custom Secondary Info
entities:
  - entity: sun.sun
    name: Entity ID with wrapped in tag
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: '<b style=''color:red''>[[ sun.sun.entity_id ]]</b>'
  - entity: sun.sun
    name: Absolute time for last-changed
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: '[[ sun.sun.last_changed ]]'
  - entity: sun.sun
    name: Static text
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: This is the entity row for the Sun
  - entity: sun.sun
    name: Entity attribute
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: 'Next Dawn: [[ sun.sun.attributes.next_dawn ]]'
  - entity: sun.sun
    name: Templated entity object
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: 'Next Dawn: [[ {entity}.attributes.next_dawn ]]'
  - entity: sun.sun
    name: Conditional template
    type: 'custom:secondaryinfo-entity-row'
    secondary_info: '[[ if(sun.sun.attributes.elevation < 0, "Below", "Above") ]] the horizon'

Captura de pantalla 2020-12-18 a las 10 05 06

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.