piitaya / lovelace-mushroom

Build a beautiful Home Assistant dashboard easily
Apache License 2.0
3.52k stars 329 forks source link

More options for conditional chips #154

Closed kineticscreen closed 9 months ago

kineticscreen commented 2 years ago

Would be good to have some more options for Conditional Chips - i.e. < > <! !>

Is / is not works for lights and switches, but not for sensors.

piitaya commented 2 years ago

As a workaround for now, your can define a binary_sensor with template and use it in your condition 🙂

kineticscreen commented 2 years ago

That's... quite clever.

KrX3D commented 2 years ago

Hi, i would also like to use within the conditional chip a custom card

i.e.

i use this card on my dashboard:


type: conditional
conditions:
  - entity: sensor.seventeentrack_packages_in_transit
    state_not: '0'
card:
  type: custom:seventeen-track-card
  entity: sensor.seventeentrack_packages_in_transit
  title: Unterwegs
  location: false`

but:

`type: custom:mushroom-chips-card
chips:
  - type: conditional
    conditions:
      - entity: sensor.seventeentrack_packages_in_transit
        state_not: '0'
    chip:
      type: custom:seventeen-track-card
      entity: sensor.seventeentrack_packages_in_transit
      title: Unterwegs
      location: false
`

doesnt show anything
janstadt commented 2 years ago

Trying to think of a way to template out a conditional chip that displays whether or not the current user is a specific person. Would anyone be able to show me how to template out an is_user binary_sensor using the {{user}} variable? I tried this but it didnt work:

template:
  - binary_sensor:
      - name: "is_jake"
        state: "{%if user === 'Jake' %}on{%else %}off{%endif %}"
davidcoulson commented 2 years ago

Use this card instead?

https://github.com/thomasloven/lovelace-state-switch

janstadt commented 2 years ago

Use this card instead?

https://github.com/thomasloven/lovelace-state-switch

Thanks for the reply @davidcoulson. Im just trying to implement what @piitaya mentioned above for my specific use case.

janstadt commented 2 years ago

I tried doing a conditional chip but the alignment was all out of wack. Ended up with this which is more verbose but works. Leaving it here in case anyone else needs an example:

type: custom:state-switch
entity: user
default: default
states:
  Jake:
    type: custom:mushroom-chips-card
    chips:
      - type: weather
        entity: weather.home
        show_conditions: true
        show_temperature: true
      - type: alarm-control-panel
        entity: alarm_control_panel.ha_alarm
      - type: entity
        entity: sensor.exchange_rate_1_btc
        icon: mdi:bitcoin
        icon_color: orange
    alignment: center
  default:
    type: custom:mushroom-chips-card
    chips:
      - type: weather
        entity: weather.home
        show_conditions: true
        show_temperature: true
      - type: alarm-control-panel
        entity: alarm_control_panel.ha_alarm
    alignment: center
piitaya commented 2 years ago

Thanks for sharing. The only solution is to create a condition template chip. We works on other cards for now but that something we can consider 😉 Templates are not user friendly but allow maximum flexibility. Building a condition builder in the UI will be to complicated.

marcusforsberg commented 2 years ago

The only solution is to create a condition template chip. We works on other cards for now but that something we can consider 😉

This would be absolutely awesome to be able to create advanced conditionals without resorting to binary sensors. I think it would be fine without a UI for more advanced users. 😊

SaSa1983 commented 1 year ago

Thanks for sharing. The only solution is to create a condition template chip. We works on other cards for now but that something we can consider 😉 Templates are not user friendly but allow maximum flexibility. Building a condition builder in the UI will be to complicated.

Actually there's no need to build a complex editor:

Currently you can add multiple (and connected) conditions based on entities. You only need to add a "select" for condition type:

diginfo commented 1 year ago

Would it be possible to use the state or attribute of a sensor as the condition:

      - type: conditional
        conditions:
          - entity: sensor.battery_device_a
            operator: "<"
            state: {{ input_number.low_batt_level  }}

I want to show devices where the battery level is less than a input_number slider

orimate commented 1 year ago

Hello I tried to make a conditional chip with extended conditions. Example "state" >=1000 chip shows up with color orange, if "state" >=1800 icon is changing to red, under 1000 chips has nothing to show. Is there any update in this direction? (chip template)

orimate commented 1 year ago

Now It works as I want, but a conditional template with operators would be really nice.

_My config would be better if sensor (sensor.netatmo_co2_indoor_mainunit0) would be declared as a variable over all. Thanks @piitaya, It is now updated. However in Style {% if states(entity)|float >= 1000 %} does not work but so {% if states('sensor.netatmo_co2_indoor_mainunit_0')|float >= 1000 %} is OK.

type: custom:mushroom-chips-card
chips:
  - type: template      
    entity: sensor.netatmo_co2_indoor_mainunit_0
    icon: |-          
      {% if states(entity) | float >= 1000 %}
      mdi:molecule-co2 
      {% else %}

      {% endif %}
    icon_color: |-
      {% if states(entity) | float >= 1800 %}
      #ff471a
      {% elif states(entity) | float >= 1000 %}
      #ff9900
      {% else %}

      {% endif %}
    content: |-
      {% if states(entity) | float >= 1000 %}
      {{ states(entity) | int }} ppm
      {% else %}

      {% endif %} 
    card_mod:
      style: |-
        {% if states('sensor.netatmo_co2_indoor_mainunit_0') | float >= 1000 %}
        ha-card {

        }
        {% else %}
        ha-card {
          --chip-box-shadow: none;
          --chip-background: none;                
        }
        {% endif %} 
piitaya commented 1 year ago

@orimate You can use entity variable (https://github.com/piitaya/lovelace-mushroom/blob/main/docs/cards/template.md#description) :

- type: template
  entity: sensor.netatmo_co2_indoor_mainunit_0
  icon: |-         
    {% if states(entity) | float >= 1000 %}
    mdi:molecule-co2
    {% else %}

    {% endif %}
piitaya commented 1 year ago

For now, there is no way to use template in condition because there is performance issue with template so I prefer to keep template for template card and template chip which are more advanced chips.

The workaround to do this is to write a binary_sensor with the condition you want so it can be easily reused in automations too.

MDausch commented 11 months ago

I had poked around with this locally, and have been running a totally hacked together implementation for a while. I have it set up such that if the template returns 1, the desired chip shows, otherwise it will be hidden. Essentially just an inline binary_sensor.

This was really nice for quick one offs that I hadn't wanted to make a new template sensor for, but now that we have the ability to define template helpers in the gui I had started converting my conditions to them. Maybe there are some other nice to haves that others can think of that would make this a more appealing option still?

piitaya commented 10 months ago

🚨 Spoiler alert 🚨

It's introduced with this PR https://github.com/piitaya/lovelace-mushroom/pull/1269. It will be available with 2023.11 Home Assistant release and 3.2.0 Mushroom release.

CleanShot 2023-10-25 at 16 21 53

KrX3D commented 7 months ago

hi, is there any plan to use for chip the type card?

like i mentioned above, i would like to use a custom card