šŸ”¹ state-switch - conditional card on steroids

Hi,

I am trying to hide some cards from users, enable it only on admin user. Seems that the user type isnā€™t working as expected. Just to be sure, is the user name is the ā€œusernameā€ or any other id generated?

Thx

entity: user goes by the username, yes.
entity: group selects by admin and not admin, i.e. user.

My username is ā€œeyalā€. The user is ā€œEyalā€. I found out the user is working and not username

1 Like

@thomasloven

I am confused :slight_smile: what is the right one, user (Eyal) or username (eyal)?. I can work with user, no problem, the only thing is that the use can have spaces e.g., ā€˜John Johnā€™

1 Like

Use the one that works.

yaml keys can have spaces too, and if that wouldnā€™t work, quote it

states:
  "Thomas LovƩn":
    ...
  "John John":
    ...

@thomasloven - Is there a way of not showing a card based on the state/user/etc? I can see there is the type markdown, but is there a way of it just being blank?

3 Likes

Hi All,

I do something wrong but donā€™t know what:

No card type found

Here input_select:

system_state_switch:
  name: "Select Technical overview:"
  options:
    - External IP
    - Device Trackers
    - Home Assistant Update

Here code in Lovelace:

  - type: module
    url: /community_plugin/lovelace-state-switch/state-switch.js
cards:
  - type: entities
    entities:
      - input_select.system_state_switch
  - type: 'custom:state-switch'
    entity: input_select.system_state_switch
    states:
      "External IP":
        type: glance
        title: Lights
        entities:
          - light.dressoir_all
      "Device Trackers":
        type: glance
        title: Lights
        entities:
          - light.livingroom_all
      "Home Assistant Update":
        type: glance
        title: Lights
        entities:
          - light.kitchen_all

In the log file I see this line:

2020-01-30 09:56:56 ERROR (MainThread) [frontend.js.latest.202001082] https://192.168.100.24:8123/community_plugin/custom-header/custom-header.js:145:62852 TypeError: undefined is not an object (evaluating 't.tabs[F().current_view].dispatchEvent')

Can someone help me with this :slight_smile:

At the and of the cards added this:

type: vertical-stack

problems solved

Feature Request or is it possible to show some cards and not others on the template.

"{% for state in states.sensor if state.state|int < 8 %} {{ state.entity_id.split('.')[1]}}, {% endfor %}"

I got this string to work ,but only if it returns only one name. If it returns two names it displays no cards.

Iā€™m having a strange problem with this card Iā€™ve never had before. It says itā€™s not installed:

However, I installed it the same way I did all my other working cards, by using HACS, verified HACS had installed it in my www folder, and then putting it in my lovelace.yaml in the same way as all my working cards, see below:

resources:

  - url: /community_plugin/vertical-stack-in-card/vertical-stack-in-card.js
    type: js
  - url: /community_plugin/button-card/button-card.js
    type: module
  - url: /community_plugin/lovelace-card-tools/card-tools.js
    type: module
  - url: /community_plugin/mini-media-player/mini-media-player-bundle.js
    type: module
  - url: /community_plugin/lovelace-layout-card/layout-card.js
    type: module
  - url: /community_plugin/calendar-card/calendar-card.js
    type: js
  - url: /community_plugin/mini-graph-card/mini-graph-card-bundle.js
    type: module
  - url: /community_plugin/lovelace-slider-entity-row/slider-entity-row.js
    type: module
  - url: /community_plugin/secondaryinfo-entity-row/secondaryinfo-entity-row.js
    type: js
  - url: /community_plugin/simple-thermostat/simple-thermostat.js
    type: module
  - url: /community_plugin/air-visual-card/air-visual-card.js
    type: js
  - url: /community_plugin/custom-header/custom-header.js
    type: module
  - url: /community_plugin/lovelace-weather-card-chart/weather-card-chart.js
    type: module
  - url: /community_plugin/lovelace-card-mod/card-mod.js
    type: module
  - url: /community_plugin/lovelace-home-feed-card/lovelace-home-feed-card.js
    type: js
  - url: /community_plugin/search-card/search-card.js
    type: module
  - url: /local/state-switch.js
    type: module

