🔹 state-switch - conditional card on steroids

When I use this inside an entities card I lose the formatting as a toggle switch. Anyway to keep that formatting?

Before:
image
After:
image

- type: custom:state-switch
  entity: switch.rachio_toggle_drip_schedule
  states:
    'on':
      type: entity
      entity: switch.rachio_toggle_drip_schedule
    'off':
      type: entity
      entity: switch.rachio_toggle_drip_schedule

Because this is a CARD.
Do you need a row?
Encapsulate it in hui-element card.

I was attempting to do that but guess I just don’t have the formatting of it correct as of yet.

Hey guys,

Started using this card and loving it. Just wondering if there’s an easy way to show the same cards for multiple states. i.e. for a media player state, I want the same cards to show whether the state is “on”, “playing”, “paused”, but different cards for “idle” and “off” (I think).

Is there a way to have the same cards show for on, paused and playing, but not for off and idle?

My current work around is to have just “playing” and “off” as the specified state cards, and the default set as “playing”, so that if the state is actually “paused” it still shows the “playing” cards.

The alternative I guess is to make a template binary sensor based on the states and reference that instead of the media player.

Is that the best option?

It’s the approach I use for a similar scenario, and it works for me.

Try using template option

1 Like

Of course! Sorry I missed that. However, this note intrigues me:

Note: Jinja2 templating is not cheap. Avoid it for simple things that can be solved with just an entity.

Does that mean that setting up a separate entity (here a binary sensor) is ‘cheaper’ than using a Jinja2 template directly in the frontend?

IMHO jinjia2 operates on a server side only.

The meaning if that note was:
instead of:

entity: "{{is_state('sun.sun','below_horizon')}}"
states:
  true:
    type: markdown
    content: ...
  false:
    type: markdown
    content: ...

use this:

entity: sun.sun
states:
  'below_horizon':
    type: markdown
    content: ...
  'above_horizon':
    type: markdown
    content: ...

Yep, totally missed that as well. I knew there was a better way. Thanks dude. Will give it a go!

This seems like a question for the browser-mod thread.

I want to have multiple !include statements, but they get concatinated rather than processed in series. Thoughts about fixes or workarounds?

This works:

  - type: custom:state-switch
    entity: input_select.remote
    states:
      'DISH':
        !include remote_dish.yaml
      'FireTV':
        !include remote_firetv.yaml
      'RADIO':
        !include remote_radio.yaml
      'VCR2':
        !include remote_off.yaml

But this raises an error:
No such file or directory: '/config/lovelace/media/remote_sources.yaml !include remote_dish.yaml'
Adding a newline between the !includes raises the same error.

  - type: custom:state-switch
    entity: input_select.remote
    states:
      'DISH':
        !include remote_sources.yaml
        !include remote_dish.yaml
      'FireTV':
        !include remote_firetv.yaml
      'RADIO':
        !include remote_radio.yaml
      'VCR2':
        !include remote_off.yaml

Btw, I believed that it should be this:

    states:
      'DISH': !include remote_dish.yaml

Thanks, but this works:

    states:
      'DISH':
        !include remote_dish.yaml

This does not:

    states:
      'DISH':
        !include remote_sources.yaml
        !include remote_dish.yaml

The parser concatenates both lines (two file names) into one line (one file name), as in a “>” markup.

I have been trying to get this card working but no matter what I have done, I don’t get the options to show up. I’ve uninstalled and reinstalled the repository and cleared the cache and cookies but nothing has changed. I’ve tried very basic setups and nothing is showing up so maybe the code is bad? Does it need to be in another card to work?

type: custom:state-switch
entity: input_select.test_mode_select
default: Test1
states:
  Test1:
    type: vertical-stack
    cards:
      - type: entities
        title: one
        entities:
          - entity: light.3d_light
  Test2:
    type: vertical-stack
    cards:
      - type: entities
        title: two
        entities:
          - entity: light.3d_light

Make sure that your input_select is set to either Test1, or Test2. (Look at Developer > States for the input_select’s current State).

It seems to be. The Test1 card option displays but I don’t have a place to choose it or Test2.

What?
Just place your input_select entity on the same view and see possible options.

@thomasloven I really love this card. Can you share the code for the example you give with the button presses change the view. Do you use an input boolean to accomplish this or what?

Be careful of tagging people out of the blue. It comes across as demanding.

I am not begging for help I just want to get the code to see if I can get it to work properly. I know its not a forum I understand that I was just curious if the maker of the card is willing to elaborate more on the code structure. I am just wanting to try to use a card in an advanced way and wanting to see if it is possible.