gadgetchnnel / lovelace-home-feed-card

A custom Lovelace card for displaying a combination of persistent notifications, calendar events, and entities in the style of a feed.
277 stars 24 forks source link

Feature suggestion #116

Open pdwonline opened 6 months ago

pdwonline commented 6 months ago

Would be nice to be able to hide entities based an expression or value of a sensor like this:

type: 'custom:home-feed-card'
  title: Home Feed
  show_empty: false
  entities:
     - entity: sensor.something
        multiple_items: false
        hidewhen: "{{states(sensor.something) | int(0) > 10}}"
notabene00 commented 5 months ago

First thing first, author, great work. Hope you don’t mind if I place here a link to my fork. https://github.com/notabene00/lovelace-home-feed-card

@pdwonline you can just add notabene00/lovelace-home-feed-card to HACS and install from there.

I've implemented jinja2 templates support for content_template, added condition, attribute options and made icon templateable.

condition, if defined, must be a jinja template string, if it renders to 'True', element will be displayed, otherwise - no. attribute parameter, if defined, must be an attribute name of the entity that is a timestamp or a datetime and then attributes value will be used to calculate timediffs and display "state". can also be a template string. icon just can contain jinja2-templates now to be in sync with any entity's state changes.

Krakoukas73 commented 5 months ago

Hi @notabene00 ,

I've added your fork. Could you please show few examples for condition usage and jinja2 syntax in content_template ? Thank you !

notabene00 commented 5 months ago

@Krakoukas73

Could you please show few examples

Sure. Here you go:

entities:
  - entity: sensor.marinas_schedule
    icon: mdi:human-female-female-child
    condition: '{{ as_local(as_datetime(state_attr(entity, attribute))) > now() }}'
    attribute: "{ 'end_date' if state_attr(entity, 'is_working_now') else 'start_date' }}"
    content_template: >-
      Марина {{ 'заканчивает' if state_attr(entity, 'is_working_now') else
      'начинает' }} в {{ state_attr(entity, attribute).strftime('%H:%M') }}

Is something like this enough?

Krakoukas73 commented 5 months ago

@notabene00

Thank you ! I'm confused. Native {{display_name}} and {{state}} are working Jinja is not interpreted. I am missing something

  - entity: sensor.here_travel_time_duration_in_traffic
    name: Temps de trajet avec Nico
    content_template: >-
      Native name: {{display_name}} <br><b><font size="5" color="#FF4444">
      Native state: {{state}} </font></b><br>
      Jinja2 : {{ 'заканчивает' if state_attr(entity, 'is_working_now') else 'начинает' }}

image

notabene00 commented 5 months ago

@Krakoukas73 I think you just didn't clear your browser's cache. Or have any other issue with resources. Because it should be vice versa - "native" (for original card) {{state}} option should not work anymore, as I removed it. But really native (for Home Assistant) jinja2 support included and is working for me.

notabene00 commented 5 months ago

And I've synced repo with local copy just now. There was an issue with "attribute" being not passed into condition template.

Krakoukas73 commented 5 months ago

Thank you so much @notabene00 for your work and your time Working like a charm and as expected. Fantastic !

Krakoukas73 commented 4 months ago

Hi Roman @notabene00 !

I'm using intensively your custom home-feed-card to centralize all alerts from 1.5K+ automations and it is awesome. Thank you. Below is the visual rendering. After that, alerts from home-feed are compiled, submited to Extended OpenAI Conversation and summarized with TTS.

image

sort order was reversed from originale : newest items are bottom, oldest are on top. Everything else works perfecty :-) I used card-mod for this :

#notifications { display: flex; flex-direction: column-reverse; }

notabene00 commented 4 months ago
- entity: sensor.xxx
  condition: '{{ int(states(entity)) > 40 }}'

int might be replaced with float to meet your needs

- entity: sensor.xxx
  condition: "{{ states(entity) not in ['1','4','29'] }}"

if you need to exclude several states using templates

Oh, I seem to be responding to something that is no longer in your post

new ordering paradigm is not a bug (maybe once I'll add a config parameter with ordering options) at first, I was doing this fork for personal use my use case implies direction from the past to the future

Krakoukas73 commented 4 months ago

Oh, I seem to be responding to something that is no longer in your post

Sorry. Being upset for days with conditions syntax. Asking GPT : correct syntax in milliseconds. I should asked OpenAI before replying here

I'm confused again

notabene00 commented 4 months ago
  1. condition is a condition for an entity to be shown, not to be hidden
  2. you need to cast types explicitly if performing numerical comparisons, as the states() function returns a string

anything else I can help you with?

Krakoukas73 commented 4 months ago

Nothing to add @notabene00 : awesome fork, great feedback and explanations. Thank you so much ! I'm using it thought scripts & automations every 45sec 24/24