Tap_action service_data option IF_ELSE custom card conditional problem

Super Simple!!.
I want to change the state of a service from ‘1’ to ‘2’ or viceversa when I tap the icon.

The code is:

type: custom:mushroom-template-card
primary: Level
secondary: ''
icon: mdi:home
tap_action:
  action: call-service
  service: select.select_option
  service_data:
    option: |
      {% if is_state('select.calefactor_jose_temperature_level', '1') %}
      '2'
      {% else %}
      '1'
      {% endif %}
  target:
    entity_id: select.calefactor_jose_temperature_level

But I get the mensage:

Failed to call service select/selection_option. Option {% if is_state(‘select.calefactor_jose_temperature_level’, ‘1’) %} ‘2’ {% else %} ‘1’ {% endif %} not valid for Smart Heater Jose Temperature Level

I been craking my head to fix this and I cant find any thing.

You can’t template in dashboards

With few exceptions core dashboard cards don’t support templating.

Put the template in a script and call that as the tap action.

Thanks.
Can you explain how to do that… I new and scare jajajaj

neither in custom cards?

Depends on the card. Some do. Some don’t.

Scripts are just sequences of actions. Like an automation without a trigger.

Plenty of documentation and examples available.

1 Like