grr, struggling with templating inconsistencies again…
using:
{% set time = {1:'one',
2:'two',
3:'three',
4:'four',
5:'five',
6:'six',
7:'seven',
8:'eight',
9:'nine',
10:'ten',
11:'eleven',
12:'twelve'} %}
{% set hour = time[now().hour] %}
{% if states('sun.sun') == 'above_horizon' %}mdi:clock-time-{{hour}}
{% else %}mdi:clock-time-{{hour}}-outline
{% endif %}
in the template editor works fine:
however, in CH this results in:
and kills the CH completely (makes it disappear) when used in the config:
tab_icons:
time_settings: >-
{% set time = {1:'one',
2:'two',
3:'three',
4:'four',
5:'five',
6:'six',
7:'seven',
8:'eight',
9:'nine',
10:'ten',
11:'eleven',
12:'twelve'} %}
{% set hour = time[now().hour] %}
{% if states('sun.sun') == 'above_horizon' %}mdi:clock-time-{{hour}}
{% else %}mdi:clock-time-{{hour}}-outline
{% endif %}
I know I shouldn’t quote the numbers, since that causes this:
(I realize haven’t guarded the template yet, will do later on, but first need to figure out why CH wont accept this valid template?
I even tried it with an extra variable, and other wordings, to prevent the use of ‘reserved’ variables. Same result unfortunately:
{% set mapper = {1:'one',
2:'two',
3:'three',
4:'four',
5:'five',
6:'six',
7:'seven',
8:'eight',
9:'nine',
10:'ten',
11:'eleven',
12:'twelve'} %}
{% set digit = now().hour %}
{% set word = mapper[digit] %}
{% if states('sun.sun') == 'above_horizon' %}mdi:clock-time-{{word}}
{% else %}mdi:clock-time-{{word}}-outline
{% endif %}
as you can see, this template works fine in HA as template sensor:
hour_icon:
friendly_name: Hour icon
entity_id: sensor.time
value_template: >
{{now().hour}}
icon_template: >
{% set mapper = {1:'one',
2:'two',
3:'three',
4:'four',
5:'five',
6:'six',
7:'seven',
8:'eight',
9:'nine',
10:'ten',
11:'eleven',
12:'twelve'} %}
{% set digit = now().hour %}
{% set word = mapper[digit] %}
{% if states('sun.sun') == 'above_horizon' %}mdi:clock-time-{{word}}
{% else %}mdi:clock-time-{{word}}-outline
{% endif %}
Please have a look, thanks!