Call-service conditional

Hi, I have the following card, the icon and content section works fine, but when I try to execute the call service (conditional based on the status of sensor) the system said that service doesn’t exist.

Please Help :wink:

Failed to call service {% if is_state(‘binary_sensor/doorbell_streaming_sensor’, ‘False’) %} 'camera. Unable to find service {% if is_state(‘binary_sensor.doorbell_streaming_sensor’, ‘false’) %} 'camera

  - type: custom:mushroom-chips-card
      - type: template
        entity: binary_sensor
        icon: |
          {% if is_state('binary_sensor.doorbell_streaming_sensor', 'False') %}
          {% else %} 
          {% endif %}
        content: |
          {% if is_state('binary_sensor.doorbell_streaming_sensor', 'False') %}
            Play Video
          {% else %} 
            Parar Video
          {% endif %} 
          action: call-service
          service: |
            {% if is_state('binary_sensor.doorbell_streaming_sensor', 'False')%}  
            {% else %}
            {% endif %}
            entity_id: camera.doorbell

The doc for the mushroom template card is here. Notice that it lists all the fields which support templates and tap_action is not one of them.

In the UI unless something explicitly says that it supports templates the assumption is that it doesn’t.

1 Like

Thanks, I will use then another different way, only when the sensor is active, show the button…

  - type: conditional
      - entity: binary_sensor.doorbell_streaming_sensor
        state: 'True'
      type: custom:mushroom-chips-card
        - type: template
          entity: binary_sensor
          icon: mdi:stop
          icon_color: green
          content: Stop Video
            action: call-service
            service: camera.turn_off
              entity_id: camera.doorbell
1 Like

Another way to handle this is to have the tap action fire a script and build the conditional logic into the script.


You are certainly not the first nor last person who would like templates in actions. I would suggest posting a desire to such for the author of this. I have resorted to using custom:state-switch for many things mushroom because of this. My old code using custom:button-card to now use custom:mushroom-template has “mushroomed” to 3x the size it use to be and it is nearly unmanagable. I will likely remove all mushroom setup because of this and a few other “non-templatable” fields. IMHO custom:button is far superior with the ability to build and reuse chunks of YAML within many other parts (instead of repeating them over and over).

1 Like

@jalejandro0211 ,
Did you ever figure out a way to work this? I’m running into a similar issue. I started another thread, but I’m not making much headway.

Mike’s response would seem to indicate what I’m trying to do isn’t possible. My issue stems from the fact that there is a new device class for window coverings, and Home Assistant hasn’t fully caught up with this device class.

Not, I’m sorry. I didn’t

I now almost exclusively use decluttering

This card?

Yes. Most of my dashboards use decluttering where you can pass in variables.
Good example starts here:

So that one decluttering template displays stats for the NFL standings by Division (8 cards), by Conference (2 cards) and Overall (1 card).

Now if the card in question did have tap-action, etc. you could pass in variables to execute the action. LIke this template which can call a service with the “mediaplayer” passed in as a variable:

      type: custom:mushroom-media-player-card
        action: call-service
        service: media_player.toggle
          entity_id: '[[mediaplayer]]'
      entity: '[[mediaplayer]]'
      layout: horizontal
      fill-container: true
      show_volume_level: true
      collapsible_controls: false
      use_media_info: true
        - volume_set
          mushroom-shape-icon$: |
            .shape {
              perspective: 7px;
          .: |
            ha-state-icon {
              {% if is_state(config.entity,'on') %}
                animation: music 2s ease-in-out infinite alternate;
                transform-origin: 50% 100%
              {% endif %}
            @keyframes music {
              0%, 100% { transform: translateY(0px) scaleX(1); }
              20% { transform: translateY(2px) scaleX(0.9); }
              40% { transform: rotateY(10deg) rotateZ(-10deg); }
              60% { transform: translateY(-4px) scaleX(1.1); }
              80% { transform: rotateY(-10deg) rotateZ(10deg); }

Now of course how does this help you? Well you can templatize the construction. In the above case, this uses auto-entities to build a whole set of cards that are my media zones:

      - type: custom:stack-in-card
          grid-area: col2
        mode: vertical
          - type: custom:auto-entities
              type: vertical-stack
              show_header_toggle: false
              state_color: true
              square: false
              title: Music Zones
            card_param: cards
              template: >
                {% for MEDIAPLAYER in states.media_player |
                selectattr("entity_id","in",integration_entities("xantech")) -%}
                  {% set SELECTZONE = "input_select.dax_source_" + (MEDIAPLAYER.entity_id).split("xantech8_")[1]
                  {% if MEDIAPLAYER.entity_id != "media_player.xantech8_xantech_house_audio"
                        'type': 'custom:layout-card',
                        'layout_type': 'custom:grid-layout',
                        'layout': {
                          'max_cols': 3,
                          'grid-template-columns': 'auto 150px'
                        'cards': [
                          'type': 'custom:decluttering-card',
                          'template': 'mediaplayer',
                          'variables': [
                             'mediaplayer': MEDIAPLAYER.entity_id
                            "type": "custom:mushroom-select-card",
                            "entity": SELECTZONE,
                            "name": "Set Zone Sources",
                            "layout": "horizontal",
                            "icon_type": "none",
                            "primary_info": "none",
                            "secondary_info": "none",
                            "card_mod": {"style": "ha-card {box-shadow:  none;}"}
                  {%- endif %}
                {%- endfor %}

What does it look like?

All the zones, volume controls and click the mushrooms are built from those templates.

1 Like