#Template

1 messages · Page 1 of 1 (latest)

prime epoch
#

Heya,

ist there a way to make the definition of this a bit more elegant and flexible by using a template? The identifier for the state_image comes from a template sensor and is so far a single character, but could be later on also '57' (resulting in error-57.svg) , '99' (resulting in error-99.svg) or such.

elements:
  - type: image
    entity: sensor.some_sensor
    state_image:
      '0': /local/images/error-0.svg
      '1': /local/images/error-1.svg
      '2': /local/images/error-2.svg
      '3': /local/images/error-3.svg
      '4': /local/images/error-4.svg
      '5': /local/images/error-5.svg
      '6': /local/images/error-6.svg
      '7': /local/images/error-7.svg
      '8': /local/images/error-8.svg
      '9': /local/images/error-9.svg

Appreciate some guidance, thanks! 🙂

/tom

viral vale
#

it'd be easier to use card-mod as you can use a template in there - something like:

card-mod:
  style: |
    ha-card  {
      background-image: "{{ '/local/images/error-' + states('sensor.some_sensor') + '.svg' }}"
    }```
prime epoch
#

(it's a picture elements card btw, it just came into my mind to possibly use image: instead of state_image: )

#

Thanks @viral vale, guess I'll try the following first, then the card-mod method:

elements:
  - type: image
    entity: sensor.some_sensor
    image: |
      '/local/images/error-' + states('sensor.some_sensor') + '.svg'
viral vale
#

pretty sure that doesn't accept templates sadly