🔹 state-switch - conditional card on steroids

And state_not: 'unavailabe" ?

I’ve got a sensor with this template working fine to show or hide a conditional card:

         {{ state_attr('sensor.trakt_next_to_watch_all', 'data')
            | map(attribute='title')| map('lower') | select('eq', 'parks and recreation')
            | list | count > 0 }}

I was hoping that I could put this template directly in a state-switch card so I wouldn’t have to make all the extra sensors.

This doesn’t seem to be working. Am I doing something wrong?

type: custom:state-switch
entity: template
template: |
          {{ state_attr('sensor.trakt_next_to_watch_all', 'data')
            | map(attribute='title')| map('lower') | select('eq', 'parks and recreation')
            | list | count > 0 }}
states:
  'True':
    type: custom:button-card
    template: serie2
    name: Fallout
    tap_action:
      action: call-service
      service: script.fallout
    entity_picture: >-
      https://walter.trakt.tv/images/shows/000/163/965/posters/thumb/048a739d1e.jpg.webp

EDIT:
My bad! Switching states to ‘true’ instead of ‘True’ did the trick

I tried the following ways but none of them work:

state_not: "unavailable"
state_not: unavailable
state_not: "Non disponibile"
state_not: Non disponibile

The card is ALWAYS displayed:

It doesn’t work like this either:

in this way, however, I can hide the contents of the card:

But I would like to hide the card completely if the sensor is “unavailable”

Did you actually check it outside of the editing mode? Conditional card editor does not update the preview based on whether the condition is currently true or not. You can try either clicking 3 dots and selecting test, or just save it and go out of dashboard editing mode. For whatever reason it works different with the entities conditional row, where the preview immediately changes depending on condition. It does make sense if you think about it.

Also by the way, the conditional card accepts lists in the state or state_not variables, so you can specify multiple states too.

I think I’ve found a bug, but it’s my first use of state switch so not certain.

Essentially state-switch itself is working perfectly. But any button I put inside it (standard or custom:button-card) fails to do anything.

My use case is below. These buttons work outside of state-switch with no code change.

*** update… user error :man_facepalming: ***

I try to make a test with state-switch and custom:button-card with transition, but not working as I expected.

When I press button test1 button 2 slide-down and I can see button only until transition finishes, after that button dissapears.

When I press button test2 button 1 slide-down and I can see button only until transition finishes, after that button dissapears.

What I am doing wrong?

Here is my test code:

type: vertical-stack
cards:
  - type: custom:state-switch
    entity: hash
    default: none
    states:
      p1:
        type: custom:button-card
        name: button 1
      p2:
        type: custom:button-card
        name: button 2
      none:
        type: custom:button-card
        name: test
  - type: custom:state-switch
    entity: hash
    default: p2
    states:
      p1:
        type: custom:button-card
        name: button 1
      p2:
        type: custom:button-card
        name: button 2
      none:
        type: custom:button-card
        name: test
    transition: slide-down
  - type: horizontal-stack
    cards:
      - type: custom:button-card
        name: test1
        tap_action:
          action: navigate
          navigation_path: '#p1'
      - type: custom:button-card
        name: test2
        tap_action:
          action: navigate
          navigation_path: '#p2'

state-switch-error

The latest HA build seem to have broken the user/group functionality. I had it set to group admin and it is no longer visible for admins.

OK, I did some more debugging and it appears that the first request does not have the correct status for user and/or group sent. Once i hit refresh the correct card populates. Unfortunately you can’t hit refresh on the mobile app so the correct cards never load on the mobile app because of this.

I’m using the state-switch card to show different entities to different users, but I want to show the same thing in case of 2 users without having to repeat the whole card definition as well. Is this possible?

Google about yaml-anchors. Work only in yaml-mode-dashboards. If you use a storage-mode-dashboard - you cannot use yaml-anchors. In general, most of ways of reusing code only work in yaml-mode-dashboards.

Hmm this is the second time today that comes up when I’m searching for solutions for my dashboard, guess that’s a sign. People say it makes editing harder, I’m guessing because you lose the live visual preview? Can’t one just have a dev dashboard for working on stuff before moving it over? …I’ll read up, thanks.

Storage mode is mainly for beginners or people who cannot program / do not want to learn programming.
Many people use storage mode for testing and yaml mode for a final code.

That’s a pretty good solution to help you transition. Admittedly the UI Dashboard editor does create a fair chunk of non-essential (default settings) YAML from time to time, but it can help you understand how everything fits together and can help you to prototype something before moving it over to
pure YAML

Yes that’s exactly what I’m doing now, I’ve transitioned our main dashboard to YAML mode, and still using storage mode for quick prototyping. I don’t see myself getting rid of the storage mode for that reason alone.