home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
74.22k stars 31.16k forks source link

Template helpers that use "label_entities" aren't updated when labels are added to or removed from entities #115439

Open cvwillegen opened 7 months ago

cvwillegen commented 7 months ago

The problem

I have a template sensor helper with the following configuration:

{%- set ns=namespace(alerts = 0) %}{%- for alert in expand(label_entities('alert') + label_entities('alert clock')) -%}{%- if alert.state== "on" -%}{% set ns.alerts = ns.alerts+1 %}{%- endif %}{%-endfor %}{{ ns.alerts }}

I have a couple of input_boolean helpers tagged with the label alert. I accidentally labeled a few automations with the same label. After that, the state of the helper went to 11 (probably because one the referenced entities changed). When I removed the label from the automations, the state of the template sensor stayed at 11, even though the preview in the helper editor showed a value of 0, and the correct selection of entities the template looked at.

So, when labels are added/removed, template sensors that use label_entities() are not evaluated again.

What version of Home Assistant Core has the issue?

2024.4.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

No response

Link to integration documentation on our website

https://www.home-assistant.io/docs/configuration/templating/#labels

Diagnostics information

No response

Example YAML snippet

No response

Anything in the logs that might be useful for us?

No response

Additional information

No response

ErikT80 commented 7 months ago

Same issue here. I have some entities I would like to track whether they will become unavailable. So I have given them a label and below template:

{% for item in label_entities('trace_unavailable') %} {% if states('item') == 'unavailable' %} {{ item }} {% endif %} {% endfor %}

A change in the state of the entities tagged with this label doesn't trigger the template sensor to be evaluated again.

issue-triage-workflows[bot] commented 4 months ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

cvwillegen commented 4 months ago

This is still an issue in the latest version of HA.

issue-triage-workflows[bot] commented 1 month ago

There hasn't been any activity on this issue recently. Due to the high number of incoming GitHub notifications, we have to clean some of the old issues, as many of them have already been resolved with the latest updates. Please make sure to update to the latest Home Assistant version and check if that solves the issue. Let us know if that works for you by adding a comment 👍 This issue has now been marked as stale and will be closed if no further activity occurs. Thank you for your contributions.

toxikman commented 1 month ago

I would very much still like this to be fixed. Not stale, don't close!