#entity progress card - hiding elements with jinja

1 messages · Page 1 of 1 (latest)

coral glade
#

I'm trying to tweak a custom card, entity progress card, and I'm strugling wiht the hide: block. I put in
hide: >-
{% if is_state('switch.shelly_1pm_gen4_2', 'on') %}
{% if is_state('sensor.contraband_generator_current_print_state', ['printing', 'error', 'paused']) %}
['value']
{% else %}
['progress_bar', 'value']
{% endif %}
{% endif %}

its just not hiding things and the docs show it can take jinja here

#

@ember night you got any ideas?

coral glade
#

If you are curious, this is the incomplete card I have so far...

type: custom:entity-progress-card
entity: sensor.contraband_generator_progress
custom_info: |-
  {% if is_state('switch.shelly_1pm_gen4_2', 'off') %}
    off
  {% elif is_state('switch.shelly_1pm_gen4_2', 'on') %}
    {% if is_state('sensor.contraband_generator_current_print_state', ['standby', 'complete', 'cancelled',  'paused', 'error']) %}
      {{states('sensor.contraband_generator_current_print_state')}}
    {% elif is_state('sensor.contraband_generator_current_print_state', 'printing') %}
      printing - {{states('sensor.contraband_generator_print_time_left')}} remaining
    {% else %}
      booting...
    {% endif %}
  {% endif %}
visibility:
  - condition: user
    users:
      - 7694ac5312e9450a9c03867fe644b34f
icon: mdi:printer-3d
layout: horizontal
name: Contraband Generator
hold_action:
  action: perform-action
  perform_action: switch.turn_off
  target:
    device_id: 8cf5d9974d9e3c0f3bcc8329fffe8d1a
  data: {}
tap_action:
  action: perform-action
  perform_action: switch.turn_on
  target:
    device_id: 8cf5d9974d9e3c0f3bcc8329fffe8d1a
  data: {}
double_tap_action:
  action: none
icon_tap_action:
  action: perform-action
  perform_action: switch.turn_on
  target:
    device_id: 8cf5d9974d9e3c0f3bcc8329fffe8d1a
  data: {}
icon_hold_action:
  action: perform-action
  perform_action: switch.turn_off
  target:
    device_id: 8cf5d9974d9e3c0f3bcc8329fffe8d1a
  data: {}
icon_double_tap_action:
  action: none
hide: |-
  {% if is_state('switch.shelly_1pm_gen4_2', 'on') %}
    {% if is_state('sensor.contraband_generator_current_print_state', ['printing', 'error', 'paused']) %}
      ['value']
    {% else %}
      ['progress_bar', 'value']
    {% endif %}
  {% endif %}
disable_unit: true
grid_options:
  columns: full

ember night
#

Without digging into it too much, I'd suggest dropping the template into Dev Tools and see what it returns.
I'll play with it later tonight after I get off work.

ember night
#

TL,DR: To me, it seems like the hide section is not evaluating templates.
I played with this a little bit last night. I noticed that hide: ['progress_bar', 'value'] worked fine. I dropped the template into Dev Tools and it returned what was expected. The only thing that I noticed is the state is case sensitive and the sensor that I was using was shown in Proper case rather than lowercase but that is just a normal templating thing. I tried using the template version of the card (custom:entity-progress-card-template). Simplifying the template didn't seem to help. I focused on just trying to get it to accept a single value rather than a list. This didn't work: hide: "{% if true %}progress_bar{% endif %}" where hide: progress_bar does. Interestingly, name: hide: "{% if true %}progress_bar{% endif %}" works just fine.

#
type: custom:entity-progress-card-template
entity: sensor.p1s_alpha_print_progress
hide: "{% if true %}progress_bar{% endif %}"
name: "{% if true %}progress_bar{% endif %}"
#

I looked through the doc trying to find examples of using hide: and there wasn't really anything useful and no examples of using a template with hide. At this point, the only thing that I can think of is the hide section is not evaluating templates. You might consider opening an issue and see what the Dev says.

coral glade
#

from what I can get from the dev chat, hide supports templates, progress_bar does not. so while it can be hidden via hide:, it cant be via a template in hide? Anyway, dev is adding the feature.

ember night
#

That's ironic that I was using the progress bar for testing, but that doesn't work. I'll go back and try again with another field.

ember night
#

Not sure how I missed it before, but templating hide: is not supported. (Look in the Entity Progress Card Template section and expand Available Jinja Options.) That could explain why we've had issues trying to get it to work. Until it is supported, I came up with a workaround using card_mod that should do what you want. This works with the regular card and the template version.

#
type: custom:entity-progress-card
entity: sensor.p1s_alpha_print_progress
icon: mdi:printer-3d
card_mod:
  style: |
    {% if is_state('switch.p1s_alpha_smart_plug', 'on') %}
      {% if is_state('sensor.p1s_alpha_print_status', ['printing', 'error', 'paused']) %}
        .secondary-info-detail-group { display: none !important }
      {% else %}
        .state-and-progress-info { display: none !important }
        .progress-bar-container { display: none }
      {% endif %}
    {% endif %}
#

The secondary-info is a container that holds the secondary line. If you hide that, the entire line is hidden and the primary line gets centered vertically in the card. If you hide the secondary-info-detail-group and the progress-bar-container, the secondary line also disappears. Depending on the look are trying to achieve, you can target different sections and hide them accordingly.