#Hey - I am trying to change the tap-

1 messages ยท Page 1 of 1 (latest)

shell otter
#

I have updated my logic to this but it still is not working. If I explicitly set the entity it does work

dusty cairn
#

If this is the card you're using, I'll point out that many fields explicitly say that they can support templates, but tap_action is not one of them.

#

you could always create a script (which can contain templates), and then call that script in your tap-action.

velvet flare
#

While tap_action may not technically support templates, it seems like it can. Some example that I've worked with using custom:button-cards yaml tap_action: action: navigate navigation_path: '[[[ return entity.state ]]]'

    variables:
      var_entity: |-
        [[[ 
          var e = states["input_select.navigation_test_variable"].state;
          if (e == "living-room" ) return 'light.living_room_lights';
          else if (e == "kitchen" ) return 'light.kitchen_lights';
          else if (e == "bedroom" ) return 'light.bedroom_lights';
          else return;
        ]]]
    tap_action:
      action: more-info
      entity: '[[[ return variables.var_entity; ]]]'
    double_tap_action:
      action: toggle
      entity: '[[[ return variables.var_entity; ]]]'```
#

Even though Dev Tools template shows that the Jinja is returning the appropriate entity_id, I wonder if its problem is the string outside of the code. What about trying to return: yaml {{ 'start' if states('sensor.qemu_vm_100_status') == 'button.qemu_vm_100_stopped' else 'button.qemu_vm_100_resume' }}

dusty cairn
#

I'm gonna say no tap_action template for this card based on looking at the code. Cards that do js templates are likely very different form this mushroom card which uses HA backend to handle templates.

shell otter
#

Sorry did not see these replies - I ended up using a script using the browser-mod dom events. Just so I can give some form of user feedback via a popup. There is probably a better way but I am yet to find it, doesn't have haptics either now.

#

Will probably have to take a look at some other card types, or doing something myself in JS. But - only just getting started with HA ๐Ÿ™‚

velvet flare
#

It is almost ironic that it seems that the mushroom-template-card cannot template the tap_action...

#

This works for the custom:button-card: yaml type: custom:button-card show_label: true name: Templated tap_action variables: var_entity: | [[[ if (states['input_boolean.tester'].state == 'on') return 'light.bedroom_lights'; else return 'light.living_room_lights' ]]] label: '[[[ return variables.var_entity ]]]' tap_action: action: call-service service: light.toggle target: entity_id: '[[[ return variables.var_entity ]]]'

#

While almost identical code does not work for the mushroom-template-card: yaml type: custom:mushroom-template-card primary: Templated tap_action entity secondary: | {% if states("input_boolean.tester") == 'on' %} light.bedroom_lights {% else %} light.living_room_lights {% endif %} tap_action: action: call-service service: light.toggle target: entity_id: | {% if states("input_boolean.tester") == 'on' %} light.bedroom_lights {% else %} light.living_room_lights {% endif %}