piitaya / lovelace-mushroom

Build a beautiful Home Assistant dashboard easily
Apache License 2.0
3.52k stars 329 forks source link

[Bug]: Call Service Templating #1296

Closed joaopedros2 closed 9 months ago

joaopedros2 commented 9 months ago

Requirements

Current Behavior

Is it possible to use the template in call services? I'd like to be able to switch the fan positions when I toggle the button. In the developer tools \ services of Home Assistant, it works perfectly. I tested it this way and it doesn't work.

type: custom:mushroom-chips-card
chips:
  - type: template
    entity: fan.dehu_guilherme_fan
    icon: |-
      {% if 'Low' in state_attr(entity, 'preset_mode') %}
        mdi:fan-speed-1
      {% elif 'Medium' in state_attr(entity, 'preset_mode') %}
        mdi:fan-speed-2
      {% else %}
        mdi:fan-speed-3
      {% endif %}
    icon_color: green
    tap_action:
      action: call-service
      service: fan.set_preset_mode
      target:
        entity_id: fan.dehu_guilherme_fan
      data:
        preset_mode: |-
          {% if 'Low' in state_attr('fan.dehu_guilherme_fan', 'preset_mode') %}
            Medium
          {% elif 'Medium' in state_attr('fan.dehu_guilherme_fan', 'preset_mode') %}
            High
          {% else %}
            Low
          {% endif %}
    double_tap_action:
      action: none
    hold_action:
      action: more-info
piitaya commented 9 months ago

There are closed issues about this feature (e.g https://github.com/piitaya/lovelace-mushroom/issues/895). The actions are not part of Mushroom but HA UI and it don't allow templating. I suggested you to create a script for that.