custom-cards / button-card

❇️ Lovelace button-card for home assistant
MIT License
1.83k stars 227 forks source link

Can I template / if else in tap action ? #849

Closed thib5 closed 1 month ago

thib5 commented 1 month ago

Hi i Tried things like that but none work. Am I supposed to be able to do it ? if so how ?


  type: 'custom:button-card'
  entity: automation.mudroom_light_motionday_night
  name: Mudroom Light
  icon: mdi:lightbulb
  state:
    - value: 'on'
      icon: mdi:lightbulb-on
    - value: 'off'
      icon: mdi:lightbulb-off
  tap_action:
    action: call-service
    service: >
      {% if is_state('automation.mudroom_light_motionday_night', 'on') %}
        - service: automation.trigger
          metadata: {}
          data:
            skip_condition: true
          target:
            entity_id: automation.killswitch_mudroom_light_motion
      {% else %}
        - service: automation.turn_on
          metadata: {}
          data: {}
          target:
            entity_id: automation.mudroom_light_motionday_night
      {% endif %}
Mariusthvdb commented 1 month ago

no. not so.

you should use javascript templates (this is jinja)

also, your template output should just be the actual service to call, and not repeat the 'service'.

please move this to the community forum and close here, as this is not a FR or an issue, but a request for help.