here is my lovelace entry to instantiate the card:

 - type: custom:state-switch
    entity: template
    template: "{% if is_state('input_select.sean_location_dropdown', 'Home')} home {% else %} away {% endif %}"
    states:
      home:

        type: vertical-stack
        cards:

        - type: picture-glance
          aspect_ratio: 16x9
          entities: []
          camera_image: camera.front_stream
          camera_view: live

        - type: horizontal-stack
          cards:

          - type: picture-glance
            aspect_ratio: 9x16
            entities: []
            camera_image: camera.left_stream
            camera_view: live

          - type: picture-glance
            aspect_ratio: 9x16
            entities: []
            camera_image: camera.right_stream
            camera_view: live

        - type: picture-glance
          aspect_ratio: 16x9
          entities: []
          camera_image: camera.back_stream
          camera_view: live


      away:
        type: vertical-stack
        cards:

        - type: picture-glance
          aspect_ratio: 16x9
          entities: []
          camera_image: camera.front_stream

        - type: horizontal-stack
          cards:

          - type: picture-glance
            aspect_ratio: 9x16
            entities: []
            camera_image: camera.left_stream

          - type: picture-glance
            aspect_ratio: 9x16
            entities: []
            camera_image: camera.right_stream

        - type: picture-glance
          aspect_ratio: 16x9
          entities: []
          camera_image: camera.back_stream

I canā€™t for the life of me figure out why this card doesnā€™t work when all my others doā€¦ Is it possibly just not compatible with .105.5?

Oh duh, itā€™s just the folder is wrong for HACS. The right one seems to be

  - url: /community_plugin/lovelace-state-switch/state-switch.js
    type: module

Card still isnā€™t working but I think I have some other syntax errors in there.

1 Like

Thereā€™s a troubleshooting guide in the install instructions linked from the readme.

Working now, thanks!

found anything on this? Thanks

hi, thanks for great card.
I am trying to use this in long vertical stack. by using three buttons would like to scroll down the page at a specific place! at the same time in the default would like to leave all cards visible. short of like anchors.

is this possible to achieve?

hi,

question, i am reverting my conditional cards to state-switch cardsā€¦

but the variables doesnt work anymore like i wanted :frowning:

this worked before:

- name: "Calendar: [[[return ${states[ā€˜sensor.calendar_fabio_vanessaā€™].state}]]]"
now i need to remove the ā€˜Calendar:ā€™ word,
so its like
- name: "[[[return ${states[ā€˜sensor.calendar_fabio_vanessaā€™].state}]]]"

how can i define a fixed word before that state
it worked before on conditional card

thxn a lot

  - type: custom:state-switch
    entity: template
    template: "{% if not is_state('sensor.calendar_fabio_vanessa', 'off') %} on  {% endif %}"
    states:
      "on":
        type: horizontal-stack
        cards:
          - !include ../includes/blank-card.yaml    
          - type: custom:decluttering-card
            template: notification
            variables:
              - card_color: rgba(0, 221, 255, 0.5)
              - icon: calendar
              - name: "[[[return `${states['sensor.calendar_fabio_vanessa'].state}`]]]"
          - !include ../includes/blank-card.yaml

Also another question:

I have some buttons I want to displayā€¦
Before with conditional cards, when I didnā€™t want to show (hide a button) the next button would be on the exact same spaceā€¦

With this card, if I have for example 10 state switches, and 2 of them are true, letā€™s say the first and the last, I have like 8 extra spaces/rowsā€¦

Normally the second buttons should be right under the first buttonā€¦ But now every card that is hidden ( no state) seems.its creating somekind of whitespacesā€¦

Hard to explain what I mean

example screenshot:

state-switch

Iā€™ve got the exact same issue with conditionally non-displayed cards, albeit horizontally (stacked):

are you sure your cards were there correctly before? I feared it to be related to the horizontal-stack card.
Eg entities cards with conditional cards as entities donā€™t suffer this behavior.

yeah, with condinional cards, there was no space/gap between cards ā€¦ now its filling up with spaces, they all shift some pixels to below
the more cards are invisible between 2 visible cards, the more the second one shift to beow

i see this PR, allthought it didnt fix my issue