Entity card - Change values with if-else-endif

Hello,
New to HA and just starting to scratch the service but loving it so far.

I am using Lovelace UI with Hass.io install currently but will migrate to Raspian with Hass.io later. I have been trying to configure an entity card on my UI but was trying to have some of its values dynamically update based on states. I seem to be close but am getting unexpected results. I wanted to see if what I am doing is
a) possible
b) just wrong syntax.

I have my Harmony remote setup and want an entity card that will toggle either turning off the current activity or if everything is off, let you switch on the Watch TV activity. I have started with just trying to update the action_name and name values in the entity. After some searching I have tried a few different formats and these 2 seem to be the closest but with different results each.

This is the most promising from my eyes:

entities:
  - action_name:
      value_template: >-
        {% if is_state('remote.hub', 'off') %} Power On {% else %} Power
        off {% endif %}
    icon: 'mdi:television'
    name:
      value_template: >-
        {% if is_state('remote.hub', 'off') %} Watch TV {% else %} Power
        off {% endif %}
    service: remote.toggle
    service_data:
      activity: Watch TV
      entity_id: remote.mena_hub
    type: call-service
show_header_toggle: true
title: Harmony Remote
type: entities

This gets me a card that shows [object Object] for its name and [OBJECT OBJECT] for the action_name.

I also tried this config but the name and activity name are basically the full string for the if-else-endif

entities:
  - action_name: |
      {% if is_state('remote.hub', 'off') %}
        Power on
      {% else %}
        Power off
      {% endif %}
    icon: 'mdi:television'
    name: |
      {% if is_state('remote.hub', 'off') %}
        Watch TV
      {% else %}
        "Activity: Watching TV"
      {% endif %}
    service: remote.toggle
    service_data:
      activity: Watch TV
      entity_id: remote.mena_hub
    type: call-service
show_header_toggle: true
title: Harmony Remote
type: entities

Any help in the right direction would be appreciated! Thanks!

Not everything can be set with a template. Typically the documentation will say if it can be set via templating. I doubt the items you chose can be set this way.

1 Like

Lovelace does not support templating unless you install this custom card:

1 Like

Thank you both. Figured it may be that it was not supported but always like to verify. Since I got into HA last week Lovelace is the only UI I have used. May need to look into setting up the older style UI.

I wouldn’t. It will be deprecated. Lovelace is the future.

1 Like