thomasloven / lovelace-auto-entities

🔹Automatically populate the entities-list of lovelace cards
MIT License
1.24k stars 113 forks source link

[FR] Management of more than 1 attribute #279

Closed chemelli74 closed 2 years ago

chemelli74 commented 2 years ago

Is there a way exclude/include more than 1 attribute ? Like:

  include:
    - domain: binary_sensor
      state: 'on'
      not:
        attributes:
          - device_class: connectivity
          - device_class: plug

If not, can you consider adding it as a feature ?

Thx in advance,

Simone

ildar170975 commented 2 years ago

You may use several filters for one list:

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - domain: sensor
          attributes:
            device_class: temperature
          sort:
            count: 3
        - domain: sensor
          attributes:
            device_class: humidity
          sort:
            count: 3

image

You particular case may be rewritten as:

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - domain: binary_sensor
          state: 'on'
      exclude:
        - attributes:
            device_class: connectivity
        - attributes:
            device_class: plug
chemelli74 commented 2 years ago

You particular case may be rewritten as:

  - type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - domain: binary_sensor
          state: 'on'
      exclude:
        - attributes:
            device_class: connectivity
        - attributes:
            device_class: plug

I would like to exclude only when "on" and not when "off" ;-) This is why I need to filter inside the include and not in the exclude block.

Simone

ildar170975 commented 2 years ago

would like to exclude only when "on" and not when "off" ;-)

I think that my solution does what you need.

chemelli74 commented 2 years ago

would like to exclude only when "on" and not when "off" ;-)

I think that my solution does what you need.

Same card, 2 lists:

I cannot see how your solution can achive this goal. Thx,

Simone

ildar170975 commented 2 years ago

cannot see how your solution can achive this goal

Have you tested my solution?

chemelli74 commented 2 years ago

cannot see how your solution can achive this goal

Have you tested my solution?

I did, but just reading the code I can see that there is no binary_sensor on off mode, which is one of the request.

Simone

ildar170975 commented 2 years ago

I did

Did you get correct results in the output?

It is strange that I am trying to convince you to accept the solution.

chemelli74 commented 2 years ago

I did

Did you get correct results in the output?

No, otherwise I would have a solution ;-)

It is strange that I am trying to convince you to accept the solution.

It is, but I think you didn't get the point.

Let's try to make a full code sample:

type: custom:auto-entities
card:
  type: entities
  title: Active problems
  show_header_toggle: false
  state_color: true
filter:
  include:
    - domain: binary_sensor
      state: 'on'
      not:
        attributes:
          device_class: connectivity
    - domain: binary_sensor
      state: 'off'
      attributes:
        device_class: connectivity
      options:
        style: |
          :host {
            --paper-item-icon-color: var(--paper-item-icon-active-color)
    - domain: binary_sensor
      state: 'off'
      attributes:
        device_class: plug
      options:
        style: |
          :host {
            --paper-item-icon-color: var(--paper-item-icon-active-color)
sort:
  method: state
  reverse: true
  numeric: true

The above is nearly working; still need to exclude binary_sensor with state off and device_class plug

Simone

ildar170975 commented 2 years ago

Your initial intention was this: image

Means - all binary_sensors which are: state = ON device_class = not connectivity and not plug

Let's check this example. You need only yellow entities, right? image

If so, this code gives the same:

type: custom:auto-entities
card:
  type: entities
  title: not
filter:
  include:
    - domain: binary_sensor
      state: 'on'
  exclude:
    - attributes:
        device_class: connectivity
    - attributes:
        device_class: problem
    - attributes:
        device_class: battery_charging
sort:
  method: attribute
  attribute: device_class

Note that here I excluded connectivity, problem & battery_charging just for example (to make a list shorter); I do not have a "plug" sensor. As a result only "none" & "moving" sensors are displayed. All displayed sensors are ON. image

Regarding your code - there are some small errors (not related to the topic): 1) show_header_toggle: false - not needed, the binary_sensor do not have a toggle. 2) numeric: true - not needed for binary_sensor. 3) Closing brackets for card-mod are missing:

style: |
          :host {
            --paper-item-icon-color: var(--paper-item-icon-active-color)
chemelli74 commented 2 years ago

I need also the blue one, otherwise is was so easy that I would not open a issue ;-)

image

Simone

ildar170975 commented 2 years ago

I need also the blue one,

But this is not what was described first: image Initially you asked for a different case, I gave you a code.

OK, here is a code for the new case: 1) Only ON except connectivity & plug. 2) Only OFF which are connectivity or plug.

    type: custom:auto-entities
    card:
      type: entities
    filter:
      include:
        - domain: binary_sensor
          state: 'on'
        - domain: binary_sensor
          state: 'off'
          attributes:
            device_class: connectivity
        - domain: binary_sensor
          state: 'off'
          attributes:
            device_class: plug
      exclude:
        - domain: binary_sensor
          state: 'on'
          attributes:
            device_class: connectivity
        - domain: binary_sensor
          state: 'on'
          attributes:
            device_class: plug
chemelli74 commented 2 years ago

I need also the blue one,

But this is not what was described first: [...] Initially you asked for a different case, I gave you a code.

I better explained in a second comment ;-)

OK, here is a code for the new case:

  1. Only ON except connectivity & plug.
  2. Only OFF which are connectivity or plug.

Thx, will test it asap.

Does include /exclude order makes a difference ? I wrote it with first esclude and then include and was not working.

Simone

ildar170975 commented 2 years ago

I think that order SHOULD not matter

chemelli74 commented 2 years ago

Thx for your help

Simone

ildar170975 commented 2 years ago

Is the code working?

chemelli74 commented 2 years ago

Is the code working?

Yes it is, this is why i closed the issue.

Simone