Icon_template not working anymore since 0.115

Hello!

Since the 0.115 update the below icon_template does not work anymore. If I test it in the Template editor it works, it detects the state and updates. The icon however is not updated on the frontend.

What changed?

- platform: template
  covers:
    awning_homekit: #name of the cover
      friendly_name: Awning
      close_cover:
        service: cover.open_cover
        data:
          entity_id: cover.awning
      open_cover:
        service: cover.close_cover
        data:
          entity_id: cover.awning
      icon_template: >-
        {% if is_state("cover.awning_homekit", "open") %}
          mdi:bus-stop-covered
        {% else %}
          mdi:bus-stop-uncovered
        {% endif %}

Ignore my first reply. The template is wrong, needs to be cover.awning, not itself

I read this twice and couldn’t see anything wrong.
But since Marc has brought a flashlight to the party

There is a superfluous “_homekit”

specifically in : -

{% if is_state("cover.awning_homekit", "open") %}

Superfluous as in ‘unnecessary’? It’s just how I named it.
Doesn’t have anything to do with the fact that the icon is not updating anymore, expecially because it seemed to work before 0.115.

I understand it looks weird. But they’re linked and the same. This was to give Homekit a reversed state so it would show up correctly in Homekit. cover.awning is the actual intergration while cover.awning_homekit is the switch that I control. Both in Lovelace and Homekit on my phone.

Again, this used to work. Why doesn’t it now?

Your template cover doesn’t have a value template, so it never knows if it is on or off. Your icon_template is based on itself and because we don’t know whether it’s on or off, the icon doesn’t know which to show.

You need cover.awning in your template, not cover.awning_homekit so that the icon has a state to monitor.

1 Like

Except that it does. The cover.awning_homekit switches on/off based on cover.awning.

Unless in order for it to work since 0.115 the icon_template needs to be in the same automation as the entity it references. So in my example only cover.awning would work.

I understand what your saying and it certainly is better then my automation, I’m maybe just trying to understand where the problem suddenly comes from.

The way templates are evaluated was changed in the latest version, I suspect previously it was able to rely on on assumed state and now it can’t.

@ Jasper8472

How did you fix the problem in your template.
I have the same issue since 0.115 with my template cover and no working icon state.

platform: template
    covers:
      slaapkamer_stef:
        open_cover:
        close_cover:
        icon_template: >-
          {% if is_state('cover.slaapkamer_stef', 'open') %}
            mdi:window-shutter-open
          {% else %}
            mdi:window-shutter
          {% endif %}

I’m trying to change the icon based on the entity’s own state.
The code above worked fine untill release 0.115.
I’ve read the huge release note for 0.115 but can’t find any answer why i does’n work anymore.

Can you please edit your post so I can check the code?

I solved it by changing cover.awning_homekit to cover.awning as that one is referenced in the automation. It’s not a problem for me as cover.awning_homekit changes state based on cover.awning. /u/mf_social was right, something changed in 0.115 that this icon_template couldn’t read the state of cover.awning_homekit as that is a different automation/entity then the one referenced.

Hi Jasper,

My post with the code now has the correct layout for the code.

Greetings

“covers:” needs to be in line with “platform: template”, your yaml lint didn’t check out. You can test this by using http://www.yamllint.com/ for example.

The code blow works checks out. You didn’t fill any data after open_cover and close_cover, did you leave that out?

platform: template
covers:
  slaapkamer_stef:
    open_cover:
    close_cover:
    icon_template: >-
      {% if is_state('cover.slaapkamer_stef', 'open') %}
        mdi:window-shutter-open
      {% else %}
        mdi:window-shutter
      {% endif %}

Hi Jasper,

Changed the yaml typo but it’s still not changing the icon based on the state of the cover switch in hassio.

I didnt fill in any data for open_cover or close_cover as it is a dummy switch which i handle from node-red. If node-red sees a change on the entity cover.slaapkamer_stef then node-red fires a http command to the custom build cover controller.

I handle all automations and stuff in node-red as it is easier to use for me with my limited programming knowledge.

In node-red the msg.payload says open or closed after activating the cover switch in hassio. So the state of the cover switch seems ok in hassio and node-red.

If i load the code in Hassio > Developer Tools > template like :

{%- if is_state("cover.slaapkamer_stef", "open")-%}mdi:window-shutter-open{% else %}mdi:window-shutter{%endif %}

The preview pane of the template tools show the correct text mdi:window-shutter or mdi:window-shutter-open corresponding to the state of the cover switch.

Could the problem be that i don’t have any data in open_cover and close_cover or is there another problem or bug in hassio with the template and changing the icon. ?

This looks like the problem I’m having here.

It’s due to template loop prevention. Do you have any erros in the Logs? Something like “Template loop detected while processing event:”?

Interesting to see if this is the problem.

I’ve checked the logs and i have loop deteced errors :frowning:

2020-10-01 16:19:15 WARNING (MainThread) [homeassistant.components.template.template_entity] Template loop detected while processing event: <Event state_changed[L]: entity_id=cover.slaapkamer_stef, old_state=<state cover.slaapkamer_stef=open; friendly_name=slaapkamer_stef, icon=mdi:window-shutter-open, supported_features=3 @ 2020-10-01T13:34:31.403295+02:00>, new_state=<state cover.slaapkamer_stef=closed; friendly_name=slaapkamer_stef, icon=mdi:window-shutter-open, supported_features=3 @ 2020-10-01T16:19:15.633687+02:00>>, skipping template render for Template[{% if is_state('cover.slaapkamer_stef', 'open') %}
  mdi:window-shutter-open
{% else %}
  mdi:window-shutter
{% endif %}]

That makes sense tbh. The template for the icon relies on the state of the entity it’s part of. So you close the cover, the state object updates, the template re-evaluates, the icon changes thus updating the state object, so the template re-evaluates in an infinite loop.

In fairness though, there should never have been a time when templates were referencing the entities they were a part of, you were just lucky it worked before.

Looks like there is gonna be a fix for the loop :slight_smile:

The link above was posted in Template loop detection broke my cover template