iantrich / config-template-card

📝 Templatable Lovelace Configurations
MIT License
441 stars 56 forks source link

Something related to `not available` state in templates #9

Closed notabene00 closed 5 years ago

notabene00 commented 5 years ago

I have something like this:

show_header_toggle: false
type: 'custom:hui-entities-card'
entities:
  - name: Ceiling
    secondary_info: last-changed
    entity: switch.ceiling_bedroom
  - icon: >-
      ${states['light.ls1'].state === 'off' ? 'mdi:led-off' :
      'mdi:led-on'}
    toggle: 'yes'
    secondary_info: last-changed
    type: 'custom:slider-entity-row'
    entity: light.ls1
  - name: Lamp
    toggle: 'yes'
    secondary_info: last-changed
    type: 'custom:slider-entity-row'
    entity: light.lamp_bedroom
  - secondary_info: last-changed
    entity: switch.homey_led_ring

And when light.ls1 is not available, the whole card is not displaying. There is something about template processing inside of icon:, I think. Because if I remove the line with template, the whole card appears back again.

iantrich commented 5 years ago

You can handle that yourself

${states['light.ls1'] ? states['light.ls1'].state === 'off' ? 'mdi:led-off' :
      'mdi:led-on' : 'mdi:led-off'}
notabene00 commented 5 years ago

Oh, okay, thanks. So, it is expected behaviour?

iantrich commented 5 years ago

OR, I like this better

${!states['light.ls1'] || states['light.ls1'].state === 'off' ? 'mdi:led-off' : 'mdi:led-on'}
iantrich commented 5 years ago

You are in control of your own destiny. If your entity might be unavailable, do a check before you try to access it's elements to be safe