Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What about "when" option? #35

Open
darkkatarsis opened this issue Nov 13, 2019 · 10 comments
Open

What about "when" option? #35

darkkatarsis opened this issue Nov 13, 2019 · 10 comments

Comments

@darkkatarsis
Copy link

darkkatarsis commented Nov 13, 2019

In the previous version of the card it was possible to show the entity when it meets the requirements of another status. Is it possible to add such functionality?

example:

         - type: custom:monster-card
            card:
              type: entities
            filter:
              include:
                - entity_id: light.ambilight
                  options:
                    type: "custom:slider-entity-row"
                    toggle: true
            when:
              entity: media_player.samsungtv
              state: 'on'
@ASchneiderBR
Copy link

Hello! Yes, I am also interested on that too. Any workaround for that? Thanks!

@thomasloven
Copy link
Owner

There are better ways to get that functionality.

https://www.home-assistant.io/lovelace/conditional/

@ASchneiderBR
Copy link

Thanks @thomasloven!

I can see the conditional as a great solution.

Sorry to bother you but would mind taking a look at this card? I cannot figure out how make it to work:

- entities:
    - binary_sensor.estado_do_bridge
    - input_boolean.zigbee_permit_join
    - type: conditional
      conditions:
        - entity: input_boolean.zigbee_permit_join
          state: 'on'
      card:
        type: entities
        entities:
          - timer.zigbee_permit_join
  show_header_toggle: false
  title: ZigBee
  type: entities

I get this:

image

Testing just the conditional part on a separated new manual card it works but not like this. I had something similar working before, using the when function.

Thanks a lot!

@darkkatarsis
Copy link
Author

darkkatarsis commented Nov 14, 2019

You cant use conditional card inside entities. For me, this is also not a solution. Conditional card requires that you use it inside a vertical stack card, and there are unnecessary margins that are hard to remove using even card-mod. @thomasloven Please consider reopen

@thomasloven
Copy link
Owner

Yes, you can, with type: custom:hui-conditional-card
https://github.com/thomasloven/hass-config/wiki/Misc-tricks#cardelemententity-row-triality

But I admit the configuration will become pretty involved to get it right.

I'll reconsider.

@thomasloven thomasloven reopened this Nov 14, 2019
@roblandry
Copy link

I had no idea this was possible as i was still using monster-card for this use purpose also. However after reading this, it is working great and i can sunset monster-card.

My working example:

- type: 'custom:hui-conditional-card'
  conditions:
    - entity: input_select.config
      state: Light
  card:
    type: custom:auto-entities
    card: 
      type: entities
      title: Light
    show_empty: true
    unique: true
    sort: 
      method: name
    filter:
      include:
        - domain: light
    entities:
      - entity: light.bathroom
      - entity: light.bathroom_light

@SBado
Copy link

SBado commented Mar 9, 2020

Well, for the time being, here's a small patch. All credits go to rhodges (here his post on Home Assistant communit forum). I'm using it right now and it's working fine, but proper testing is needed:

diff --git a/src/filter.js b/src/filter.js
index 33db425..6d09686 100644
--- a/src/filter.js
+++ b/src/filter.js
@@ -139,6 +139,37 @@ export function entity_filter(hass, filter) {
             break;
           }
 
+        case "when":
+          {
+            for (var i = 0; i < value.length; i++) {
+              var val = value[i];
+              if (val.entity_id) {
+                const whenEntity = hass.states[val.entity_id];
+                if (whenEntity) {
+                  if (val.state) {
+                      if(!match(val.state, whenEntity.state))
+                        return false;
+                  }
+                  if (val.attributes) {
+                    for(const [k, v] of Object.entries(val.attributes)) {
+                      let attr = k.trim();
+                      let entityAttribute = whenEntity.attributes;
+                      while(attr && entityAttribute) {
+                        let step;
+                        [step, attr] = attr.split(":");
+                        entityAttribute = entityAttribute[step];
+                      }
+                      if(entityAttribute === undefined || (v !== undefined && !match(v, entityAttribute)))
+                        return false;
+                      continue;
+                    }
+                  }
+                }
+              }
+                       }
+            break;
+          }
+
         default:
           return false;
       }

Example usage:

  - type: custom:auto-entities    
    card:
      type: entities
      title: Test
      show_header_toggle: false
    filter:
        include:
          - entity_id: input_boolean.alarm_mode
          - entity_id: input_boolean.vacation_mode
          - entity_id: light.back_door_lights
            when:
              - entity_id: input_boolean.alarm_mode
                state: 'on'

In this example, light.back_door_lights will only be visible when input_boolean.alarm_mode is “on”.

@akeslo
Copy link

akeslo commented Jan 4, 2021

Can this be done with conditionals or is this also a use case for the when condition?

I want to show both entities listed but only if the conditions of the first entity are met. Currently, the second entity shows regardless.

Thanks!

image

@SBado
Copy link

SBado commented Jan 12, 2021

PR created (#164).

@bcutter
Copy link

bcutter commented Oct 26, 2022

PR created (#164).

Thanks. Unfortunately it sits and waits like forever.


I also need the option to filter entities based on other entities states. Doing that with the stock conditional card is a pain in the app (😄) and I always wondered why custom:auto-entities can not do this.

E. g.:

                  include:
                    - entity_id: binary_sensor.*firmware_update
                      state: 'on'
                      attributes:
                        device_class: update
                        latest_stable_version: '*'

Task: Now please also show all update entities belonging to those devices (e. g. binary_sensor.device_a_firmware_update has a button.device_a_ota_update which shall be included if the binary_sensor is of state on). They share the friendly_name and entity_id according to a strict naming convention. But I can't make that work with auto-entities.

Simply using this is not working because simply all entities are always shown (no state option available matching the other entities):

                    - entity_id: button.*ota_update
                      attributes:
                        device_class: update

The big improvement would be to show entities based on conditions of other entities (e. g. their states).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants