thomasloven / lovelace-template-entity-row

🔹 Display whatever you want in an entities card row.
MIT License
210 stars 16 forks source link

Conditional Tap Action #26

Closed dudu631 closed 3 years ago

dudu631 commented 4 years ago

Is it possible to template the tap action, in order to only enable it on a certain state?

Example:

 tap_action: |-
      {% if is_state('media_player.tv_samsung', 'on')%}  
        action: call-service
        confirmation: 
            text: Turn off TV? 
        service: media_player.turn_off
        service_data: 
            entity_id: media_player.tv_samsung 
      {% endif %}

Or something like that?

jschonenberg commented 3 years ago

Seconded, but for a different use case:

...
 include:
    - domain: timer
      entity_id: /chore/
      options:
        tap_action:
          action: call-service
          service: timer.start
          service_data:
            entity_id: "{{ config.entity }}"
...

Edit: I found that my request is possible when using: https://github.com/thomasloven/lovelace-auto-entities

As follows:

type: 'custom:auto-entities'
card:
  type: entities
filter:
  include:
    - domain: timer
      entity_id: /chore/
      options:
        tap_action:
          action: call-service
          service: timer.start
          service_data:
            entity_id: 'this.entity_id'
thomasloven commented 3 years ago

Added in 1.3.0. The actions need to be python formated if templates. See readme.