Hi all,
depending on the first letter of an input_text I want a different icon…
How can I cover that first lettter ?
Hi all,
depending on the first letter of an input_text I want a different icon…
How can I cover that first lettter ?
{% set STRING = 'abcdef' %}
{{STRING[0]}}
euh
so
if input_text first letter is A
then
mdi:alpha-a-circle-outline
how do i get your code in it ?
{% set STRING = states('input_text.xxxx') %}
{% if STRING[0] == 'A' %}
...
{% endif %}
Actually, you have not explained where & how yo want that “different icon”. It could be in a template sensor, in card-mod, …
- type: custom:mushroom-template-card
primary: '{{ states(''input_text.ruimte_4'')}}'
secondary: "{{ states('sensor.indoor_temperature') | round(1) | float(0) }} °C" #sensor.ruimte4_temperatuur
icon: >
{% if is_state("input_boolean.ruimte4", 'on') %}
mdi:lightbulb
{% else %}
mdi:alpha-s-circle-outline
{% endif %}
so if the state is off, I want to check the name of the input_text and change to icon to the first letter of the input_text
but I was thinking its a little stupid to write 26 if else structures to get the right icon…
is it possible to fill in the * in the icon ?
{% set STRING = states('input_text.xxxx') %}
{% if STRING[0] == '* %}
icon: mdi:alpha-*-circle-outline
{% endif %}
- type: custom:mushroom-template-card
primary: "{{ states('input_text.ruimte_4')}}"
secondary: "{{ states('sensor.indoor_temperature') | round(1) | float(0) }} °C"
icon: >
{% set STRING = states('input_text.ruimte_4') %}
{% if is_state('input_boolean.ruimte4', 'on') %}
mdi:lightbulb
{% else %}
mdi:alpha-{{STRING[0]}}-circle-outline
{% endif %}
I didn’t check, if the icons are valid and if there is an icon that is named like that.
your code is working, but the string gives me the letter in capital, and I think it has to be lowercase. Is it fixabel ?
edit : solution
mdi:alpha-{{STRING[0] | lower}}-circle-outline