Custom:button-card different action if a entity has specific state

Hi.
I am working with a button.
When I tap it, it should (and it does) set the input_select.zigbee_30_lightning_effects to Slow Colorloop.
But this is what I also want: If input_select.zigbee_30_lightning_effects already is Slow Colorloop* set it to No Effect.

I guess jinja2 don’t work in this card?

type: custom:button-card
name: Slow Colorloop
color_type: card
entity: input_select.zigbee_30_lightning_effects
state:
  - value: Slow Colorloop
    color: yellow
    icon: mdi:checkbox-blank-circle
  - value: Slow Colorloop
    operator: '!='
    color: black
    icon: mdi:checkbox-blank-circle-outline
tap_action:
  action: call-service
  service: input_select.select_option
  service_data:
    entity_id: input_select.zigbee_30_lightning_effects
    option: Slow Colorloop

BONUS QUESTION: “None” as color is setting the default color, but this option is not updating “back to default”, is it another variable that set-back to default when no oher color should apply? I use “black” ass a workaround in my above code

You can template the call-service part:


tap_action:
  action: |
    [[[ 
      if (entity.state == 'Slow Colorloop') return 'none'; 
      return 'call-service'; ]]]
  service: input_select.select_option
  service_data:
    entity_id: …
    option: …

This did not work.

type: custom:button-card
name: Slow<br>Colorloop
color_type: card
entity: input_select.zigbee_30_lightning_effects
state:
  - value: Slow Colorloop
    color: Gold
    icon: mdi:pause
  - value: Slow Colorloop
    operator: '!='
    color: DarkSlateGray
    icon: mdi:play
tap_action:
  action: |
    [[[ 
      if (entity.state == 'Slow Colorloop') return 'none'; 
      return 'call-service'; ]]]
  service: input_select.select_option
  service_data:
    entity_id: input_select.zigbee_30_lightning_effects
    option: Slow Colorloop

Also tried this, but it did not work:

    option: |
      [[[ 
         {% if is_state('input_select.zigbee_30_lightning_effects', 'Slow Colorloop') %}
      No Effect
         {% else %}
      Slow Colorloop
         {% endif %} ]]]

Then please post the data of your input_select entity under Developer Tools → States.

options:
  - No Effect
  - Slow Colorloop
  - Fast Colorloop
  - Flashing Colors
editable: true
friendly_name: zigbee_30_lightning_effects
icon: mdi:lightbulb-group-outline

Looks like mine does. „State“ is the selected effect?


type: custom:button-card
entity: input_select.hue_szenen
name: Szene
show_state: true
tap_action:
  action: |
    [[[ 
      if (entity.state == 'Ibiza I') return 'none'; 
      return 'call-service'; ]]]
  service: input_select.select_option
  service_data:
    entity_id: input_select.hue_szenen
    option: Ibiza I

works like a charm, so I have no clue.

I think you might missunderstand what i am asking.

Lets say the state is “Fast Colorloop” right now.
If i select “Fast Colorloop” again now it will still be “Fast Colorloop”.
But that is not what I want.
I want it to be “No Effect” if “Fast Colorloop” is selected when it already was “Fast Colorloop”

Like: Push button again to stop the running effect.

If the colorloop effect is already running, tapping the button changes to „No Effect“:

tap_action:
  action: |
    [[[ 
      if (entity.state == 'Slow Colorloop') return 'call-service'; 
      return 'none'; ]]]
  service: input_select.select_option
  service_data:
    entity_id: input_select.zigbee_30_lightning_effects
    option: No Effect

[/quote]

Depends on what „No Effect“ does (e.g. turns the light off).

“No Effect” does nothing.

I have a Node-Red flow that is constantly checking “Is state still Slow Colorloop?” If it’s not the flow stops and the effect stops.

God it working :slight_smile:

tap_action:
  action: call-service
  service: input_select.select_option
  service_data:
    entity_id: input_select.zigbee_30_lightning_effects
    option: |
      [[[
        if (entity.state == "Slow Colorloop")
          return "No Effect";
        else
          return "Slow Colorloop";
      ]]]

Glad to hear!