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

More options for conditional chips #154

Closed
kineticscreen opened this issue Feb 24, 2022 · 18 comments
Closed

More options for conditional chips #154

kineticscreen opened this issue Feb 24, 2022 · 18 comments
Labels
enhancement New feature or request

Comments

@kineticscreen
Copy link

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.

@kineticscreen kineticscreen added the enhancement New feature or request label Feb 24, 2022
@piitaya
Copy link
Owner

piitaya commented Feb 25, 2022

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

@kineticscreen
Copy link
Author

That's... quite clever.

@KrX3D
Copy link

KrX3D commented Apr 9, 2022

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
Copy link

janstadt commented Apr 10, 2022

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
Copy link

Use this card instead?

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

@janstadt
Copy link

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
Copy link

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
Copy link
Owner

piitaya commented Apr 10, 2022

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
Copy link

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
Copy link

SaSa1983 commented Jan 27, 2023

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:

  • Entity: should be the default in order for "migration" and displays the current input fields
  • Template: hides the entity input fields ans shows a single "text" input allowing to input template syntax, whereas the expression must evaluate to boolean, e.g. "{{expand(states.update) | selectattr('state', 'eq', 'on') | list | length > 0}}" to know if any update is available

@diginfo
Copy link

diginfo commented Apr 10, 2023

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
Copy link

orimate commented Aug 30, 2023

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
Copy link

orimate commented Aug 30, 2023

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_mainunit_0) 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
Copy link
Owner

piitaya commented Aug 30, 2023

@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
Copy link
Owner

piitaya commented Aug 30, 2023

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
Copy link

MDausch commented Oct 8, 2023

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
Copy link
Owner

piitaya commented Oct 25, 2023

🚨 Spoiler alert 🚨

It's introduced with this PR #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

@piitaya piitaya closed this as completed Dec 4, 2023
@KrX3D
Copy link

KrX3D commented Jan 29, 2024

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

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

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

No branches or pull requests

10 participants