thomasloven / lovelace-template-entity-row

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

Feature request: add entity as a configuration option #5

Closed dooz127 closed 4 years ago

dooz127 commented 4 years ago

It would be awesome if entity was a configuration option in which lovelace would use default entity attribute values if not user-defined and the module would override an attribute if defined by the user. For example, my yaml right now is:

entities:
  - icon: '{{ state_attr(''binary_sensor.ring_backyard_motion'',''icon'') }}'
    name: '{{ state_attr(''binary_sensor.ring_backyard_motion'',''friendly_name'') }}'
    secondary: >-
      Last Changed: {{
      as_timestamp(states['sensor.ring_backyard_last_activity'].attributes.created_at)
      | timestamp_custom("%x %I:%M %p") }}      
    state: '{{ states(''binary_sensor.ring_backyard_motion'')|title }}'
    type: 'custom:template-entity-row'
show_header_toggle: false
title: Presence Sensors
type: entities

With the feature, the yaml could be shortened to:

entities:
  - entity: binary_sensor.ring_backyard_motion
    # apply binary_sensor.ring_backyard_motion's default icon since not defined by user
    # apply binary_sensor.ring_backyard_motion's default friendly name since not defined by user
    secondary:  >-
      Last Changed: {{
      as_timestamp(states['sensor.ring_backyard_last_activity'].attributes.created_at)
      | timestamp_custom("%x %I:%M %p") }}      
    # apply binary_sensor.ring_backyard_motion's default state since not defined by user
    type: 'custom:template-entity-row'
show_header_toggle: false
title: Presence Sensors
type: entities

Another small benefit of this approach is the entity is no longer categorized as an unused entity.

thomasloven commented 4 years ago

You can always add entity: to the configuration - even if it does nothing - and it will be counted as used.

dooz127 commented 4 years ago

Ah, good point. So I like this approach because to do something similar, I previously had this as my yaml:

card:
  entities:
    - entity: camera.front_door
      secondary_info: '${ ''Last Activity: '' +  vars[0]  }'
      type: 'custom:secondaryinfo-entity-row'
  show_header_toggle: false
  title: Cameras
  type: 'custom:hui-entities-card'
entities:
  - entity: camera.front_door
  - entity: sensor.ring_front_door_last_activity
type: 'custom:config-template-card'
variables:
  - >-
    new Date(states['sensor.ring_front_door_last_activity'].attributes['created_at'].valueOf()).toLocaleString('en-US')

This is really hard to understand. Now my yaml can be:

entities:
  - entity: camera.front_door
    icon: mdi:camera # or entity_picture: '{{ state_attr(''camera.front_door'',''entity_picture'') }}'
    name: '{{ state_attr(''camera.front_door'',''friendly_name'') }}'
    secondary: >-
      Last Activity: {{
      as_timestamp(states['sensor.ring_front_door_last_activity'].attributes.created_at)
      | timestamp_custom("%x %I:%M %p") }}
    state: '{{ states(''camera.front_door'')|title }}'
    type: 'custom:template-entity-row'
show_header_toggle: false
title: Cameras
type: entities

It would be even better if it could be:

entities:
  - entity: camera.front_door
    secondary: >-
      Last Activity: {{
      as_timestamp(states['sensor.ring_front_door_last_activity'].attributes.created_at)
      | timestamp_custom("%x %I:%M %p") }}
    type: 'custom:template-entity-row'
show_header_toggle: false
title: Cameras
type: entities
dooz127 commented 4 years ago

Awesome. Thank you so much!!!